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,
11 websocket::{send::send_post_ws_message, UserOperation},
15 objects::post::ApubPost,
16 protocol::activities::{create_or_update::page::CreateOrUpdatePage, CreateOrUpdateType},
18 use lemmy_db_schema::{
20 moderator::{ModLockPost, ModLockPostForm},
21 post::{Post, PostUpdateForm},
25 use lemmy_utils::{error::LemmyError, ConnectionId};
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 = Post::read(context.pool(), 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 = Post::update(
66 &PostUpdateForm::builder().locked(Some(locked)).build(),
72 let form = ModLockPostForm {
73 mod_person_id: local_user_view.person.id,
74 post_id: data.post_id,
77 ModLockPost::create(context.pool(), &form).await?;
80 CreateOrUpdatePage::send(
82 &local_user_view.person.clone().into(),
83 CreateOrUpdateType::Update,
90 UserOperation::LockPost,
92 Some(local_user_view.person.id),