2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 post::{LockPost, PostResponse},
7 check_community_deleted_or_removed,
8 get_local_user_view_from_jwt,
13 objects::post::ApubPost,
14 protocol::activities::{create_or_update::post::CreateOrUpdatePost, CreateOrUpdateType},
16 use lemmy_db_schema::{
18 moderator::{ModLockPost, ModLockPostForm},
19 post::{Post, PostUpdateForm},
23 use lemmy_utils::{error::LemmyError, ConnectionId};
24 use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperation};
26 #[async_trait::async_trait(?Send)]
27 impl Perform for LockPost {
28 type Response = PostResponse;
30 #[tracing::instrument(skip(context, websocket_id))]
33 context: &Data<LemmyContext>,
34 websocket_id: Option<ConnectionId>,
35 ) -> Result<PostResponse, LemmyError> {
36 let data: &LockPost = self;
38 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
40 let post_id = data.post_id;
41 let orig_post = Post::read(context.pool(), post_id).await?;
44 local_user_view.person.id,
45 orig_post.community_id,
49 check_community_deleted_or_removed(orig_post.community_id, context.pool()).await?;
51 // Verify that only the mods can lock
54 local_user_view.person.id,
55 orig_post.community_id,
60 let post_id = data.post_id;
61 let locked = data.locked;
62 let updated_post: ApubPost = Post::update(
65 &PostUpdateForm::builder().locked(Some(locked)).build(),
71 let form = ModLockPostForm {
72 mod_person_id: local_user_view.person.id,
73 post_id: data.post_id,
76 ModLockPost::create(context.pool(), &form).await?;
79 CreateOrUpdatePost::send(
81 &local_user_view.person.clone().into(),
82 CreateOrUpdateType::Update,
89 UserOperation::LockPost,
91 Some(local_user_view.person.id),