-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;
#[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)
+ }
+ }
}