2023-08-02 16:52:41 +00:00
|
|
|
use activitypub_federation::config::Data;
|
|
|
|
use actix_web::web::Json;
|
2022-05-03 17:44:13 +00:00
|
|
|
use lemmy_api_common::{
|
2023-07-20 14:36:16 +00:00
|
|
|
build_response::build_post_response,
|
2022-11-28 14:29:33 +00:00
|
|
|
context::LemmyContext,
|
2022-05-03 17:44:13 +00:00
|
|
|
post::{PostResponse, RemovePost},
|
2023-08-02 16:52:41 +00:00
|
|
|
send_activity::{ActivityChannel, SendActivityData},
|
2023-10-13 13:48:18 +00:00
|
|
|
utils::check_community_mod_action,
|
2022-05-03 17:44:13 +00:00
|
|
|
};
|
|
|
|
use lemmy_db_schema::{
|
|
|
|
source::{
|
|
|
|
moderator::{ModRemovePost, ModRemovePostForm},
|
2022-10-27 09:24:07 +00:00
|
|
|
post::{Post, PostUpdateForm},
|
2024-02-15 13:52:04 +00:00
|
|
|
post_report::PostReport,
|
2022-05-03 17:44:13 +00:00
|
|
|
},
|
2024-02-15 13:52:04 +00:00
|
|
|
traits::{Crud, Reportable},
|
2022-05-03 17:44:13 +00:00
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
use lemmy_db_views::structs::LocalUserView;
|
2024-04-16 12:48:15 +00:00
|
|
|
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
2022-05-03 17:44:13 +00:00
|
|
|
|
2023-08-02 16:52:41 +00:00
|
|
|
#[tracing::instrument(skip(context))]
|
|
|
|
pub async fn remove_post(
|
|
|
|
data: Json<RemovePost>,
|
|
|
|
context: Data<LemmyContext>,
|
2023-09-21 10:42:28 +00:00
|
|
|
local_user_view: LocalUserView,
|
2024-04-10 14:14:11 +00:00
|
|
|
) -> LemmyResult<Json<PostResponse>> {
|
2023-08-02 16:52:41 +00:00
|
|
|
let post_id = data.post_id;
|
2024-04-16 12:48:15 +00:00
|
|
|
let orig_post = Post::read(&mut context.pool(), post_id)
|
|
|
|
.await?
|
|
|
|
.ok_or(LemmyErrorType::CouldntFindPost)?;
|
2022-05-03 17:44:13 +00:00
|
|
|
|
2023-10-13 13:48:18 +00:00
|
|
|
check_community_mod_action(
|
|
|
|
&local_user_view.person,
|
2023-08-02 16:52:41 +00:00
|
|
|
orig_post.community_id,
|
2023-10-13 13:48:18 +00:00
|
|
|
false,
|
2023-08-02 16:52:41 +00:00
|
|
|
&mut context.pool(),
|
|
|
|
)
|
|
|
|
.await?;
|
2022-05-03 17:44:13 +00:00
|
|
|
|
2023-08-02 16:52:41 +00:00
|
|
|
// Update the post
|
|
|
|
let post_id = data.post_id;
|
|
|
|
let removed = data.removed;
|
|
|
|
let post = Post::update(
|
|
|
|
&mut context.pool(),
|
|
|
|
post_id,
|
2023-08-08 09:41:41 +00:00
|
|
|
&PostUpdateForm {
|
|
|
|
removed: Some(removed),
|
|
|
|
..Default::default()
|
|
|
|
},
|
2023-08-02 16:52:41 +00:00
|
|
|
)
|
|
|
|
.await?;
|
2022-05-03 17:44:13 +00:00
|
|
|
|
2024-02-15 13:52:04 +00:00
|
|
|
PostReport::resolve_all_for_object(&mut context.pool(), post_id, local_user_view.person.id)
|
|
|
|
.await?;
|
|
|
|
|
2023-08-02 16:52:41 +00:00
|
|
|
// Mod tables
|
|
|
|
let form = ModRemovePostForm {
|
|
|
|
mod_person_id: local_user_view.person.id,
|
|
|
|
post_id: data.post_id,
|
|
|
|
removed: Some(removed),
|
|
|
|
reason: data.reason.clone(),
|
|
|
|
};
|
|
|
|
ModRemovePost::create(&mut context.pool(), &form).await?;
|
2022-05-03 17:44:13 +00:00
|
|
|
|
2023-08-02 16:52:41 +00:00
|
|
|
ActivityChannel::submit_activity(
|
2024-01-25 14:24:09 +00:00
|
|
|
SendActivityData::RemovePost {
|
|
|
|
post,
|
|
|
|
moderator: local_user_view.person.clone(),
|
|
|
|
reason: data.reason.clone(),
|
|
|
|
removed: data.removed,
|
|
|
|
},
|
2023-08-02 16:52:41 +00:00
|
|
|
&context,
|
|
|
|
)
|
|
|
|
.await?;
|
2022-05-03 17:44:13 +00:00
|
|
|
|
2023-10-13 13:48:18 +00:00
|
|
|
build_post_response(
|
|
|
|
&context,
|
|
|
|
orig_post.community_id,
|
|
|
|
&local_user_view.person,
|
|
|
|
post_id,
|
|
|
|
)
|
|
|
|
.await
|
2022-05-03 17:44:13 +00:00
|
|
|
}
|