2022-12-01 20:52:49 +00:00
|
|
|
use crate::{
|
2023-02-18 14:50:28 +00:00
|
|
|
activities::verify_community_matches,
|
2022-12-01 20:52:49 +00:00
|
|
|
objects::{community::ApubCommunity, person::ApubPerson},
|
|
|
|
protocol::InCommunity,
|
|
|
|
};
|
2023-03-21 15:03:05 +00:00
|
|
|
use activitypub_federation::{
|
|
|
|
config::Data,
|
|
|
|
fetch::object_id::ObjectId,
|
|
|
|
kinds::activity::RemoveType,
|
|
|
|
protocol::helpers::deserialize_one_or_many,
|
|
|
|
};
|
2022-11-28 14:29:33 +00:00
|
|
|
use lemmy_api_common::context::LemmyContext;
|
2023-02-18 14:50:28 +00:00
|
|
|
use lemmy_db_schema::source::community::Community;
|
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;
|
|
|
|
|
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")]
|
2023-02-18 14:50:28 +00:00
|
|
|
pub struct CollectionRemove {
|
2021-10-29 10:32:42 +00:00
|
|
|
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>,
|
2023-03-21 15:03:05 +00:00
|
|
|
pub(crate) object: Url,
|
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: RemoveType,
|
|
|
|
pub(crate) target: Url,
|
|
|
|
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]
|
2023-02-18 14:50:28 +00:00
|
|
|
impl InCommunity for CollectionRemove {
|
2023-03-21 15:03:05 +00:00
|
|
|
async fn community(&self, context: &Data<LemmyContext>) -> Result<ApubCommunity, LemmyError> {
|
2023-02-18 14:50:28 +00:00
|
|
|
let (community, _) =
|
2023-07-11 13:09:59 +00:00
|
|
|
Community::get_by_collection_url(&mut context.pool(), &self.clone().target.into()).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.into())
|
2022-12-01 20:52:49 +00:00
|
|
|
}
|
2021-10-29 10:32:42 +00:00
|
|
|
}
|