]> Untitled Git - lemmy.git/commitdiff
Make apub extension fields optional (ref #1220)
authorFelix Ableitner <me@nutomic.com>
Fri, 5 Feb 2021 13:23:57 +0000 (14:23 +0100)
committerFelix Ableitner <me@nutomic.com>
Fri, 5 Feb 2021 13:23:57 +0000 (14:23 +0100)
crates/apub/src/extensions/group_extensions.rs
crates/apub/src/extensions/page_extension.rs
crates/apub/src/objects/community.rs
crates/apub/src/objects/post.rs

index b9790b2317b7eadf70a1d6b7eabcd9e08674288e..891cb26c73cf28a229d46a3b04de629abaa3253b 100644 (file)
@@ -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<GroupCategory>,
+  pub sensitive: Option<bool>,
 }
 
 #[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),
     })
   }
 }
index 8ed12a0c7f268f3a681f973e05ed0fc026f09e3c..752fa2b4b3f67a64d084d6f109abf512e7445ae5 100644 (file)
@@ -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<bool>,
+  pub sensitive: Option<bool>,
+  pub stickied: Option<bool>,
 }
 
 impl<U> UnparsedExtension<U> for PageExtension
index af947e04713bc75f8ba659621e5d2756ae825f0a..c6189f9c7572757ad1ad900279a74a7f21b6dc0c 100644 (file)
@@ -207,13 +207,19 @@ impl FromApubToForm<GroupExt> for CommunityForm {
       name,
       title,
       description,
-      category_id: group.ext_one.category.identifier.parse::<i32>()?,
+      category_id: group
+        .ext_one
+        .category
+        .clone()
+        .map(|c| c.identifier.parse::<i32>().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,
index 31f848a4dacac3e14a1cd1c62bf92bce7c7c86f7..1420e145d9063ade50b2f8a17d51645c48724f3a 100644 (file)
@@ -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<PageExt> 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<PageExt> 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,