convert undo_delete and undo_remove receivers

This commit is contained in:
Felix Ableitner 2021-06-29 03:08:47 +02:00
parent 004a07c41b
commit ab5b072e21
17 changed files with 261 additions and 232 deletions

View file

@ -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(())
}

View file

@ -4,17 +4,11 @@ use activitystreams::{
error::DomainError, error::DomainError,
}; };
use anyhow::{anyhow, Context}; 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_utils::{location_info, LemmyError};
use lemmy_websocket::LemmyContext;
use log::debug; use log::debug;
use std::fmt::Debug; use std::fmt::Debug;
use url::Url; use url::Url;
pub(crate) mod comment_undo;
pub(crate) mod post_undo;
/// Return HTTP 501 for unsupported activities in inbox. /// Return HTTP 501 for unsupported activities in inbox.
pub(crate) fn receive_unhandled_activity<A>(activity: A) -> Result<(), LemmyError> pub(crate) fn receive_unhandled_activity<A>(activity: A) -> Result<(), LemmyError>
where where

View file

@ -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(())
}

View file

@ -12,9 +12,9 @@ use url::Url;
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct DeleteComment { pub struct DeleteComment {
actor: Url, pub(in crate::activities_new::comment) actor: Url,
to: PublicUrl, to: PublicUrl,
object: Url, pub(in crate::activities_new::comment) object: Url,
cc: [Url; 1], cc: [Url; 1],
#[serde(rename = "type")] #[serde(rename = "type")]
kind: DeleteType, kind: DeleteType,
@ -44,7 +44,6 @@ impl ReceiveActivity for Activity<DeleteComment> {
}) })
.await??; .await??;
// TODO get those recipient actor ids from somewhere
send_websocket_message( send_websocket_message(
deleted_comment.id, deleted_comment.id,
vec![], vec![],

View file

@ -22,8 +22,10 @@ pub mod delete;
pub mod dislike; pub mod dislike;
pub mod like; pub mod like;
pub mod remove; pub mod remove;
pub mod undo_delete;
pub mod undo_dislike; pub mod undo_dislike;
pub mod undo_like; pub mod undo_like;
pub mod undo_remove;
pub mod update; pub mod update;
async fn get_notif_recipients( 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 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<OP: ToString + Send + lemmy_websocket::OperationType + 'static>( async fn send_websocket_message<OP: ToString + Send + lemmy_websocket::OperationType + 'static>(
comment_id: CommentId, comment_id: CommentId,
recipient_ids: Vec<LocalUserId>, recipient_ids: Vec<LocalUserId>,
@ -96,7 +100,6 @@ async fn like_or_dislike_comment(
}) })
.await??; .await??;
// TODO get those recipient actor ids from somewhere
send_websocket_message( send_websocket_message(
comment_id, comment_id,
vec![], vec![],
@ -122,7 +125,6 @@ async fn undo_like_or_dislike_comment(
}) })
.await??; .await??;
// TODO get those recipient actor ids from somewhere
send_websocket_message( send_websocket_message(
comment.id, comment.id,
vec![], vec![],

View file

@ -17,7 +17,7 @@ use url::Url;
pub struct RemoveComment { pub struct RemoveComment {
actor: Url, actor: Url,
to: PublicUrl, to: PublicUrl,
object: Url, pub(in crate::activities_new::comment) object: Url,
cc: [Url; 1], cc: [Url; 1],
#[serde(rename = "type")] #[serde(rename = "type")]
kind: RemoveType, kind: RemoveType,
@ -47,7 +47,6 @@ impl ReceiveActivity for Activity<RemoveComment> {
}) })
.await??; .await??;
// TODO get those recipient actor ids from somewhere
send_websocket_message( send_websocket_message(
removed_comment.id, removed_comment.id,
vec![], vec![],

View file

@ -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<DeleteComment>,
cc: [Url; 1],
#[serde(rename = "type")]
kind: UndoType,
}
#[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<UndoDeleteComment> {
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<UndoDeleteComment> {
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
}
}

View file

@ -1,8 +1,5 @@
use crate::{ use crate::{
activities_new::{ activities_new::comment::{dislike::DislikeComment, undo_like_or_dislike_comment},
comment::{dislike::DislikeComment, undo_like_or_dislike_comment},
post::like::LikePost,
},
inbox::new_inbox_routing::Activity, inbox::new_inbox_routing::Activity,
}; };
use activitystreams::activity::kind::UndoType; use activitystreams::activity::kind::UndoType;

View file

@ -1,8 +1,5 @@
use crate::{ use crate::{
activities_new::{ activities_new::comment::{like::LikeComment, undo_like_or_dislike_comment},
comment::{like::LikeComment, undo_like_or_dislike_comment},
post::like::LikePost,
},
inbox::new_inbox_routing::Activity, inbox::new_inbox_routing::Activity,
}; };
use activitystreams::activity::kind::UndoType; use activitystreams::activity::kind::UndoType;

View file

@ -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<RemoveComment>,
cc: [Url; 1],
#[serde(rename = "type")]
kind: UndoType,
}
#[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<UndoRemoveComment> {
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<UndoRemoveComment> {
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
}
}

View file

@ -12,9 +12,9 @@ use url::Url;
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct DeletePost { pub struct DeletePost {
actor: Url, pub(in crate::activities_new::post) actor: Url,
to: PublicUrl, to: PublicUrl,
object: Url, pub(in crate::activities_new::post) object: Url,
cc: [Url; 1], cc: [Url; 1],
#[serde(rename = "type")] #[serde(rename = "type")]
kind: DeleteType, kind: DeleteType,

View file

@ -18,8 +18,10 @@ pub mod delete;
pub mod dislike; pub mod dislike;
pub mod like; pub mod like;
pub mod remove; pub mod remove;
pub mod undo_delete;
pub mod undo_dislike; pub mod undo_dislike;
pub mod undo_like; pub mod undo_like;
pub mod undo_remove;
pub mod update; pub mod update;
async fn send_websocket_message<OP: ToString + Send + lemmy_websocket::OperationType + 'static>( async fn send_websocket_message<OP: ToString + Send + lemmy_websocket::OperationType + 'static>(

View file

@ -17,7 +17,7 @@ use url::Url;
pub struct RemovePost { pub struct RemovePost {
actor: Url, actor: Url,
to: PublicUrl, to: PublicUrl,
object: Url, pub(in crate::activities_new::post) object: Url,
cc: [Url; 1], cc: [Url; 1],
#[serde(rename = "type")] #[serde(rename = "type")]
kind: RemoveType, kind: RemoveType,
@ -39,7 +39,7 @@ impl ReceiveActivity for Activity<RemovePost> {
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> 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 post = get_or_fetch_and_insert_post(&self.inner.object, context, request_counter).await?;
let removed_post = blocking(context.pool(), move |conn| { let removed_post = blocking(context.pool(), move |conn| {

View file

@ -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<DeletePost>,
cc: [Url; 1],
#[serde(rename = "type")]
kind: UndoType,
}
#[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<UndoDeletePost> {
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<UndoDeletePost> {
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
}
}

View file

@ -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<RemovePost>,
cc: [Url; 1],
#[serde(rename = "type")]
kind: UndoType,
}
#[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<UndoRemovePost> {
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<UndoRemovePost> {
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
}
}

View file

@ -5,8 +5,10 @@ use crate::activities_new::{
dislike::DislikeComment, dislike::DislikeComment,
like::LikeComment, like::LikeComment,
remove::RemoveComment, remove::RemoveComment,
undo_delete::UndoDeleteComment,
undo_dislike::UndoDislikeComment, undo_dislike::UndoDislikeComment,
undo_like::UndoLikeComment, undo_like::UndoLikeComment,
undo_remove::UndoRemoveComment,
update::UpdateComment, update::UpdateComment,
}, },
community::{ community::{
@ -23,8 +25,10 @@ use crate::activities_new::{
dislike::DislikePost, dislike::DislikePost,
like::LikePost, like::LikePost,
remove::RemovePost, remove::RemovePost,
undo_delete::UndoDeletePost,
undo_dislike::UndoDislikePost, undo_dislike::UndoDislikePost,
undo_like::UndoLikePost, undo_like::UndoLikePost,
undo_remove::UndoRemovePost,
update::UpdatePost, update::UpdatePost,
}, },
private_message::{ private_message::{
@ -81,13 +85,17 @@ pub enum PersonAcceptedActivitiesNew {
UndoLikeComment(UndoLikeComment), UndoLikeComment(UndoLikeComment),
UndoDislikeComment(UndoDislikeComment), UndoDislikeComment(UndoDislikeComment),
DeleteComment(DeleteComment), DeleteComment(DeleteComment),
UndoDeleteComment(UndoDeleteComment),
RemoveComment(RemoveComment), RemoveComment(RemoveComment),
UndoRemoveComment(UndoRemoveComment),
CreatePost(CreatePost), CreatePost(CreatePost),
UpdatePost(UpdatePost), UpdatePost(UpdatePost),
LikePost(LikePost), LikePost(LikePost),
DislikePost(DislikePost), DislikePost(DislikePost),
DeletePost(DeletePost), DeletePost(DeletePost),
UndoDeletePost(UndoDeletePost),
RemovePost(RemovePost), RemovePost(RemovePost),
UndoRemovePost(UndoRemovePost),
UndoLikePost(UndoLikePost), UndoLikePost(UndoLikePost),
UndoDislikePost(UndoDislikePost), UndoDislikePost(UndoDislikePost),
UpdateCommunity(UpdateCommunity), UpdateCommunity(UpdateCommunity),

View file

@ -1,14 +1,9 @@
use crate::{ use crate::{
activities::receive::{ activities::receive::{receive_unhandled_activity, verify_activity_domains_valid},
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,
},
inbox::verify_is_addressed_to_public, inbox::verify_is_addressed_to_public,
}; };
use activitystreams::{ use activitystreams::{
activity::{ActorAndObjectRef, Add, Announce, Block, Delete, OptTargetRef, Remove, Undo}, activity::{ActorAndObjectRef, Add, Announce, Block, OptTargetRef, Remove, Undo},
base::AnyBase, base::AnyBase,
object::AsObject, object::AsObject,
prelude::*, prelude::*,
@ -17,12 +12,8 @@ use anyhow::{anyhow, Context};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub::{ use lemmy_apub::{
fetcher::person::get_or_fetch_and_upsert_person, fetcher::person::get_or_fetch_and_upsert_person,
find_object_by_id,
find_post_or_comment_by_id,
generate_moderators_url, generate_moderators_url,
CommunityType, CommunityType,
Object,
PostOrComment,
}; };
use lemmy_db_queries::{ use lemmy_db_queries::{
source::community::CommunityModerator_, source::community::CommunityModerator_,
@ -135,12 +126,8 @@ pub(in crate::inbox) async fn receive_undo_for_community(
.as_single_kind_str() .as_single_kind_str()
.and_then(|s| s.parse().ok()) .and_then(|s| s.parse().ok())
{ {
Some(Delete) => { Some(Delete) => todo!(),
receive_undo_delete_for_community(context, undo, expected_domain, request_counter).await Some(Remove) => todo!(),
}
Some(Remove) => {
receive_undo_remove_for_community(context, undo, announce, expected_domain).await
}
Some(Like) => todo!(), Some(Like) => todo!(),
Some(Dislike) => todo!(), Some(Dislike) => todo!(),
Some(Block) => { 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<Announce>,
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). /// 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( pub(in crate::inbox) async fn receive_add_for_community(
context: &LemmyContext, context: &LemmyContext,