]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/fetcher/post_or_comment.rs
Use audience field to federate items in groups (fixes #2464) (#2584)
[lemmy.git] / crates / apub / src / fetcher / post_or_comment.rs
index dc425e21bf5668ffbe223289662c9235d5bf7737..d2d0b91f64e6fae2c0e58ab08619dfe1ac8033ea 100644 (file)
@@ -1,9 +1,16 @@
 use crate::{
-  objects::{comment::ApubComment, post::ApubPost},
-  protocol::objects::{note::Note, page::Page},
+  objects::{comment::ApubComment, community::ApubCommunity, post::ApubPost},
+  protocol::{
+    objects::{note::Note, page::Page},
+    InCommunity,
+  },
 };
 use activitypub_federation::traits::ApubObject;
 use chrono::NaiveDateTime;
+use lemmy_db_schema::{
+  source::{community::Community, post::Post},
+  traits::Crud,
+};
 use lemmy_utils::error::LemmyError;
 use lemmy_websocket::LemmyContext;
 use serde::Deserialize;
@@ -99,3 +106,18 @@ impl PostOrComment {
     .into()
   }
 }
+
+#[async_trait::async_trait(?Send)]
+impl InCommunity for PostOrComment {
+  async fn community(
+    &self,
+    context: &LemmyContext,
+    _: &mut i32,
+  ) -> Result<ApubCommunity, LemmyError> {
+    let cid = match self {
+      PostOrComment::Post(p) => p.community_id,
+      PostOrComment::Comment(c) => Post::read(context.pool(), c.post_id).await?.community_id,
+    };
+    Ok(Community::read(context.pool(), cid).await?.into())
+  }
+}