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::{link::LinkExt, 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
70 .map(|t| ObjectId::new(t.clone()))
72 let mut inboxes = vec![];
73 for t in tagged_users {
74 let person = t.dereference(context, request_counter).await?;
75 inboxes.push(person.shared_inbox_or_inbox_url());
78 let activity = AnnouncableActivities::CreateOrUpdateComment(create_or_update);
79 send_activity_in_community(activity, &id, actor, &community, inboxes, context).await
83 #[async_trait::async_trait(?Send)]
84 impl ActivityHandler for CreateOrUpdateComment {
85 type DataType = LemmyContext;
89 context: &Data<LemmyContext>,
90 request_counter: &mut i32,
91 ) -> Result<(), LemmyError> {
92 verify_is_public(&self.to, &self.cc)?;
93 let post = self.object.get_parents(context, request_counter).await?.0;
94 let community = self.get_community(context, request_counter).await?;
96 verify_activity(&self.id, self.actor.inner(), &context.settings())?;
97 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
98 verify_domains_match(self.actor.inner(), self.object.id.inner())?;
99 check_community_deleted_or_removed(&community)?;
100 check_post_deleted_or_removed(&post)?;
102 ApubComment::verify(&self.object, self.actor.inner(), context, request_counter).await?;
108 context: &Data<LemmyContext>,
109 request_counter: &mut i32,
110 ) -> Result<(), LemmyError> {
111 let comment = ApubComment::from_apub(self.object, context, request_counter).await?;
112 let recipients = get_notif_recipients(&self.actor, &comment, context, request_counter).await?;
113 let notif_type = match self.kind {
114 CreateOrUpdateType::Create => UserOperationCrud::CreateComment,
115 CreateOrUpdateType::Update => UserOperationCrud::EditComment,
117 send_comment_ws_message(
118 comment.id, notif_type, None, None, None, recipients, context,
125 #[async_trait::async_trait(?Send)]
126 impl GetCommunity for CreateOrUpdateComment {
127 async fn get_community(
129 context: &LemmyContext,
130 request_counter: &mut i32,
131 ) -> Result<ApubCommunity, LemmyError> {
132 let post = self.object.get_parents(context, request_counter).await?.0;
133 let community = blocking(context.pool(), move |conn| {
134 Community::read(conn, post.community_id)