]> Untitled Git - lemmy.git/blob - crates/apub/src/protocol/activities/community/update.rs
add enable_federated_downvotes site option
[lemmy.git] / crates / apub / src / protocol / activities / community / update.rs
1 use crate::{
2   activities::verify_community_matches,
3   objects::{community::ApubCommunity, person::ApubPerson},
4   protocol::{objects::group::Group, InCommunity},
5 };
6 use activitypub_federation::{
7   config::Data,
8   fetch::object_id::ObjectId,
9   kinds::activity::UpdateType,
10   protocol::helpers::deserialize_one_or_many,
11 };
12 use lemmy_api_common::context::LemmyContext;
13 use lemmy_utils::error::LemmyError;
14 use serde::{Deserialize, Serialize};
15 use url::Url;
16
17 /// This activity is received from a remote community mod, and updates the description or other
18 /// fields of a local community.
19 #[derive(Clone, Debug, Deserialize, Serialize)]
20 #[serde(rename_all = "camelCase")]
21 pub struct UpdateCommunity {
22   pub(crate) actor: ObjectId<ApubPerson>,
23   #[serde(deserialize_with = "deserialize_one_or_many")]
24   pub(crate) to: Vec<Url>,
25   // TODO: would be nice to use a separate struct here, which only contains the fields updated here
26   pub(crate) object: Box<Group>,
27   #[serde(deserialize_with = "deserialize_one_or_many")]
28   pub(crate) cc: Vec<Url>,
29   #[serde(rename = "type")]
30   pub(crate) kind: UpdateType,
31   pub(crate) id: Url,
32   pub(crate) audience: Option<ObjectId<ApubCommunity>>,
33 }
34
35 #[async_trait::async_trait]
36 impl InCommunity for UpdateCommunity {
37   async fn community(&self, context: &Data<LemmyContext>) -> Result<ApubCommunity, LemmyError> {
38     let community: ApubCommunity = self.object.id.clone().dereference(context).await?;
39     if let Some(audience) = &self.audience {
40       verify_community_matches(audience, community.actor_id.clone())?;
41     }
42     Ok(community)
43   }
44 }