From ae9c9262f7d9b89bfca0aa61b8b7e433e9ab798a Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Mon, 2 May 2022 23:16:55 +0900 Subject: [PATCH] Use Reshare::build_undo07() instead of build_undo() --- plume-models/src/reshares.rs | 56 ++++-------------------------------- src/routes/reshares.rs | 6 ++-- 2 files changed, 8 insertions(+), 54 deletions(-) diff --git a/plume-models/src/reshares.rs b/plume-models/src/reshares.rs index 05973f89..663fdc8d 100644 --- a/plume-models/src/reshares.rs +++ b/plume-models/src/reshares.rs @@ -2,9 +2,9 @@ use crate::{ db_conn::DbConn, instance::Instance, notifications::*, posts::Post, schema::reshares, timeline::*, users::User, Connection, Error, Result, CONFIG, }; -use activitypub::activity::{Announce, Undo}; +use activitypub::activity::Announce; use activitystreams::{ - activity::{ActorAndObjectRef, Announce as Announce07, Undo as Undo07}, + activity::{ActorAndObjectRef, Announce as Announce07, Undo}, base::AnyBase, iri_string::types::IriString, prelude::*, @@ -113,23 +113,8 @@ impl Reshare { Ok(()) } - pub fn build_undo(&self, conn: &Connection) -> Result { - let mut act = 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(self.get_user(conn)?.followers_endpoint)])?; - - Ok(act) - } - - pub fn build_undo07(&self, conn: &Connection) -> Result { - let mut act = Undo07::new( + pub fn build_undo07(&self, conn: &Connection) -> Result { + let mut act = Undo::new( User::get(conn, self.user_id)?.ap_url.parse::()?, AnyBase::from_extended(self.to_activity07(conn)?)?, ); @@ -214,7 +199,7 @@ impl FromId for Reshare { } } -impl AsObject for Reshare { +impl AsObject for Reshare { type Error = Error; type Output = (); @@ -301,37 +286,6 @@ mod test { }); } - #[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 reshare = Reshare::insert(&*conn, NewReshare::new(post, user))?; - let act = reshare.build_undo(&*conn)?; - - let expected = json!({ - "actor": "https://plu.me/@/admin/", - "cc": ["https://plu.me/@/admin/followers"], - "id": "https://plu.me/@/admin/reshare/https://plu.me/~/BlogName/testing#delete", - "object": { - "actor": "https://plu.me/@/admin/", - "cc": ["https://plu.me/@/admin/followers"], - "id": "https://plu.me/@/admin/reshare/https://plu.me/~/BlogName/testing", - "object": "https://plu.me/~/BlogName/testing", - "to": ["https://www.w3.org/ns/activitystreams#Public"], - "type": "Announce" - }, - "to": ["https://www.w3.org/ns/activitystreams#Public"], - "type": "Undo", - }); - assert_json_eq!(to_value(act)?, expected); - - Ok(()) - }); - } - #[test] fn build_undo07() { let conn = db(); diff --git a/src/routes/reshares.rs b/src/routes/reshares.rs index b6d11c8a..8010b846 100644 --- a/src/routes/reshares.rs +++ b/src/routes/reshares.rs @@ -3,7 +3,7 @@ use rocket_i18n::I18n; use crate::routes::errors::ErrorPage; use crate::utils::requires_login; -use plume_common::activity_pub::broadcast; +use plume_common::activity_pub::{broadcast, broadcast07}; use plume_models::{ blogs::Blog, db_conn::DbConn, inbox::inbox, posts::Post, reshares::*, timeline::*, users::User, Error, PlumeRocket, CONFIG, @@ -33,7 +33,7 @@ pub fn create( .execute(move || broadcast(&user, act, dest, CONFIG.proxy().cloned())); } else { let reshare = Reshare::find_by_user_on_post(&conn, user.id, post.id)?; - let delete_act = reshare.build_undo(&conn)?; + let delete_act = reshare.build_undo07(&conn)?; inbox( &conn, serde_json::to_value(&delete_act).map_err(Error::from)?, @@ -42,7 +42,7 @@ pub fn create( let dest = User::one_by_instance(&conn)?; rockets .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!(