deletion::{receive_delete_action, verify_delete_activity, DeletableObjects},
generate_activity_id,
},
- insert_activity,
+ insert_received_activity,
objects::person::ApubPerson,
protocol::{activities::deletion::delete::Delete, IdOrNestedObject},
};
use activitypub_federation::{config::Data, kinds::activity::DeleteType, traits::ActivityHandler};
-use lemmy_api_common::context::LemmyContext;
+use lemmy_api_common::{context::LemmyContext, utils::sanitize_html_opt};
use lemmy_db_schema::{
source::{
comment::{Comment, CommentUpdateForm},
+ comment_report::CommentReport,
community::{Community, CommunityUpdateForm},
moderator::{
ModRemoveComment,
ModRemovePostForm,
},
post::{Post, PostUpdateForm},
+ post_report::PostReport,
},
- traits::Crud,
+ traits::{Crud, Reportable},
};
use lemmy_utils::error::{LemmyError, LemmyErrorType};
use url::Url;
#[tracing::instrument(skip_all)]
async fn verify(&self, context: &Data<Self::DataType>) -> Result<(), LemmyError> {
+ insert_received_activity(&self.id, context).await?;
verify_delete_activity(self, self.summary.is_some(), context).await?;
Ok(())
}
#[tracing::instrument(skip_all)]
async fn receive(self, context: &Data<LemmyContext>) -> Result<(), LemmyError> {
- insert_activity(&self.id, &self, false, false, context).await?;
if let Some(reason) = self.summary {
// We set reason to empty string if it doesn't exist, to distinguish between delete and
// remove. Here we change it back to option, so we don't write it to db.
reason: Option<String>,
context: &Data<LemmyContext>,
) -> Result<(), LemmyError> {
+ let reason = sanitize_html_opt(&reason);
+
match DeletableObjects::read_from_db(object, context).await? {
DeletableObjects::Community(community) => {
if community.local {
reason,
expires: None,
};
- ModRemoveCommunity::create(context.pool(), &form).await?;
+ ModRemoveCommunity::create(&mut context.pool(), &form).await?;
Community::update(
- context.pool(),
+ &mut context.pool(),
community.id,
- &CommunityUpdateForm::builder().removed(Some(true)).build(),
+ &CommunityUpdateForm {
+ removed: Some(true),
+ ..Default::default()
+ },
)
.await?;
}
DeletableObjects::Post(post) => {
+ PostReport::resolve_all_for_object(&mut context.pool(), post.id, actor.id).await?;
let form = ModRemovePostForm {
mod_person_id: actor.id,
post_id: post.id,
removed: Some(true),
reason,
};
- ModRemovePost::create(context.pool(), &form).await?;
+ ModRemovePost::create(&mut context.pool(), &form).await?;
Post::update(
- context.pool(),
+ &mut context.pool(),
post.id,
- &PostUpdateForm::builder().removed(Some(true)).build(),
+ &PostUpdateForm {
+ removed: Some(true),
+ ..Default::default()
+ },
)
.await?;
}
DeletableObjects::Comment(comment) => {
+ CommentReport::resolve_all_for_object(&mut context.pool(), comment.id, actor.id).await?;
let form = ModRemoveCommentForm {
mod_person_id: actor.id,
comment_id: comment.id,
removed: Some(true),
reason,
};
- ModRemoveComment::create(context.pool(), &form).await?;
+ ModRemoveComment::create(&mut context.pool(), &form).await?;
Comment::update(
- context.pool(),
+ &mut context.pool(),
comment.id,
- &CommentUpdateForm::builder().removed(Some(true)).build(),
+ &CommentUpdateForm {
+ removed: Some(true),
+ ..Default::default()
+ },
)
.await?;
}