2023-08-02 16:52:41 +00:00
|
|
|
use activitypub_federation::config::Data;
|
|
|
|
use actix_web::web::Json;
|
2022-04-13 18:12:25 +00:00
|
|
|
use lemmy_api_common::{
|
2023-06-06 16:27:22 +00:00
|
|
|
build_response::build_post_response,
|
2022-11-28 14:29:33 +00:00
|
|
|
context::LemmyContext,
|
2022-04-13 18:12:25 +00:00
|
|
|
post::{LockPost, PostResponse},
|
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-04-13 18:12:25 +00:00
|
|
|
};
|
|
|
|
use lemmy_db_schema::{
|
|
|
|
source::{
|
2024-11-28 23:21:43 +00:00
|
|
|
mod_log::moderator::{ModLockPost, ModLockPostForm},
|
2022-10-27 09:24:07 +00:00
|
|
|
post::{Post, PostUpdateForm},
|
2022-04-13 18:12:25 +00:00
|
|
|
},
|
|
|
|
traits::Crud,
|
|
|
|
};
|
2024-11-07 10:49:05 +00:00
|
|
|
use lemmy_db_views::structs::{LocalUserView, PostView};
|
2024-09-23 15:26:50 +00:00
|
|
|
use lemmy_utils::error::LemmyResult;
|
2022-04-13 18:12:25 +00:00
|
|
|
|
2023-08-02 16:52:41 +00:00
|
|
|
#[tracing::instrument(skip(context))]
|
|
|
|
pub async fn lock_post(
|
|
|
|
data: Json<LockPost>,
|
|
|
|
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-11-07 10:49:05 +00:00
|
|
|
let orig_post = PostView::read(&mut context.pool(), post_id, None, false).await?;
|
2022-04-13 18:12:25 +00:00
|
|
|
|
2023-10-13 13:48:18 +00:00
|
|
|
check_community_mod_action(
|
|
|
|
&local_user_view.person,
|
2024-11-07 10:49:05 +00:00
|
|
|
&orig_post.community,
|
2023-10-13 13:48:18 +00:00
|
|
|
false,
|
2023-08-02 16:52:41 +00:00
|
|
|
&mut context.pool(),
|
|
|
|
)
|
|
|
|
.await?;
|
2022-04-13 18:12:25 +00:00
|
|
|
|
2023-08-02 16:52:41 +00:00
|
|
|
// Update the post
|
|
|
|
let post_id = data.post_id;
|
|
|
|
let locked = data.locked;
|
|
|
|
let post = Post::update(
|
|
|
|
&mut context.pool(),
|
|
|
|
post_id,
|
2023-08-08 09:41:41 +00:00
|
|
|
&PostUpdateForm {
|
|
|
|
locked: Some(locked),
|
|
|
|
..Default::default()
|
|
|
|
},
|
2023-08-02 16:52:41 +00:00
|
|
|
)
|
|
|
|
.await?;
|
2022-04-13 18:12:25 +00:00
|
|
|
|
2023-08-02 16:52:41 +00:00
|
|
|
// Mod tables
|
|
|
|
let form = ModLockPostForm {
|
|
|
|
mod_person_id: local_user_view.person.id,
|
|
|
|
post_id: data.post_id,
|
|
|
|
locked: Some(locked),
|
|
|
|
};
|
|
|
|
ModLockPost::create(&mut context.pool(), &form).await?;
|
2022-04-13 18:12:25 +00:00
|
|
|
|
2023-08-02 16:52:41 +00:00
|
|
|
ActivityChannel::submit_activity(
|
2023-10-13 13:48:18 +00:00
|
|
|
SendActivityData::LockPost(post, local_user_view.person.clone(), data.locked),
|
2023-08-02 16:52:41 +00:00
|
|
|
&context,
|
2024-11-07 10:49:05 +00:00
|
|
|
)?;
|
2022-04-13 18:12:25 +00:00
|
|
|
|
2024-11-07 10:49:05 +00:00
|
|
|
build_post_response(&context, orig_post.community.id, local_user_view, post_id).await
|
2022-04-13 18:12:25 +00:00
|
|
|
}
|