From effdc44943aa4f55744d8596fef0414b78fc6866 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Tue, 3 May 2022 00:03:11 +0900 Subject: [PATCH] Use User::delete_activity07() instead of delete_activity() --- plume-models/src/users.rs | 68 ++++----------------------------------- src/routes/instance.rs | 6 ++-- src/routes/user.rs | 6 ++-- 3 files changed, 13 insertions(+), 67 deletions(-) diff --git a/plume-models/src/users.rs b/plume-models/src/users.rs index 343f61ef..f9075779 100644 --- a/plume-models/src/users.rs +++ b/plume-models/src/users.rs @@ -4,21 +4,16 @@ use crate::{ safe_string::SafeString, schema::users, timeline::Timeline, Connection, Error, Result, UserEvent::*, CONFIG, ITEMS_PER_PAGE, USER_CHAN, }; -use activitypub::{ - activity::Delete, - actor::Person, - object::{Image, Tombstone}, - Activity, CustomObject, Endpoint, -}; +use activitypub::{actor::Person, object::Image, Activity, CustomObject, Endpoint}; use activitystreams::{ - activity::Delete as Delete07, + activity::Delete, actor::{ApActor, AsApActor}, actor::{ApActor as ApActor07, Endpoints as Endpoints07, Person as Person07}, base::{AnyBase, Base}, collection::{OrderedCollection as OrderedCollection07, OrderedCollectionPage}, iri_string::types::IriString, markers::Activity as Activity07, - object::{kind::ImageType, AsObject as _, Image as Image07, Tombstone as Tombstone07}, + object::{kind::ImageType, AsObject as _, Image as Image07, Tombstone}, prelude::*, }; use chrono::{NaiveDateTime, Utc}; @@ -917,34 +912,11 @@ impl User { Ok(CustomPerson07::new(actor, ap_signature)) } - pub fn delete_activity(&self, conn: &Connection) -> Result { - let mut del = Delete::default(); - - let mut tombstone = Tombstone::default(); - tombstone.object_props.set_id_string(self.ap_url.clone())?; - - del.delete_props - .set_actor_link(Id::new(self.ap_url.clone()))?; - del.delete_props.set_object_object(tombstone)?; - del.object_props - .set_id_string(format!("{}#delete", self.ap_url))?; - del.object_props - .set_to_link_vec(vec![Id::new(PUBLIC_VISIBILITY)])?; - del.object_props.set_cc_link_vec( - self.get_followers(conn)? - .into_iter() - .map(|f| Id::new(f.ap_url)) - .collect(), - )?; - - Ok(del) - } - - pub fn delete_activity07(&self, conn: &Connection) -> Result { - let mut tombstone = Tombstone07::new(); + pub fn delete_activity07(&self, conn: &Connection) -> Result { + let mut tombstone = Tombstone::new(); tombstone.set_id(self.ap_url.parse()?); - let mut del = Delete07::new( + let mut del = Delete::new( self.ap_url.parse::()?, Base::retract(tombstone)?.into_generic()?, ); @@ -1192,7 +1164,7 @@ impl AsActor<&DbConn> for User { } } -impl AsObject for User { +impl AsObject for User { type Error = Error; type Output = (); @@ -1700,32 +1672,6 @@ pub(crate) mod tests { }); } - #[test] - fn delete_activity() { - let conn = db(); - conn.test_transaction::<_, Error, _>(|| { - let users = fill_database(&conn); - let user = &users[1]; - let act = user.delete_activity(&conn)?; - - let expected = json!({ - "actor": "https://plu.me/@/user/", - "cc": [], - "id": "https://plu.me/@/user/#delete", - "object": { - "id": "https://plu.me/@/user/", - "type": "Tombstone", - }, - "to": ["https://www.w3.org/ns/activitystreams#Public"], - "type": "Delete", - }); - - assert_json_eq!(to_value(act)?, expected); - - Ok(()) - }); - } - #[test] fn delete_activity07() { let conn = db(); diff --git a/src/routes/instance.rs b/src/routes/instance.rs index cedaa900..3864f20c 100644 --- a/src/routes/instance.rs +++ b/src/routes/instance.rs @@ -11,7 +11,7 @@ use validator::{Validate, ValidationErrors}; use crate::inbox; use crate::routes::{errors::ErrorPage, rocket_uri_macro_static_files, Page, RespondOrRedirect}; use crate::template_utils::{IntoContext, Ructe}; -use plume_common::activity_pub::{broadcast, inbox::FromId}; +use plume_common::activity_pub::{broadcast07, inbox::FromId}; use plume_models::{ admin::*, blocklisted_emails::*, @@ -382,8 +382,8 @@ fn ban(id: i32, conn: &Connection, worker: &ScheduledThreadPool) -> Result<(), E ) .unwrap(); let target = User::one_by_instance(&*conn)?; - let delete_act = u.delete_activity(&*conn)?; - worker.execute(move || broadcast(&u, delete_act, target, CONFIG.proxy().cloned())); + let delete_act = u.delete_activity07(&*conn)?; + worker.execute(move || broadcast07(&u, delete_act, target, CONFIG.proxy().cloned())); } Ok(()) diff --git a/src/routes/user.rs b/src/routes/user.rs index da5b1a19..99315697 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -18,7 +18,7 @@ use crate::routes::{ }; use crate::template_utils::{IntoContext, Ructe}; use crate::utils::requires_login; -use plume_common::activity_pub::{broadcast, ActivityStream, ApRequest, Id}; +use plume_common::activity_pub::{broadcast, broadcast07, ActivityStream, ApRequest, Id}; use plume_common::utils::md_to_html; use plume_models::{ blogs::Blog, @@ -386,10 +386,10 @@ pub fn delete( account.delete(&conn)?; let target = User::one_by_instance(&conn)?; - let delete_act = account.delete_activity(&conn)?; + let delete_act = account.delete_activity07(&conn)?; rockets .worker - .execute(move || broadcast(&account, delete_act, target, CONFIG.proxy().cloned())); + .execute(move || broadcast07(&account, delete_act, target, CONFIG.proxy().cloned())); if let Some(cookie) = cookies.get_private(AUTH_COOKIE) { cookies.remove_private(cookie);