2021-10-28 21:17:59 +00:00
|
|
|
use crate::{
|
2022-06-02 14:33:41 +00:00
|
|
|
check_apub_id_valid_with_strictness,
|
2021-10-28 21:17:59 +00:00
|
|
|
collections::{
|
2023-02-18 14:50:28 +00:00
|
|
|
community_featured::ApubCommunityFeatured,
|
2023-10-17 14:34:38 +00:00
|
|
|
community_follower::ApubCommunityFollower,
|
2021-10-28 21:17:59 +00:00
|
|
|
community_moderators::ApubCommunityModerators,
|
|
|
|
community_outbox::ApubCommunityOutbox,
|
|
|
|
},
|
2023-07-05 15:08:02 +00:00
|
|
|
local_site_data_cached,
|
2022-05-10 17:08:13 +00:00
|
|
|
objects::{community::ApubCommunity, read_from_string_or_source_opt},
|
2022-10-06 18:27:58 +00:00
|
|
|
protocol::{
|
|
|
|
objects::{Endpoints, LanguageTag},
|
|
|
|
ImageObject,
|
|
|
|
Source,
|
|
|
|
},
|
2021-10-28 21:17:59 +00:00
|
|
|
};
|
2022-06-02 14:33:41 +00:00
|
|
|
use activitypub_federation::{
|
2023-03-21 15:03:05 +00:00
|
|
|
fetch::{collection_id::CollectionId, object_id::ObjectId},
|
|
|
|
kinds::actor::GroupType,
|
|
|
|
protocol::{
|
|
|
|
helpers::deserialize_skip_error,
|
|
|
|
public_key::PublicKey,
|
|
|
|
verification::verify_domains_match,
|
|
|
|
},
|
2022-06-02 14:33:41 +00:00
|
|
|
};
|
2023-08-24 15:27:00 +00:00
|
|
|
use chrono::{DateTime, Utc};
|
2023-10-11 14:48:19 +00:00
|
|
|
use lemmy_api_common::{context::LemmyContext, utils::local_site_opt_to_slur_regex};
|
2021-10-28 21:17:59 +00:00
|
|
|
use lemmy_utils::{
|
2022-06-02 14:33:41 +00:00
|
|
|
error::LemmyError,
|
2023-02-16 04:05:14 +00:00
|
|
|
utils::slurs::{check_slurs, check_slurs_opt},
|
2021-10-28 21:17:59 +00:00
|
|
|
};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use serde_with::skip_serializing_none;
|
2023-02-05 05:38:08 +00:00
|
|
|
use std::fmt::Debug;
|
2021-10-28 21:17:59 +00:00
|
|
|
use url::Url;
|
|
|
|
|
|
|
|
#[skip_serializing_none]
|
2024-01-25 16:04:25 +00:00
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
|
2021-10-28 21:17:59 +00:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct Group {
|
|
|
|
#[serde(rename = "type")]
|
|
|
|
pub(crate) kind: GroupType,
|
2021-11-03 16:26:09 +00:00
|
|
|
pub(crate) id: ObjectId<ApubCommunity>,
|
2022-02-17 22:04:01 +00:00
|
|
|
/// username, set at account creation and usually fixed after that
|
2021-10-28 21:17:59 +00:00
|
|
|
pub(crate) preferred_username: String,
|
2022-02-17 22:04:01 +00:00
|
|
|
pub(crate) inbox: Url,
|
2023-10-17 14:34:38 +00:00
|
|
|
pub(crate) followers: CollectionId<ApubCommunityFollower>,
|
2022-02-17 22:04:01 +00:00
|
|
|
pub(crate) public_key: PublicKey,
|
|
|
|
|
2022-03-24 16:33:42 +00:00
|
|
|
/// title
|
|
|
|
pub(crate) name: Option<String>,
|
2021-10-28 21:17:59 +00:00
|
|
|
pub(crate) summary: Option<String>,
|
2022-06-02 14:33:41 +00:00
|
|
|
#[serde(deserialize_with = "deserialize_skip_error", default)]
|
2022-04-01 18:25:19 +00:00
|
|
|
pub(crate) source: Option<Source>,
|
2023-12-14 12:25:47 +00:00
|
|
|
#[serde(deserialize_with = "deserialize_skip_error", default)]
|
2021-10-28 21:17:59 +00:00
|
|
|
pub(crate) icon: Option<ImageObject>,
|
|
|
|
/// banner
|
|
|
|
pub(crate) image: Option<ImageObject>,
|
|
|
|
// lemmy extension
|
|
|
|
pub(crate) sensitive: Option<bool>,
|
2022-11-25 14:01:58 +00:00
|
|
|
#[serde(deserialize_with = "deserialize_skip_error", default)]
|
2023-03-21 15:03:05 +00:00
|
|
|
pub(crate) attributed_to: Option<CollectionId<ApubCommunityModerators>>,
|
2022-04-28 20:32:32 +00:00
|
|
|
// lemmy extension
|
|
|
|
pub(crate) posting_restricted_to_mods: Option<bool>,
|
2023-03-21 15:03:05 +00:00
|
|
|
pub(crate) outbox: CollectionId<ApubCommunityOutbox>,
|
2022-01-17 14:40:47 +00:00
|
|
|
pub(crate) endpoints: Option<Endpoints>,
|
2023-03-21 15:03:05 +00:00
|
|
|
pub(crate) featured: Option<CollectionId<ApubCommunityFeatured>>,
|
2022-10-06 18:27:58 +00:00
|
|
|
#[serde(default)]
|
|
|
|
pub(crate) language: Vec<LanguageTag>,
|
2023-08-24 15:27:00 +00:00
|
|
|
pub(crate) published: Option<DateTime<Utc>>,
|
|
|
|
pub(crate) updated: Option<DateTime<Utc>>,
|
2021-10-28 21:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Group {
|
2021-11-06 17:35:14 +00:00
|
|
|
pub(crate) async fn verify(
|
|
|
|
&self,
|
2021-10-28 21:17:59 +00:00
|
|
|
expected_domain: &Url,
|
2021-11-06 17:35:14 +00:00
|
|
|
context: &LemmyContext,
|
|
|
|
) -> Result<(), LemmyError> {
|
2023-07-05 15:08:02 +00:00
|
|
|
check_apub_id_valid_with_strictness(self.id.inner(), true, context).await?;
|
2021-11-06 12:37:55 +00:00
|
|
|
verify_domains_match(expected_domain, self.id.inner())?;
|
2021-10-28 21:17:59 +00:00
|
|
|
|
2023-07-11 13:09:59 +00:00
|
|
|
let local_site_data = local_site_data_cached(&mut context.pool()).await?;
|
2022-10-27 09:24:07 +00:00
|
|
|
let slur_regex = &local_site_opt_to_slur_regex(&local_site_data.local_site);
|
|
|
|
|
2021-11-06 17:35:14 +00:00
|
|
|
check_slurs(&self.preferred_username, slur_regex)?;
|
2022-03-24 16:33:42 +00:00
|
|
|
check_slurs_opt(&self.name, slur_regex)?;
|
2022-05-06 23:53:33 +00:00
|
|
|
let description = read_from_string_or_source_opt(&self.summary, &None, &self.source);
|
2021-10-28 21:17:59 +00:00
|
|
|
check_slurs_opt(&description, slur_regex)?;
|
2021-11-06 17:35:14 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
2021-10-28 21:17:59 +00:00
|
|
|
}
|