]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/protocol/activities/community/update.rs
Use audience field to federate items in groups (fixes #2464) (#2584)
[lemmy.git] / crates / apub / src / protocol / activities / community / update.rs
index f6ef99c0938e23b23ac3b2bf242823f137b79c4d..f534f236945f0747e504d72cf86319a3eeaca8af 100644 (file)
@@ -1,6 +1,13 @@
-use crate::{objects::person::ApubPerson, protocol::objects::group::Group};
+use crate::{
+  activities::verify_community_matches,
+  local_instance,
+  objects::{community::ApubCommunity, person::ApubPerson},
+  protocol::{objects::group::Group, InCommunity},
+};
 use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
 use activitystreams_kinds::activity::UpdateType;
+use lemmy_utils::error::LemmyError;
+use lemmy_websocket::LemmyContext;
 use serde::{Deserialize, Serialize};
 use url::Url;
 
@@ -19,4 +26,27 @@ pub struct UpdateCommunity {
   #[serde(rename = "type")]
   pub(crate) kind: UpdateType,
   pub(crate) id: Url,
+  pub(crate) audience: Option<ObjectId<ApubCommunity>>,
+}
+
+#[async_trait::async_trait(?Send)]
+impl InCommunity for UpdateCommunity {
+  async fn community(
+    &self,
+    context: &LemmyContext,
+    request_counter: &mut i32,
+  ) -> Result<ApubCommunity, LemmyError> {
+    let object_community: ApubCommunity = ObjectId::new(self.object.id.clone())
+      .dereference(context, local_instance(context).await, request_counter)
+      .await?;
+    if let Some(audience) = &self.audience {
+      let audience = audience
+        .dereference(context, local_instance(context).await, request_counter)
+        .await?;
+      verify_community_matches(&audience, object_community.id)?;
+      Ok(audience)
+    } else {
+      Ok(object_community)
+    }
+  }
 }