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::{PostResponse, StickyPost},
12 objects::post::ApubPost,
13 protocol::activities::{create_or_update::post::CreateOrUpdatePost, CreateOrUpdateType},
15 use lemmy_db_schema::{
17 moderator::{ModStickyPost, ModStickyPostForm},
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 StickyPost {
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: &StickyPost = 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 sticky
53 local_user_view.person.id,
54 orig_post.community_id,
59 let post_id = data.post_id;
60 let stickied = data.stickied;
61 let updated_post: ApubPost = blocking(context.pool(), move |conn| {
62 Post::update_stickied(conn, post_id, stickied)
68 let form = ModStickyPostForm {
69 mod_person_id: local_user_view.person.id,
70 post_id: data.post_id,
71 stickied: Some(stickied),
73 blocking(context.pool(), move |conn| {
74 ModStickyPost::create(conn, &form)
79 // TODO stickied should pry work like locked for ease of use
80 CreateOrUpdatePost::send(
82 &local_user_view.person.clone().into(),
83 CreateOrUpdateType::Update,
90 UserOperation::StickyPost,
92 Some(local_user_view.person.id),