2 activities::verify_community_matches,
4 objects::{community::ApubCommunity, person::ApubPerson},
5 protocol::{objects::group::Group, InCommunity},
7 use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
8 use activitystreams_kinds::activity::UpdateType;
9 use lemmy_utils::error::LemmyError;
10 use lemmy_websocket::LemmyContext;
11 use serde::{Deserialize, Serialize};
14 /// This activity is received from a remote community mod, and updates the description or other
15 /// fields of a local community.
16 #[derive(Clone, Debug, Deserialize, Serialize)]
17 #[serde(rename_all = "camelCase")]
18 pub struct UpdateCommunity {
19 pub(crate) actor: ObjectId<ApubPerson>,
20 #[serde(deserialize_with = "deserialize_one_or_many")]
21 pub(crate) to: Vec<Url>,
22 // TODO: would be nice to use a separate struct here, which only contains the fields updated here
23 pub(crate) object: Box<Group>,
24 #[serde(deserialize_with = "deserialize_one_or_many")]
25 pub(crate) cc: Vec<Url>,
26 #[serde(rename = "type")]
27 pub(crate) kind: UpdateType,
29 pub(crate) audience: Option<ObjectId<ApubCommunity>>,
32 #[async_trait::async_trait(?Send)]
33 impl InCommunity for UpdateCommunity {
36 context: &LemmyContext,
37 request_counter: &mut i32,
38 ) -> Result<ApubCommunity, LemmyError> {
39 let object_community: ApubCommunity = ObjectId::new(self.object.id.clone())
40 .dereference(context, local_instance(context).await, request_counter)
42 if let Some(audience) = &self.audience {
43 let audience = audience
44 .dereference(context, local_instance(context).await, request_counter)
46 verify_community_matches(&audience, object_community.id)?;