From ce551e9c8b5a7860b1baf82a3d59fb18ece3d36d Mon Sep 17 00:00:00 2001 From: silverpill Date: Fri, 12 Nov 2021 14:51:03 +0000 Subject: [PATCH] Handle incoming Delete() activities --- src/activitypub/receiver.rs | 11 +++++++++++ src/activitypub/vocabulary.rs | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/src/activitypub/receiver.rs b/src/activitypub/receiver.rs index ecdf043..ceafe38 100644 --- a/src/activitypub/receiver.rs +++ b/src/activitypub/receiver.rs @@ -14,6 +14,7 @@ use crate::models::posts::queries::{ create_post, get_post_by_id, get_post_by_object_id, + delete_post, }; use crate::models::profiles::queries::{ get_profile_by_actor_id, @@ -255,6 +256,16 @@ pub async fn receive_activity( .map_err(|_| ValidationError("invalid object"))?; process_note(config, db_client, object).await?; }, + (DELETE, TOMBSTONE) => { + let object: Object = serde_json::from_value(activity.object) + .map_err(|_| ValidationError("invalid object"))?; + let post = get_post_by_object_id(db_client, &object.id).await?; + let deletion_queue = delete_post(db_client, &post.id).await?; + let config = config.clone(); + actix_rt::spawn(async move { + deletion_queue.process(&config).await; + }); + }, (LIKE, _) => { let author = get_or_fetch_profile_by_actor_id( db_client, diff --git a/src/activitypub/vocabulary.rs b/src/activitypub/vocabulary.rs index a2c9e07..4f7b486 100644 --- a/src/activitypub/vocabulary.rs +++ b/src/activitypub/vocabulary.rs @@ -1,6 +1,9 @@ +/// https://www.w3.org/TR/activitystreams-vocabulary/ + // Activity types pub const ACCEPT: &str = "Accept"; pub const CREATE: &str = "Create"; +pub const DELETE: &str = "Delete"; pub const FOLLOW: &str = "Follow"; pub const LIKE: &str = "Like"; pub const REJECT: &str = "Reject"; @@ -15,6 +18,7 @@ pub const DOCUMENT: &str = "Document"; pub const IMAGE: &str = "Image"; pub const MENTION: &str = "Mention"; pub const NOTE: &str = "Note"; +pub const TOMBSTONE: &str = "Tombstone"; // Misc pub const PROPERTY_VALUE: &str = "PropertyValue";