2 use actix_web::web::Data;
3 use lemmy_api_common::{
6 check_community_deleted_or_removed,
7 get_local_user_view_from_jwt,
9 post::{LockPost, PostResponse},
12 objects::post::ApubPost,
13 protocol::activities::{create_or_update::post::CreateOrUpdatePost, CreateOrUpdateType},
15 use lemmy_db_schema::{
17 moderator::{ModLockPost, ModLockPostForm},
22 use lemmy_utils::{ConnectionId, LemmyError};
23 use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperation};
25 #[async_trait::async_trait(?Send)]
26 impl Perform for LockPost {
27 type Response = PostResponse;
29 #[tracing::instrument(skip(context, websocket_id))]
32 context: &Data<LemmyContext>,
33 websocket_id: Option<ConnectionId>,
34 ) -> Result<PostResponse, LemmyError> {
35 let data: &LockPost = self;
37 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
39 let post_id = data.post_id;
40 let orig_post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
43 local_user_view.person.id,
44 orig_post.community_id,
48 check_community_deleted_or_removed(orig_post.community_id, context.pool()).await?;
50 // Verify that only the mods can lock
53 local_user_view.person.id,
54 orig_post.community_id,
59 let post_id = data.post_id;
60 let locked = data.locked;
61 let updated_post: ApubPost = blocking(context.pool(), move |conn| {
62 Post::update_locked(conn, post_id, locked)
68 let form = ModLockPostForm {
69 mod_person_id: local_user_view.person.id,
70 post_id: data.post_id,
73 blocking(context.pool(), move |conn| ModLockPost::create(conn, &form)).await??;
76 CreateOrUpdatePost::send(
78 &local_user_view.person.clone().into(),
79 CreateOrUpdateType::Update,
86 UserOperation::LockPost,
88 Some(local_user_view.person.id),