From: Felix Ableitner Date: Fri, 5 Feb 2021 13:23:57 +0000 (+0100) Subject: Make apub extension fields optional (ref #1220) X-Git-Url: http://these/git/%7B%60%24%7BarchiveTodayUrl%7D/static/%24%7BappleTouchIcon%7D?a=commitdiff_plain;h=105dfc93f1fa63f7ea1bdfff1fad9eb799aba064;p=lemmy.git Make apub extension fields optional (ref #1220) --- diff --git a/crates/apub/src/extensions/group_extensions.rs b/crates/apub/src/extensions/group_extensions.rs index b9790b23..891cb26c 100644 --- a/crates/apub/src/extensions/group_extensions.rs +++ b/crates/apub/src/extensions/group_extensions.rs @@ -11,8 +11,8 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Default, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct GroupExtension { - pub category: GroupCategory, - pub sensitive: bool, + pub category: Option, + pub sensitive: Option, } #[derive(Clone, Debug, Default, Deserialize, Serialize)] @@ -35,8 +35,8 @@ impl GroupExtension { name: category.name, }; Ok(GroupExtension { - category: group_category, - sensitive, + category: Some(group_category), + sensitive: Some(sensitive), }) } } diff --git a/crates/apub/src/extensions/page_extension.rs b/crates/apub/src/extensions/page_extension.rs index 8ed12a0c..752fa2b4 100644 --- a/crates/apub/src/extensions/page_extension.rs +++ b/crates/apub/src/extensions/page_extension.rs @@ -8,9 +8,9 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Default, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct PageExtension { - pub comments_enabled: bool, - pub sensitive: bool, - pub stickied: bool, + pub comments_enabled: Option, + pub sensitive: Option, + pub stickied: Option, } impl UnparsedExtension for PageExtension diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index af947e04..c6189f9c 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -207,13 +207,19 @@ impl FromApubToForm for CommunityForm { name, title, description, - category_id: group.ext_one.category.identifier.parse::()?, + category_id: group + .ext_one + .category + .clone() + .map(|c| c.identifier.parse::().ok()) + .flatten() + .unwrap_or(1), creator_id: creator.id, removed: None, published: group.inner.published().map(|u| u.to_owned().naive_local()), updated: group.inner.updated().map(|u| u.to_owned().naive_local()), deleted: None, - nsfw: group.ext_one.sensitive, + nsfw: group.ext_one.sensitive.unwrap_or(false), actor_id: Some(check_object_domain(group, expected_domain)?), local: false, private_key: None, diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index 31f848a4..1420e145 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -85,9 +85,9 @@ impl ToApub for Post { } let ext = PageExtension { - comments_enabled: !self.locked, - sensitive: self.nsfw, - stickied: self.stickied, + comments_enabled: Some(!self.locked), + sensitive: Some(self.nsfw), + stickied: Some(self.stickied), }; Ok(Ext1::new(page, ext)) } @@ -198,7 +198,7 @@ impl FromApubToForm for PostForm { creator_id: creator.id, community_id: community.id, removed: None, - locked: Some(!ext.comments_enabled), + locked: ext.comments_enabled.map(|e| !e), published: page .inner .published() @@ -210,8 +210,8 @@ impl FromApubToForm for PostForm { .as_ref() .map(|u| u.to_owned().naive_local()), deleted: None, - nsfw: ext.sensitive, - stickied: Some(ext.stickied), + nsfw: ext.sensitive.unwrap_or(false), + stickied: ext.stickied.or(Some(false)), embed_title: iframely_title, embed_description: iframely_description, embed_html: iframely_html,