]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/activities/create_or_update/comment.rs
Use audience field to federate items in groups (fixes #2464) (#2584)
[lemmy.git] / crates / apub / src / activities / create_or_update / comment.rs
index 59e9d4b4e1ce14130530094d386378c948ff97cb..a4b60ad4d052a8b3163c8aa623826c6728906221 100644 (file)
@@ -1,7 +1,7 @@
 use crate::{
   activities::{
     check_community_deleted_or_removed,
-    community::{announce::GetCommunity, send_activity_in_community},
+    community::send_activity_in_community,
     create_or_update::get_comment_notif_recipients,
     generate_activity_id,
     verify_is_public,
@@ -11,7 +11,10 @@ use crate::{
   local_instance,
   mentions::MentionOrValue,
   objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson},
-  protocol::activities::{create_or_update::comment::CreateOrUpdateComment, CreateOrUpdateType},
+  protocol::{
+    activities::{create_or_update::note::CreateOrUpdateNote, CreateOrUpdateType},
+    InCommunity,
+  },
   ActorType,
 };
 use activitypub_federation::{
@@ -34,7 +37,7 @@ use lemmy_utils::error::LemmyError;
 use lemmy_websocket::{send::send_comment_ws_message, LemmyContext, UserOperationCrud};
 use url::Url;
 
-impl CreateOrUpdateComment {
+impl CreateOrUpdateNote {
   #[tracing::instrument(skip(comment, actor, kind, context))]
   pub async fn send(
     comment: ApubComment,
@@ -55,7 +58,7 @@ impl CreateOrUpdateComment {
     )?;
     let note = comment.into_apub(context).await?;
 
-    let create_or_update = CreateOrUpdateComment {
+    let create_or_update = CreateOrUpdateNote {
       actor: ObjectId::new(actor.actor_id()),
       to: vec![public()],
       cc: note.cc.clone(),
@@ -63,6 +66,7 @@ impl CreateOrUpdateComment {
       object: note,
       kind,
       id: id.clone(),
+      audience: Some(ObjectId::new(community.actor_id())),
     };
 
     let tagged_users: Vec<ObjectId<ApubPerson>> = create_or_update
@@ -92,7 +96,7 @@ impl CreateOrUpdateComment {
 }
 
 #[async_trait::async_trait(?Send)]
-impl ActivityHandler for CreateOrUpdateComment {
+impl ActivityHandler for CreateOrUpdateNote {
   type DataType = LemmyContext;
   type Error = LemmyError;
 
@@ -112,7 +116,7 @@ impl ActivityHandler for CreateOrUpdateComment {
   ) -> Result<(), LemmyError> {
     verify_is_public(&self.to, &self.cc)?;
     let post = self.object.get_parents(context, request_counter).await?.0;
-    let community = self.get_community(context, request_counter).await?;
+    let community = self.community(context, request_counter).await?;
 
     verify_person_in_community(&self.actor, &community, context, request_counter).await?;
     verify_domains_match(self.actor.inner(), self.object.id.inner())?;
@@ -160,17 +164,3 @@ impl ActivityHandler for CreateOrUpdateComment {
     Ok(())
   }
 }
-
-#[async_trait::async_trait(?Send)]
-impl GetCommunity for CreateOrUpdateComment {
-  #[tracing::instrument(skip_all)]
-  async fn get_community(
-    &self,
-    context: &LemmyContext,
-    request_counter: &mut i32,
-  ) -> Result<ApubCommunity, LemmyError> {
-    let post = self.object.get_parents(context, request_counter).await?.0;
-    let community = Community::read(context.pool(), post.community_id).await?;
-    Ok(community.into())
-  }
-}