3 community_moderators::ApubCommunityModerators,
4 community_outbox::ApubCommunityOutbox,
6 fetcher::object_id::ObjectId,
7 objects::get_summary_from_string_or_source,
8 protocol::{ImageObject, Source},
10 use activitystreams::{
11 actor::{kind::GroupType, Endpoints},
14 use chrono::{DateTime, FixedOffset};
15 use lemmy_apub_lib::{signatures::PublicKey, verify::verify_domains_match};
16 use lemmy_db_schema::{naive_now, source::community::CommunityForm};
18 settings::structs::Settings,
19 utils::{check_slurs, check_slurs_opt},
22 use serde::{Deserialize, Serialize};
23 use serde_with::skip_serializing_none;
26 #[skip_serializing_none]
27 #[derive(Clone, Debug, Deserialize, Serialize)]
28 #[serde(rename_all = "camelCase")]
30 #[serde(rename = "type")]
31 pub(crate) kind: GroupType,
33 /// username, set at account creation and can never be changed
34 pub(crate) preferred_username: String,
35 /// title (can be changed at any time)
36 pub(crate) name: String,
37 pub(crate) summary: Option<String>,
38 pub(crate) source: Option<Source>,
39 pub(crate) icon: Option<ImageObject>,
41 pub(crate) image: Option<ImageObject>,
43 pub(crate) sensitive: Option<bool>,
45 pub(crate) moderators: Option<ObjectId<ApubCommunityModerators>>,
46 pub(crate) inbox: Url,
47 pub(crate) outbox: ObjectId<ApubCommunityOutbox>,
48 pub(crate) followers: Url,
49 pub(crate) endpoints: Endpoints<Url>,
50 pub(crate) public_key: PublicKey,
51 pub(crate) published: Option<DateTime<FixedOffset>>,
52 pub(crate) updated: Option<DateTime<FixedOffset>>,
54 pub(crate) unparsed: Unparsed,
58 pub(crate) async fn from_apub_to_form(
60 expected_domain: &Url,
62 ) -> Result<CommunityForm, LemmyError> {
63 verify_domains_match(expected_domain, &group.id)?;
64 let name = group.preferred_username.clone();
65 let title = group.name.clone();
66 let description = get_summary_from_string_or_source(&group.summary, &group.source);
67 let shared_inbox = group.endpoints.shared_inbox.clone().map(|s| s.into());
69 let slur_regex = &settings.slur_regex();
70 check_slurs(&name, slur_regex)?;
71 check_slurs(&title, slur_regex)?;
72 check_slurs_opt(&description, slur_regex)?;
79 published: group.published.map(|u| u.naive_local()),
80 updated: group.updated.map(|u| u.naive_local()),
82 nsfw: Some(group.sensitive.unwrap_or(false)),
83 actor_id: Some(group.id.clone().into()),
86 public_key: Some(group.public_key.public_key_pem.clone()),
87 last_refreshed_at: Some(naive_now()),
88 icon: Some(group.icon.clone().map(|i| i.url.into())),
89 banner: Some(group.image.clone().map(|i| i.url.into())),
90 followers_url: Some(group.followers.clone().into()),
91 inbox_url: Some(group.inbox.clone().into()),
92 shared_inbox_url: Some(shared_inbox),