diff --git a/crates/apub_receive/src/activities/receive/comment_undo.rs b/crates/apub_receive/src/activities/receive/comment_undo.rs deleted file mode 100644 index 7f3b0e64..00000000 --- a/crates/apub_receive/src/activities/receive/comment_undo.rs +++ /dev/null @@ -1,73 +0,0 @@ -use activitystreams::activity::{Dislike, Like}; -use lemmy_api_common::{blocking, comment::CommentResponse}; -use lemmy_db_queries::{source::comment::Comment_, Likeable}; -use lemmy_db_schema::source::comment::{Comment, CommentLike}; -use lemmy_db_views::comment_view::CommentView; -use lemmy_utils::LemmyError; -use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperation, UserOperationCrud}; - -pub(crate) async fn receive_undo_delete_comment( - context: &LemmyContext, - comment: Comment, -) -> Result<(), LemmyError> { - let deleted_comment = blocking(context.pool(), move |conn| { - Comment::update_deleted(conn, comment.id, false) - }) - .await??; - - // Refetch the view - let comment_id = deleted_comment.id; - let comment_view = blocking(context.pool(), move |conn| { - CommentView::read(conn, comment_id, None) - }) - .await??; - - // TODO get those recipient actor ids from somewhere - let recipient_ids = vec![]; - let res = CommentResponse { - comment_view, - recipient_ids, - form_id: None, - }; - - context.chat_server().do_send(SendComment { - op: UserOperationCrud::EditComment, - comment: res, - websocket_id: None, - }); - - Ok(()) -} - -pub(crate) async fn receive_undo_remove_comment( - context: &LemmyContext, - comment: Comment, -) -> Result<(), LemmyError> { - let removed_comment = blocking(context.pool(), move |conn| { - Comment::update_removed(conn, comment.id, false) - }) - .await??; - - // Refetch the view - let comment_id = removed_comment.id; - let comment_view = blocking(context.pool(), move |conn| { - CommentView::read(conn, comment_id, None) - }) - .await??; - - // TODO get those recipient actor ids from somewhere - let recipient_ids = vec![]; - let res = CommentResponse { - comment_view, - recipient_ids, - form_id: None, - }; - - context.chat_server().do_send(SendComment { - op: UserOperationCrud::EditComment, - comment: res, - websocket_id: None, - }); - - Ok(()) -} diff --git a/crates/apub_receive/src/activities/receive/mod.rs b/crates/apub_receive/src/activities/receive/mod.rs index f4b87536..8b085cda 100644 --- a/crates/apub_receive/src/activities/receive/mod.rs +++ b/crates/apub_receive/src/activities/receive/mod.rs @@ -4,17 +4,11 @@ use activitystreams::{ error::DomainError, }; use anyhow::{anyhow, Context}; -use lemmy_apub::fetcher::person::get_or_fetch_and_upsert_person; -use lemmy_db_schema::source::person::Person; use lemmy_utils::{location_info, LemmyError}; -use lemmy_websocket::LemmyContext; use log::debug; use std::fmt::Debug; use url::Url; -pub(crate) mod comment_undo; -pub(crate) mod post_undo; - /// Return HTTP 501 for unsupported activities in inbox. pub(crate) fn receive_unhandled_activity(activity: A) -> Result<(), LemmyError> where diff --git a/crates/apub_receive/src/activities/receive/post_undo.rs b/crates/apub_receive/src/activities/receive/post_undo.rs deleted file mode 100644 index a040ca8b..00000000 --- a/crates/apub_receive/src/activities/receive/post_undo.rs +++ /dev/null @@ -1,60 +0,0 @@ -use activitystreams::activity::{Dislike, Like}; -use lemmy_api_common::{blocking, post::PostResponse}; -use lemmy_db_queries::{source::post::Post_, Likeable}; -use lemmy_db_schema::source::post::{Post, PostLike}; -use lemmy_db_views::post_view::PostView; -use lemmy_utils::LemmyError; -use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation, UserOperationCrud}; - -pub(crate) async fn receive_undo_delete_post( - context: &LemmyContext, - post: Post, -) -> Result<(), LemmyError> { - let deleted_post = blocking(context.pool(), move |conn| { - Post::update_deleted(conn, post.id, false) - }) - .await??; - - // Refetch the view - let post_id = deleted_post.id; - let post_view = blocking(context.pool(), move |conn| { - PostView::read(conn, post_id, None) - }) - .await??; - - let res = PostResponse { post_view }; - context.chat_server().do_send(SendPost { - op: UserOperationCrud::EditPost, - post: res, - websocket_id: None, - }); - - Ok(()) -} - -pub(crate) async fn receive_undo_remove_post( - context: &LemmyContext, - post: Post, -) -> Result<(), LemmyError> { - let removed_post = blocking(context.pool(), move |conn| { - Post::update_removed(conn, post.id, false) - }) - .await??; - - // Refetch the view - let post_id = removed_post.id; - let post_view = blocking(context.pool(), move |conn| { - PostView::read(conn, post_id, None) - }) - .await??; - - let res = PostResponse { post_view }; - - context.chat_server().do_send(SendPost { - op: UserOperationCrud::EditPost, - post: res, - websocket_id: None, - }); - - Ok(()) -} diff --git a/crates/apub_receive/src/activities_new/comment/delete.rs b/crates/apub_receive/src/activities_new/comment/delete.rs index e50c3888..5c863dc3 100644 --- a/crates/apub_receive/src/activities_new/comment/delete.rs +++ b/crates/apub_receive/src/activities_new/comment/delete.rs @@ -12,9 +12,9 @@ use url::Url; #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[serde(rename_all = "camelCase")] pub struct DeleteComment { - actor: Url, + pub(in crate::activities_new::comment) actor: Url, to: PublicUrl, - object: Url, + pub(in crate::activities_new::comment) object: Url, cc: [Url; 1], #[serde(rename = "type")] kind: DeleteType, @@ -44,7 +44,6 @@ impl ReceiveActivity for Activity { }) .await??; - // TODO get those recipient actor ids from somewhere send_websocket_message( deleted_comment.id, vec![], diff --git a/crates/apub_receive/src/activities_new/comment/mod.rs b/crates/apub_receive/src/activities_new/comment/mod.rs index 44d54d18..d433f035 100644 --- a/crates/apub_receive/src/activities_new/comment/mod.rs +++ b/crates/apub_receive/src/activities_new/comment/mod.rs @@ -22,8 +22,10 @@ pub mod delete; pub mod dislike; pub mod like; pub mod remove; +pub mod undo_delete; pub mod undo_dislike; pub mod undo_like; +pub mod undo_remove; pub mod update; async fn get_notif_recipients( @@ -45,6 +47,8 @@ async fn get_notif_recipients( send_local_notifs(mentions, comment.clone(), actor, post, context.pool(), true).await } +// TODO: in many call sites we are setting an empty vec for recipient_ids, we should get the actual +// recipient actors from somewhere async fn send_websocket_message( comment_id: CommentId, recipient_ids: Vec, @@ -96,7 +100,6 @@ async fn like_or_dislike_comment( }) .await??; - // TODO get those recipient actor ids from somewhere send_websocket_message( comment_id, vec![], @@ -122,7 +125,6 @@ async fn undo_like_or_dislike_comment( }) .await??; - // TODO get those recipient actor ids from somewhere send_websocket_message( comment.id, vec![], diff --git a/crates/apub_receive/src/activities_new/comment/remove.rs b/crates/apub_receive/src/activities_new/comment/remove.rs index 44ee49af..38b85df0 100644 --- a/crates/apub_receive/src/activities_new/comment/remove.rs +++ b/crates/apub_receive/src/activities_new/comment/remove.rs @@ -17,7 +17,7 @@ use url::Url; pub struct RemoveComment { actor: Url, to: PublicUrl, - object: Url, + pub(in crate::activities_new::comment) object: Url, cc: [Url; 1], #[serde(rename = "type")] kind: RemoveType, @@ -47,7 +47,6 @@ impl ReceiveActivity for Activity { }) .await??; - // TODO get those recipient actor ids from somewhere send_websocket_message( removed_comment.id, vec![], diff --git a/crates/apub_receive/src/activities_new/comment/undo_delete.rs b/crates/apub_receive/src/activities_new/comment/undo_delete.rs new file mode 100644 index 00000000..be233bbd --- /dev/null +++ b/crates/apub_receive/src/activities_new/comment/undo_delete.rs @@ -0,0 +1,60 @@ +use crate::{ + activities_new::comment::{delete::DeleteComment, send_websocket_message}, + inbox::new_inbox_routing::Activity, +}; +use activitystreams::activity::kind::UndoType; +use lemmy_api_common::blocking; +use lemmy_apub::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_comment}; +use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; +use lemmy_db_queries::source::comment::Comment_; +use lemmy_db_schema::source::comment::Comment; +use lemmy_utils::LemmyError; +use lemmy_websocket::{LemmyContext, UserOperationCrud}; +use url::Url; + +#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] +#[serde(rename_all = "camelCase")] +pub struct UndoDeleteComment { + actor: Url, + to: PublicUrl, + object: Activity, + cc: [Url; 1], + #[serde(rename = "type")] + kind: UndoType, +} + +#[async_trait::async_trait(?Send)] +impl VerifyActivity for Activity { + async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { + verify_domains_match(&self.inner.actor, self.id_unchecked())?; + verify_domains_match(&self.inner.actor, &self.inner.object.inner.actor)?; + check_is_apub_id_valid(&self.inner.actor, false)?; + self.inner.object.verify(context).await + } +} + +#[async_trait::async_trait(?Send)] +impl ReceiveActivity for Activity { + async fn receive( + &self, + context: &LemmyContext, + request_counter: &mut i32, + ) -> Result<(), LemmyError> { + let comment = + get_or_fetch_and_insert_comment(&self.inner.object.inner.object, context, request_counter) + .await?; + + let deleted_comment = blocking(context.pool(), move |conn| { + Comment::update_deleted(conn, comment.id, false) + }) + .await??; + + send_websocket_message( + deleted_comment.id, + vec![], + UserOperationCrud::EditComment, + context, + ) + .await + } +} diff --git a/crates/apub_receive/src/activities_new/comment/undo_dislike.rs b/crates/apub_receive/src/activities_new/comment/undo_dislike.rs index 2da74339..428ab663 100644 --- a/crates/apub_receive/src/activities_new/comment/undo_dislike.rs +++ b/crates/apub_receive/src/activities_new/comment/undo_dislike.rs @@ -1,8 +1,5 @@ use crate::{ - activities_new::{ - comment::{dislike::DislikeComment, undo_like_or_dislike_comment}, - post::like::LikePost, - }, + activities_new::comment::{dislike::DislikeComment, undo_like_or_dislike_comment}, inbox::new_inbox_routing::Activity, }; use activitystreams::activity::kind::UndoType; diff --git a/crates/apub_receive/src/activities_new/comment/undo_like.rs b/crates/apub_receive/src/activities_new/comment/undo_like.rs index b4dfa99c..c09365f6 100644 --- a/crates/apub_receive/src/activities_new/comment/undo_like.rs +++ b/crates/apub_receive/src/activities_new/comment/undo_like.rs @@ -1,8 +1,5 @@ use crate::{ - activities_new::{ - comment::{like::LikeComment, undo_like_or_dislike_comment}, - post::like::LikePost, - }, + activities_new::comment::{like::LikeComment, undo_like_or_dislike_comment}, inbox::new_inbox_routing::Activity, }; use activitystreams::activity::kind::UndoType; diff --git a/crates/apub_receive/src/activities_new/comment/undo_remove.rs b/crates/apub_receive/src/activities_new/comment/undo_remove.rs new file mode 100644 index 00000000..63587a96 --- /dev/null +++ b/crates/apub_receive/src/activities_new/comment/undo_remove.rs @@ -0,0 +1,63 @@ +use crate::{ + activities_new::{ + comment::{remove::RemoveComment, send_websocket_message}, + verify_mod_action, + }, + inbox::new_inbox_routing::Activity, +}; +use activitystreams::activity::kind::UndoType; +use lemmy_api_common::blocking; +use lemmy_apub::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_comment}; +use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; +use lemmy_db_queries::source::comment::Comment_; +use lemmy_db_schema::source::comment::Comment; +use lemmy_utils::LemmyError; +use lemmy_websocket::{LemmyContext, UserOperationCrud}; +use url::Url; + +#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] +#[serde(rename_all = "camelCase")] +pub struct UndoRemoveComment { + actor: Url, + to: PublicUrl, + object: Activity, + cc: [Url; 1], + #[serde(rename = "type")] + kind: UndoType, +} + +#[async_trait::async_trait(?Send)] +impl VerifyActivity for Activity { + async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { + verify_domains_match(&self.inner.actor, self.id_unchecked())?; + check_is_apub_id_valid(&self.inner.actor, false)?; + verify_mod_action(self.inner.actor.clone(), self.inner.cc[0].clone(), context).await?; + self.inner.object.verify(context).await + } +} + +#[async_trait::async_trait(?Send)] +impl ReceiveActivity for Activity { + async fn receive( + &self, + context: &LemmyContext, + request_counter: &mut i32, + ) -> Result<(), LemmyError> { + let comment = + get_or_fetch_and_insert_comment(&self.inner.object.inner.object, context, request_counter) + .await?; + + let removed_comment = blocking(context.pool(), move |conn| { + Comment::update_removed(conn, comment.id, false) + }) + .await??; + + send_websocket_message( + removed_comment.id, + vec![], + UserOperationCrud::EditComment, + context, + ) + .await + } +} diff --git a/crates/apub_receive/src/activities_new/post/delete.rs b/crates/apub_receive/src/activities_new/post/delete.rs index 47b1fc97..8d98be31 100644 --- a/crates/apub_receive/src/activities_new/post/delete.rs +++ b/crates/apub_receive/src/activities_new/post/delete.rs @@ -12,9 +12,9 @@ use url::Url; #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[serde(rename_all = "camelCase")] pub struct DeletePost { - actor: Url, + pub(in crate::activities_new::post) actor: Url, to: PublicUrl, - object: Url, + pub(in crate::activities_new::post) object: Url, cc: [Url; 1], #[serde(rename = "type")] kind: DeleteType, diff --git a/crates/apub_receive/src/activities_new/post/mod.rs b/crates/apub_receive/src/activities_new/post/mod.rs index b8865f23..7004c0cb 100644 --- a/crates/apub_receive/src/activities_new/post/mod.rs +++ b/crates/apub_receive/src/activities_new/post/mod.rs @@ -18,8 +18,10 @@ pub mod delete; pub mod dislike; pub mod like; pub mod remove; +pub mod undo_delete; pub mod undo_dislike; pub mod undo_like; +pub mod undo_remove; pub mod update; async fn send_websocket_message( diff --git a/crates/apub_receive/src/activities_new/post/remove.rs b/crates/apub_receive/src/activities_new/post/remove.rs index f491feb7..7daafe88 100644 --- a/crates/apub_receive/src/activities_new/post/remove.rs +++ b/crates/apub_receive/src/activities_new/post/remove.rs @@ -17,7 +17,7 @@ use url::Url; pub struct RemovePost { actor: Url, to: PublicUrl, - object: Url, + pub(in crate::activities_new::post) object: Url, cc: [Url; 1], #[serde(rename = "type")] kind: RemoveType, @@ -39,7 +39,7 @@ impl ReceiveActivity for Activity { context: &LemmyContext, request_counter: &mut i32, ) -> Result<(), LemmyError> { - // TODO: check that actor is instance mod if community is local (same for RemoveComment) + // TODO: check that actor is instance mod if community is local (same for undo, RemoveComment) let post = get_or_fetch_and_insert_post(&self.inner.object, context, request_counter).await?; let removed_post = blocking(context.pool(), move |conn| { diff --git a/crates/apub_receive/src/activities_new/post/undo_delete.rs b/crates/apub_receive/src/activities_new/post/undo_delete.rs new file mode 100644 index 00000000..e57c419b --- /dev/null +++ b/crates/apub_receive/src/activities_new/post/undo_delete.rs @@ -0,0 +1,54 @@ +use crate::{ + activities_new::post::{delete::DeletePost, send_websocket_message}, + inbox::new_inbox_routing::Activity, +}; +use activitystreams::activity::kind::UndoType; +use lemmy_api_common::blocking; +use lemmy_apub::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_post}; +use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; +use lemmy_db_queries::source::post::Post_; +use lemmy_db_schema::source::post::Post; +use lemmy_utils::LemmyError; +use lemmy_websocket::{LemmyContext, UserOperationCrud}; +use url::Url; + +#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] +#[serde(rename_all = "camelCase")] +pub struct UndoDeletePost { + actor: Url, + to: PublicUrl, + object: Activity, + cc: [Url; 1], + #[serde(rename = "type")] + kind: UndoType, +} + +#[async_trait::async_trait(?Send)] +impl VerifyActivity for Activity { + async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { + verify_domains_match(&self.inner.actor, self.id_unchecked())?; + verify_domains_match(&self.inner.actor, &self.inner.object.inner.actor)?; + check_is_apub_id_valid(&self.inner.actor, false)?; + self.inner.object.verify(context).await + } +} + +#[async_trait::async_trait(?Send)] +impl ReceiveActivity for Activity { + async fn receive( + &self, + context: &LemmyContext, + request_counter: &mut i32, + ) -> Result<(), LemmyError> { + let post = + get_or_fetch_and_insert_post(&self.inner.object.inner.object, context, request_counter) + .await?; + + let deleted_post = blocking(context.pool(), move |conn| { + Post::update_deleted(conn, post.id, false) + }) + .await??; + + send_websocket_message(deleted_post.id, UserOperationCrud::EditPost, context).await + } +} diff --git a/crates/apub_receive/src/activities_new/post/undo_remove.rs b/crates/apub_receive/src/activities_new/post/undo_remove.rs new file mode 100644 index 00000000..891c32d6 --- /dev/null +++ b/crates/apub_receive/src/activities_new/post/undo_remove.rs @@ -0,0 +1,57 @@ +use crate::{ + activities_new::{ + post::{remove::RemovePost, send_websocket_message}, + verify_mod_action, + }, + inbox::new_inbox_routing::Activity, +}; +use activitystreams::activity::kind::UndoType; +use lemmy_api_common::blocking; +use lemmy_apub::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_post}; +use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; +use lemmy_db_queries::source::post::Post_; +use lemmy_db_schema::source::post::Post; +use lemmy_utils::LemmyError; +use lemmy_websocket::{LemmyContext, UserOperationCrud}; +use url::Url; + +#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] +#[serde(rename_all = "camelCase")] +pub struct UndoRemovePost { + actor: Url, + to: PublicUrl, + object: Activity, + cc: [Url; 1], + #[serde(rename = "type")] + kind: UndoType, +} + +#[async_trait::async_trait(?Send)] +impl VerifyActivity for Activity { + async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { + verify_domains_match(&self.inner.actor, self.id_unchecked())?; + check_is_apub_id_valid(&self.inner.actor, false)?; + verify_mod_action(self.inner.actor.clone(), self.inner.cc[0].clone(), context).await?; + self.inner.object.verify(context).await + } +} + +#[async_trait::async_trait(?Send)] +impl ReceiveActivity for Activity { + async fn receive( + &self, + context: &LemmyContext, + request_counter: &mut i32, + ) -> Result<(), LemmyError> { + let post = + get_or_fetch_and_insert_post(&self.inner.object.inner.object, context, request_counter) + .await?; + + let removed_post = blocking(context.pool(), move |conn| { + Post::update_removed(conn, post.id, false) + }) + .await??; + + send_websocket_message(removed_post.id, UserOperationCrud::EditPost, context).await + } +} diff --git a/crates/apub_receive/src/inbox/new_inbox_routing.rs b/crates/apub_receive/src/inbox/new_inbox_routing.rs index ccd3f9fe..3542f331 100644 --- a/crates/apub_receive/src/inbox/new_inbox_routing.rs +++ b/crates/apub_receive/src/inbox/new_inbox_routing.rs @@ -5,8 +5,10 @@ use crate::activities_new::{ dislike::DislikeComment, like::LikeComment, remove::RemoveComment, + undo_delete::UndoDeleteComment, undo_dislike::UndoDislikeComment, undo_like::UndoLikeComment, + undo_remove::UndoRemoveComment, update::UpdateComment, }, community::{ @@ -23,8 +25,10 @@ use crate::activities_new::{ dislike::DislikePost, like::LikePost, remove::RemovePost, + undo_delete::UndoDeletePost, undo_dislike::UndoDislikePost, undo_like::UndoLikePost, + undo_remove::UndoRemovePost, update::UpdatePost, }, private_message::{ @@ -81,13 +85,17 @@ pub enum PersonAcceptedActivitiesNew { UndoLikeComment(UndoLikeComment), UndoDislikeComment(UndoDislikeComment), DeleteComment(DeleteComment), + UndoDeleteComment(UndoDeleteComment), RemoveComment(RemoveComment), + UndoRemoveComment(UndoRemoveComment), CreatePost(CreatePost), UpdatePost(UpdatePost), LikePost(LikePost), DislikePost(DislikePost), DeletePost(DeletePost), + UndoDeletePost(UndoDeletePost), RemovePost(RemovePost), + UndoRemovePost(UndoRemovePost), UndoLikePost(UndoLikePost), UndoDislikePost(UndoDislikePost), UpdateCommunity(UpdateCommunity), diff --git a/crates/apub_receive/src/inbox/receive_for_community.rs b/crates/apub_receive/src/inbox/receive_for_community.rs index c3b39fb2..67f262ad 100644 --- a/crates/apub_receive/src/inbox/receive_for_community.rs +++ b/crates/apub_receive/src/inbox/receive_for_community.rs @@ -1,14 +1,9 @@ use crate::{ - activities::receive::{ - comment_undo::{receive_undo_delete_comment, receive_undo_remove_comment}, - post_undo::{receive_undo_delete_post, receive_undo_remove_post}, - receive_unhandled_activity, - verify_activity_domains_valid, - }, + activities::receive::{receive_unhandled_activity, verify_activity_domains_valid}, inbox::verify_is_addressed_to_public, }; use activitystreams::{ - activity::{ActorAndObjectRef, Add, Announce, Block, Delete, OptTargetRef, Remove, Undo}, + activity::{ActorAndObjectRef, Add, Announce, Block, OptTargetRef, Remove, Undo}, base::AnyBase, object::AsObject, prelude::*, @@ -17,12 +12,8 @@ use anyhow::{anyhow, Context}; use lemmy_api_common::blocking; use lemmy_apub::{ fetcher::person::get_or_fetch_and_upsert_person, - find_object_by_id, - find_post_or_comment_by_id, generate_moderators_url, CommunityType, - Object, - PostOrComment, }; use lemmy_db_queries::{ source::community::CommunityModerator_, @@ -135,12 +126,8 @@ pub(in crate::inbox) async fn receive_undo_for_community( .as_single_kind_str() .and_then(|s| s.parse().ok()) { - Some(Delete) => { - receive_undo_delete_for_community(context, undo, expected_domain, request_counter).await - } - Some(Remove) => { - receive_undo_remove_for_community(context, undo, announce, expected_domain).await - } + Some(Delete) => todo!(), + Some(Remove) => todo!(), Some(Like) => todo!(), Some(Dislike) => todo!(), Some(Block) => { @@ -157,63 +144,6 @@ pub(in crate::inbox) async fn receive_undo_for_community( } } -/// A post, comment or community deletion being reverted -pub(in crate::inbox) async fn receive_undo_delete_for_community( - context: &LemmyContext, - undo: Undo, - expected_domain: &Url, - _request_counter: &mut i32, -) -> Result<(), LemmyError> { - let delete = Delete::from_any_base(undo.object().to_owned().one().context(location_info!())?)? - .context(location_info!())?; - verify_is_addressed_to_public(&delete)?; - - let object = delete - .object() - .to_owned() - .single_xsd_any_uri() - .context(location_info!())?; - match find_object_by_id(context, object).await { - Ok(Object::Post(p)) => { - verify_activity_domains_valid(&delete, &expected_domain, true)?; - receive_undo_delete_post(context, *p).await - } - Ok(Object::Comment(c)) => { - verify_activity_domains_valid(&delete, &expected_domain, true)?; - receive_undo_delete_comment(context, *c).await - } - Ok(Object::Community(_)) => todo!(), - // if we dont have the object or dont support its deletion, no need to do anything - _ => Ok(()), - } -} - -/// A post or comment removal being reverted -pub(in crate::inbox) async fn receive_undo_remove_for_community( - context: &LemmyContext, - undo: Undo, - announce: Option, - expected_domain: &Url, -) -> Result<(), LemmyError> { - let remove = Remove::from_any_base(undo.object().to_owned().one().context(location_info!())?)? - .context(location_info!())?; - verify_activity_domains_valid(&remove, &expected_domain, false)?; - verify_is_addressed_to_public(&remove)?; - verify_undo_remove_actor_instance(&undo, &remove, &announce, context).await?; - - let object = remove - .object() - .to_owned() - .single_xsd_any_uri() - .context(location_info!())?; - match find_post_or_comment_by_id(context, object).await { - Ok(PostOrComment::Post(p)) => receive_undo_remove_post(context, *p).await, - Ok(PostOrComment::Comment(c)) => receive_undo_remove_comment(context, *c).await, - // if we dont have the object, no need to do anything - Err(_) => Ok(()), - } -} - /// Add a new mod to the community (can only be done by an existing mod). pub(in crate::inbox) async fn receive_add_for_community( context: &LemmyContext,