2021-10-29 10:32:42 +00:00
|
|
|
use crate::{
|
2022-12-01 20:52:49 +00:00
|
|
|
activities::verify_community_matches,
|
2021-11-05 00:24:10 +00:00
|
|
|
fetcher::post_or_comment::PostOrComment,
|
2021-10-29 10:32:42 +00:00
|
|
|
objects::{community::ApubCommunity, person::ApubPerson},
|
2022-12-01 20:52:49 +00:00
|
|
|
protocol::InCommunity,
|
2021-10-29 10:32:42 +00:00
|
|
|
};
|
2023-03-21 15:03:05 +00:00
|
|
|
use activitypub_federation::{
|
|
|
|
config::Data,
|
|
|
|
fetch::object_id::ObjectId,
|
|
|
|
kinds::activity::FlagType,
|
|
|
|
protocol::helpers::deserialize_one,
|
|
|
|
};
|
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;
|
|
|
|
|
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 Report {
|
|
|
|
pub(crate) actor: ObjectId<ApubPerson>,
|
2022-06-02 14:33:41 +00:00
|
|
|
#[serde(deserialize_with = "deserialize_one")]
|
2022-06-08 15:45:39 +00:00
|
|
|
pub(crate) to: [ObjectId<ApubCommunity>; 1],
|
2021-10-29 10:32:42 +00:00
|
|
|
pub(crate) object: ObjectId<PostOrComment>,
|
|
|
|
pub(crate) summary: String,
|
|
|
|
#[serde(rename = "type")]
|
|
|
|
pub(crate) kind: FlagType,
|
|
|
|
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 Report {
|
2023-03-21 15:03:05 +00:00
|
|
|
async fn community(&self, context: &Data<LemmyContext>) -> Result<ApubCommunity, LemmyError> {
|
|
|
|
let community = self.to[0].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
|
|
|
}
|