mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-23 03:51:00 +00:00
Use Like::build_undo07() instead of build_undo()
This commit is contained in:
parent
771c157fe5
commit
b13444895f
2 changed files with 3 additions and 50 deletions
|
@ -87,22 +87,6 @@ impl Like {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_undo(&self, conn: &Connection) -> Result<activity::Undo> {
|
|
||||||
let mut act = activity::Undo::default();
|
|
||||||
act.undo_props
|
|
||||||
.set_actor_link(User::get(conn, self.user_id)?.into_id())?;
|
|
||||||
act.undo_props.set_object_object(self.to_activity(conn)?)?;
|
|
||||||
act.object_props
|
|
||||||
.set_id_string(format!("{}#delete", self.ap_url))?;
|
|
||||||
act.object_props
|
|
||||||
.set_to_link_vec(vec![Id::new(PUBLIC_VISIBILITY.to_string())])?;
|
|
||||||
act.object_props.set_cc_link_vec(vec![Id::new(
|
|
||||||
User::get(conn, self.user_id)?.followers_endpoint,
|
|
||||||
)])?;
|
|
||||||
|
|
||||||
Ok(act)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn build_undo07(&self, conn: &Connection) -> Result<Undo07> {
|
pub fn build_undo07(&self, conn: &Connection) -> Result<Undo07> {
|
||||||
let mut act = Undo07::new(
|
let mut act = Undo07::new(
|
||||||
User::get(conn, self.user_id)?.ap_url.parse::<IriString>()?,
|
User::get(conn, self.user_id)?.ap_url.parse::<IriString>()?,
|
||||||
|
@ -273,37 +257,6 @@ mod tests {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn build_undo() {
|
|
||||||
let conn = db();
|
|
||||||
conn.test_transaction::<_, Error, _>(|| {
|
|
||||||
let (posts, _users, _blogs) = fill_database(&conn);
|
|
||||||
let post = &posts[0];
|
|
||||||
let user = &post.get_authors(&conn)?[0];
|
|
||||||
let like = Like::insert(&*conn, NewLike::new(post, user))?;
|
|
||||||
let act = like.build_undo(&*conn)?;
|
|
||||||
|
|
||||||
let expected = json!({
|
|
||||||
"actor": "https://plu.me/@/admin/",
|
|
||||||
"cc": ["https://plu.me/@/admin/followers"],
|
|
||||||
"id": "https://plu.me/@/admin/like/https://plu.me/~/BlogName/testing#delete",
|
|
||||||
"object": {
|
|
||||||
"actor": "https://plu.me/@/admin/",
|
|
||||||
"cc": ["https://plu.me/@/admin/followers"],
|
|
||||||
"id": "https://plu.me/@/admin/like/https://plu.me/~/BlogName/testing",
|
|
||||||
"object": "https://plu.me/~/BlogName/testing",
|
|
||||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
|
||||||
"type": "Like",
|
|
||||||
},
|
|
||||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
|
||||||
"type": "Undo",
|
|
||||||
});
|
|
||||||
assert_json_eq!(to_value(act)?, expected);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn build_undo07() {
|
fn build_undo07() {
|
||||||
let conn = db();
|
let conn = db();
|
||||||
|
|
|
@ -3,7 +3,7 @@ use rocket_i18n::I18n;
|
||||||
|
|
||||||
use crate::routes::errors::ErrorPage;
|
use crate::routes::errors::ErrorPage;
|
||||||
use crate::utils::requires_login;
|
use crate::utils::requires_login;
|
||||||
use plume_common::activity_pub::broadcast;
|
use plume_common::activity_pub::{broadcast, broadcast07};
|
||||||
use plume_models::{
|
use plume_models::{
|
||||||
blogs::Blog, db_conn::DbConn, inbox::inbox, likes, posts::Post, timeline::*, users::User,
|
blogs::Blog, db_conn::DbConn, inbox::inbox, likes, posts::Post, timeline::*, users::User,
|
||||||
Error, PlumeRocket, CONFIG,
|
Error, PlumeRocket, CONFIG,
|
||||||
|
@ -33,7 +33,7 @@ pub fn create(
|
||||||
.execute(move || broadcast(&user, act, dest, CONFIG.proxy().cloned()));
|
.execute(move || broadcast(&user, act, dest, CONFIG.proxy().cloned()));
|
||||||
} else {
|
} else {
|
||||||
let like = likes::Like::find_by_user_on_post(&conn, user.id, post.id)?;
|
let like = likes::Like::find_by_user_on_post(&conn, user.id, post.id)?;
|
||||||
let delete_act = like.build_undo(&conn)?;
|
let delete_act = like.build_undo07(&conn)?;
|
||||||
inbox(
|
inbox(
|
||||||
&conn,
|
&conn,
|
||||||
serde_json::to_value(&delete_act).map_err(Error::from)?,
|
serde_json::to_value(&delete_act).map_err(Error::from)?,
|
||||||
|
@ -42,7 +42,7 @@ pub fn create(
|
||||||
let dest = User::one_by_instance(&conn)?;
|
let dest = User::one_by_instance(&conn)?;
|
||||||
rockets
|
rockets
|
||||||
.worker
|
.worker
|
||||||
.execute(move || broadcast(&user, delete_act, dest, CONFIG.proxy().cloned()));
|
.execute(move || broadcast07(&user, delete_act, dest, CONFIG.proxy().cloned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Redirect::to(uri!(
|
Ok(Redirect::to(uri!(
|
||||||
|
|
Loading…
Reference in a new issue