1 use crate::activities::{
2 post::send_websocket_message,
5 verify_person_in_community,
7 use activitystreams::{activity::kind::UpdateType, base::BaseExt};
9 use lemmy_api_common::blocking;
11 objects::{FromApub, FromApubToForm},
15 use lemmy_apub_lib::{verify_domains_match_opt, ActivityCommonFields, ActivityHandler, PublicUrl};
16 use lemmy_db_queries::ApubObject;
17 use lemmy_db_schema::{
18 source::post::{Post, PostForm},
21 use lemmy_utils::{location_info, LemmyError};
22 use lemmy_websocket::{LemmyContext, UserOperationCrud};
25 #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
26 #[serde(rename_all = "camelCase")]
27 pub struct UpdatePost {
31 #[serde(rename = "type")]
34 common: ActivityCommonFields,
37 #[async_trait::async_trait(?Send)]
38 impl ActivityHandler for UpdatePost {
41 context: &LemmyContext,
42 request_counter: &mut i32,
43 ) -> Result<(), LemmyError> {
44 verify_activity(self.common())?;
46 verify_person_in_community(&self.common.actor, &self.cc, context, request_counter).await?;
48 let temp_post = PostForm::from_apub(
51 self.common.actor.clone(),
56 let post_id: DbUrl = temp_post.ap_id.context(location_info!())?;
57 let old_post = blocking(context.pool(), move |conn| {
58 Post::read_from_apub_id(conn, &post_id)
61 let stickied = temp_post.stickied.context(location_info!())?;
62 let locked = temp_post.locked.context(location_info!())?;
63 // community mod changed locked/sticky status
64 if (stickied != old_post.stickied) || (locked != old_post.locked) {
65 verify_mod_action(&self.common.actor, community.actor_id(), context).await?;
67 // user edited their own post
69 verify_domains_match_opt(&self.common.actor, self.object.id_unchecked())?;
77 context: &LemmyContext,
78 request_counter: &mut i32,
79 ) -> Result<(), LemmyError> {
80 let post = Post::from_apub(
83 self.common.actor.clone(),
85 // TODO: we already check here if the mod action is valid, can remove that check param
90 send_websocket_message(post.id, UserOperationCrud::EditPost, context).await
93 fn common(&self) -> &ActivityCommonFields {