2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 post::{PostResponse, StickyPost},
7 check_community_deleted_or_removed,
8 get_local_user_view_from_jwt,
13 objects::post::ApubPost,
14 protocol::activities::{create_or_update::page::CreateOrUpdatePage, CreateOrUpdateType},
16 use lemmy_db_schema::{
18 moderator::{ModStickyPost, ModStickyPostForm},
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 StickyPost {
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: &StickyPost = 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 sticky
54 local_user_view.person.id,
55 orig_post.community_id,
60 let post_id = data.post_id;
61 let stickied = data.stickied;
62 let updated_post: ApubPost = Post::update(
65 &PostUpdateForm::builder().stickied(Some(stickied)).build(),
71 let form = ModStickyPostForm {
72 mod_person_id: local_user_view.person.id,
73 post_id: data.post_id,
74 stickied: Some(stickied),
77 ModStickyPost::create(context.pool(), &form).await?;
80 // TODO stickied should pry work like locked for ease of use
81 CreateOrUpdatePage::send(
83 &local_user_view.person.clone().into(),
84 CreateOrUpdateType::Update,
91 UserOperation::StickyPost,
93 Some(local_user_view.person.id),