mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-05-20 10:48:05 +00:00
514f2222e0
* convert naive time to utc time * compounding fixes * cargo fmt * fix the rest * fix down migration * fix migrations * fix after merge * clippy fix * ap-fed 0.5.0 --------- Co-authored-by: Nutomic <me@nutomic.com>
58 lines
1.9 KiB
Rust
58 lines
1.9 KiB
Rust
use crate::{
|
|
activities::{block::SiteOrCommunity, verify_community_matches},
|
|
objects::{community::ApubCommunity, person::ApubPerson},
|
|
protocol::InCommunity,
|
|
};
|
|
use activitypub_federation::{
|
|
config::Data,
|
|
fetch::object_id::ObjectId,
|
|
kinds::activity::BlockType,
|
|
protocol::helpers::deserialize_one_or_many,
|
|
};
|
|
use anyhow::anyhow;
|
|
use chrono::{DateTime, Utc};
|
|
use lemmy_api_common::context::LemmyContext;
|
|
use lemmy_utils::error::LemmyError;
|
|
use serde::{Deserialize, Serialize};
|
|
use serde_with::skip_serializing_none;
|
|
use url::Url;
|
|
|
|
#[skip_serializing_none]
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub struct BlockUser {
|
|
pub(crate) actor: ObjectId<ApubPerson>,
|
|
#[serde(deserialize_with = "deserialize_one_or_many")]
|
|
pub(crate) to: Vec<Url>,
|
|
pub(crate) object: ObjectId<ApubPerson>,
|
|
#[serde(deserialize_with = "deserialize_one_or_many")]
|
|
pub(crate) cc: Vec<Url>,
|
|
pub(crate) target: ObjectId<SiteOrCommunity>,
|
|
#[serde(rename = "type")]
|
|
pub(crate) kind: BlockType,
|
|
pub(crate) id: Url,
|
|
pub(crate) audience: Option<ObjectId<ApubCommunity>>,
|
|
|
|
/// Quick and dirty solution.
|
|
/// TODO: send a separate Delete activity instead
|
|
pub(crate) remove_data: Option<bool>,
|
|
/// block reason, written to mod log
|
|
pub(crate) summary: Option<String>,
|
|
pub(crate) expires: Option<DateTime<Utc>>,
|
|
}
|
|
|
|
#[async_trait::async_trait]
|
|
impl InCommunity for BlockUser {
|
|
async fn community(&self, context: &Data<LemmyContext>) -> Result<ApubCommunity, LemmyError> {
|
|
let target = self.target.dereference(context).await?;
|
|
let community = match target {
|
|
SiteOrCommunity::Community(c) => c,
|
|
SiteOrCommunity::Site(_) => return Err(anyhow!("activity is not in community").into()),
|
|
};
|
|
if let Some(audience) = &self.audience {
|
|
verify_community_matches(audience, community.actor_id.clone())?;
|
|
}
|
|
Ok(community)
|
|
}
|
|
}
|