2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 post::{PostResponse, StickyPost},
8 check_community_deleted_or_removed,
9 get_local_user_view_from_jwt,
12 websocket::{send::send_post_ws_message, UserOperation},
14 use lemmy_db_schema::{
16 moderator::{ModStickyPost, ModStickyPostForm},
17 post::{Post, PostUpdateForm},
21 use lemmy_utils::{error::LemmyError, ConnectionId};
23 #[async_trait::async_trait(?Send)]
24 impl Perform for StickyPost {
25 type Response = PostResponse;
27 #[tracing::instrument(skip(context, websocket_id))]
30 context: &Data<LemmyContext>,
31 websocket_id: Option<ConnectionId>,
32 ) -> Result<PostResponse, LemmyError> {
33 let data: &StickyPost = self;
35 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
37 let post_id = data.post_id;
38 let orig_post = Post::read(context.pool(), post_id).await?;
41 local_user_view.person.id,
42 orig_post.community_id,
46 check_community_deleted_or_removed(orig_post.community_id, context.pool()).await?;
48 // Verify that only the mods can sticky
51 local_user_view.person.id,
52 orig_post.community_id,
57 let post_id = data.post_id;
58 let stickied = data.stickied;
62 &PostUpdateForm::builder().stickied(Some(stickied)).build(),
67 let form = ModStickyPostForm {
68 mod_person_id: local_user_view.person.id,
69 post_id: data.post_id,
70 stickied: Some(stickied),
73 ModStickyPost::create(context.pool(), &form).await?;
77 UserOperation::StickyPost,
79 Some(local_user_view.person.id),