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;
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 {
Community::update(
&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,
Post::update(
&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,
Comment::update(
&mut context.pool(),
comment.id,
- &CommentUpdateForm::builder().removed(Some(true)).build(),
+ &CommentUpdateForm {
+ removed: Some(true),
+ ..Default::default()
+ },
)
.await?;
}