2022-12-01 20:52:49 +00:00
|
|
|
use crate::{
|
|
|
|
activities::verify_community_matches,
|
|
|
|
objects::{community::ApubCommunity, person::ApubPerson},
|
|
|
|
protocol::{objects::group::Group, InCommunity},
|
|
|
|
};
|
2023-03-21 15:03:05 +00:00
|
|
|
use activitypub_federation::{
|
2023-09-23 01:39:03 +00:00
|
|
|
config::Data, fetch::object_id::ObjectId, kinds::activity::UpdateType,
|
2023-03-21 15:03:05 +00:00
|
|
|
protocol::helpers::deserialize_one_or_many,
|
|
|
|
};
|
2022-11-28 14:29:33 +00:00
|
|
|
use lemmy_api_common::context::LemmyContext;
|
2022-12-01 20:52:49 +00:00
|
|
|
use lemmy_utils::error::LemmyError;
|
2021-10-29 10:32:42 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use url::Url;
|
|
|
|
|
|
|
|
/// This activity is received from a remote community mod, and updates the description or other
|
|
|
|
/// fields of a local community.
|
2021-11-03 17:33:51 +00:00
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
2021-10-29 10:32:42 +00:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct UpdateCommunity {
|
|
|
|
pub(crate) actor: ObjectId<ApubPerson>,
|
2022-06-02 14:33:41 +00:00
|
|
|
#[serde(deserialize_with = "deserialize_one_or_many")]
|
2021-10-29 10:32:42 +00:00
|
|
|
pub(crate) to: Vec<Url>,
|
|
|
|
// TODO: would be nice to use a separate struct here, which only contains the fields updated here
|
2021-11-06 13:25:34 +00:00
|
|
|
pub(crate) object: Box<Group>,
|
2022-06-02 14:33:41 +00:00
|
|
|
#[serde(deserialize_with = "deserialize_one_or_many")]
|
2021-10-29 10:32:42 +00:00
|
|
|
pub(crate) cc: Vec<Url>,
|
|
|
|
#[serde(rename = "type")]
|
|
|
|
pub(crate) kind: UpdateType,
|
|
|
|
pub(crate) id: Url,
|
2022-12-01 20:52:49 +00:00
|
|
|
pub(crate) audience: Option<ObjectId<ApubCommunity>>,
|
|
|
|
}
|
|
|
|
|
2023-03-21 15:03:05 +00:00
|
|
|
#[async_trait::async_trait]
|
2022-12-01 20:52:49 +00:00
|
|
|
impl InCommunity for UpdateCommunity {
|
2023-03-21 15:03:05 +00:00
|
|
|
async fn community(&self, context: &Data<LemmyContext>) -> Result<ApubCommunity, LemmyError> {
|
|
|
|
let community: ApubCommunity = self.object.id.clone().dereference(context).await?;
|
2022-12-01 20:52:49 +00:00
|
|
|
if let Some(audience) = &self.audience {
|
2023-02-18 14:50:28 +00:00
|
|
|
verify_community_matches(audience, community.actor_id.clone())?;
|
2022-12-01 20:52:49 +00:00
|
|
|
}
|
2023-02-18 14:50:28 +00:00
|
|
|
Ok(community)
|
2022-12-01 20:52:49 +00:00
|
|
|
}
|
2021-10-29 10:32:42 +00:00
|
|
|
}
|