3 check_community_deleted_or_removed,
4 comment::{collect_non_local_mentions, get_notif_recipients},
5 community::{announce::GetCommunity, send_activity_in_community},
9 verify_person_in_community,
11 activity_lists::AnnouncableActivities,
12 objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson},
13 protocol::activities::{create_or_update::comment::CreateOrUpdateComment, CreateOrUpdateType},
15 use activitystreams::public;
16 use lemmy_api_common::{blocking, check_post_deleted_or_removed};
20 traits::{ActivityHandler, ActorType, ApubObject},
21 verify::verify_domains_match,
23 use lemmy_db_schema::{
24 source::{community::Community, post::Post},
27 use lemmy_utils::LemmyError;
28 use lemmy_websocket::{send::send_comment_ws_message, LemmyContext, UserOperationCrud};
30 impl CreateOrUpdateComment {
34 kind: CreateOrUpdateType,
35 context: &LemmyContext,
36 ) -> Result<(), LemmyError> {
37 // TODO: might be helpful to add a comment method to retrieve community directly
38 let post_id = comment.post_id;
39 let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
40 let community_id = post.community_id;
41 let community: ApubCommunity = blocking(context.pool(), move |conn| {
42 Community::read(conn, community_id)
47 let id = generate_activity_id(
49 &context.settings().get_protocol_and_hostname(),
51 let maa = collect_non_local_mentions(&comment, &community, context).await?;
53 let create_or_update = CreateOrUpdateComment {
54 actor: ObjectId::new(actor.actor_id()),
56 object: comment.into_apub(context).await?,
61 unparsed: Default::default(),
64 let activity = AnnouncableActivities::CreateOrUpdateComment(create_or_update);
65 send_activity_in_community(activity, &id, actor, &community, maa.inboxes, context).await
69 #[async_trait::async_trait(?Send)]
70 impl ActivityHandler for CreateOrUpdateComment {
71 type DataType = LemmyContext;
75 context: &Data<LemmyContext>,
76 request_counter: &mut i32,
77 ) -> Result<(), LemmyError> {
78 verify_is_public(&self.to, &self.cc)?;
79 let post = self.object.get_parents(context, request_counter).await?.0;
80 let community = self.get_community(context, request_counter).await?;
82 verify_activity(&self.id, self.actor.inner(), &context.settings())?;
83 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
84 verify_domains_match(self.actor.inner(), self.object.id.inner())?;
85 check_community_deleted_or_removed(&community)?;
86 check_post_deleted_or_removed(&post)?;
88 ApubComment::verify(&self.object, self.actor.inner(), context, request_counter).await?;
94 context: &Data<LemmyContext>,
95 request_counter: &mut i32,
96 ) -> Result<(), LemmyError> {
97 let comment = ApubComment::from_apub(self.object, context, request_counter).await?;
98 let recipients = get_notif_recipients(&self.actor, &comment, context, request_counter).await?;
99 let notif_type = match self.kind {
100 CreateOrUpdateType::Create => UserOperationCrud::CreateComment,
101 CreateOrUpdateType::Update => UserOperationCrud::EditComment,
103 send_comment_ws_message(
104 comment.id, notif_type, None, None, None, recipients, context,
111 #[async_trait::async_trait(?Send)]
112 impl GetCommunity for CreateOrUpdateComment {
113 async fn get_community(
115 context: &LemmyContext,
116 request_counter: &mut i32,
117 ) -> Result<ApubCommunity, LemmyError> {
118 let post = self.object.get_parents(context, request_counter).await?.0;
119 let community = blocking(context.pool(), move |conn| {
120 Community::read(conn, post.community_id)