2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 post::{LockPost, PostResponse},
8 check_community_deleted_or_removed,
9 get_local_user_view_from_jwt,
14 objects::post::ApubPost,
15 protocol::activities::{create_or_update::post::CreateOrUpdatePost, CreateOrUpdateType},
17 use lemmy_db_schema::{
19 moderator::{ModLockPost, ModLockPostForm},
20 post::{Post, PostUpdateForm},
24 use lemmy_utils::{error::LemmyError, ConnectionId};
25 use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperation};
27 #[async_trait::async_trait(?Send)]
28 impl Perform for LockPost {
29 type Response = PostResponse;
31 #[tracing::instrument(skip(context, websocket_id))]
34 context: &Data<LemmyContext>,
35 websocket_id: Option<ConnectionId>,
36 ) -> Result<PostResponse, LemmyError> {
37 let data: &LockPost = self;
39 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
41 let post_id = data.post_id;
42 let orig_post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
45 local_user_view.person.id,
46 orig_post.community_id,
50 check_community_deleted_or_removed(orig_post.community_id, context.pool()).await?;
52 // Verify that only the mods can lock
55 local_user_view.person.id,
56 orig_post.community_id,
61 let post_id = data.post_id;
62 let locked = data.locked;
63 let updated_post: ApubPost = blocking(context.pool(), move |conn| {
67 &PostUpdateForm::builder().locked(Some(locked)).build(),
74 let form = ModLockPostForm {
75 mod_person_id: local_user_view.person.id,
76 post_id: data.post_id,
79 blocking(context.pool(), move |conn| ModLockPost::create(conn, &form)).await??;
82 CreateOrUpdatePost::send(
84 &local_user_view.person.clone().into(),
85 CreateOrUpdateType::Update,
92 UserOperation::LockPost,
94 Some(local_user_view.person.id),