3 check_community_deleted_or_removed,
4 comment::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_kinds::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 request_counter: &mut i32,
37 ) -> Result<(), LemmyError> {
38 // TODO: might be helpful to add a comment method to retrieve community directly
39 let post_id = comment.post_id;
40 let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
41 let community_id = post.community_id;
42 let community: ApubCommunity = blocking(context.pool(), move |conn| {
43 Community::read(conn, community_id)
48 let id = generate_activity_id(
50 &context.settings().get_protocol_and_hostname(),
52 let note = comment.into_apub(context).await?;
54 let create_or_update = CreateOrUpdateComment {
55 actor: ObjectId::new(actor.actor_id()),
58 tag: note.tag.clone(),
62 unparsed: Default::default(),
65 let tagged_users: Vec<ObjectId<ApubPerson>> = create_or_update
68 .map(|t| t.href.clone())
71 let mut inboxes = vec![];
72 for t in tagged_users {
73 let person = t.dereference(context, request_counter).await?;
74 inboxes.push(person.shared_inbox_or_inbox_url());
77 let activity = AnnouncableActivities::CreateOrUpdateComment(create_or_update);
78 send_activity_in_community(activity, &id, actor, &community, inboxes, context).await
82 #[async_trait::async_trait(?Send)]
83 impl ActivityHandler for CreateOrUpdateComment {
84 type DataType = LemmyContext;
88 context: &Data<LemmyContext>,
89 request_counter: &mut i32,
90 ) -> Result<(), LemmyError> {
91 verify_is_public(&self.to, &self.cc)?;
92 let post = self.object.get_parents(context, request_counter).await?.0;
93 let community = self.get_community(context, request_counter).await?;
95 verify_activity(&self.id, self.actor.inner(), &context.settings())?;
96 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
97 verify_domains_match(self.actor.inner(), self.object.id.inner())?;
98 check_community_deleted_or_removed(&community)?;
99 check_post_deleted_or_removed(&post)?;
101 ApubComment::verify(&self.object, self.actor.inner(), context, request_counter).await?;
107 context: &Data<LemmyContext>,
108 request_counter: &mut i32,
109 ) -> Result<(), LemmyError> {
110 let comment = ApubComment::from_apub(self.object, context, request_counter).await?;
111 let do_send_email = self.kind == CreateOrUpdateType::Create;
112 let recipients = get_notif_recipients(
120 let notif_type = match self.kind {
121 CreateOrUpdateType::Create => UserOperationCrud::CreateComment,
122 CreateOrUpdateType::Update => UserOperationCrud::EditComment,
124 send_comment_ws_message(
125 comment.id, notif_type, None, None, None, recipients, context,
132 #[async_trait::async_trait(?Send)]
133 impl GetCommunity for CreateOrUpdateComment {
134 async fn get_community(
136 context: &LemmyContext,
137 request_counter: &mut i32,
138 ) -> Result<ApubCommunity, LemmyError> {
139 let post = self.object.get_parents(context, request_counter).await?.0;
140 let community = blocking(context.pool(), move |conn| {
141 Community::read(conn, post.community_id)