Make apub extension fields optional (ref #1220)

This commit is contained in:
Felix Ableitner 2021-02-05 14:23:57 +01:00
parent f45f2ec202
commit 105dfc93f1
4 changed files with 21 additions and 15 deletions

View file

@ -11,8 +11,8 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default, Deserialize, Serialize)] #[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct GroupExtension { pub struct GroupExtension {
pub category: GroupCategory, pub category: Option<GroupCategory>,
pub sensitive: bool, pub sensitive: Option<bool>,
} }
#[derive(Clone, Debug, Default, Deserialize, Serialize)] #[derive(Clone, Debug, Default, Deserialize, Serialize)]
@ -35,8 +35,8 @@ impl GroupExtension {
name: category.name, name: category.name,
}; };
Ok(GroupExtension { Ok(GroupExtension {
category: group_category, category: Some(group_category),
sensitive, sensitive: Some(sensitive),
}) })
} }
} }

View file

@ -8,9 +8,9 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default, Deserialize, Serialize)] #[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct PageExtension { pub struct PageExtension {
pub comments_enabled: bool, pub comments_enabled: Option<bool>,
pub sensitive: bool, pub sensitive: Option<bool>,
pub stickied: bool, pub stickied: Option<bool>,
} }
impl<U> UnparsedExtension<U> for PageExtension impl<U> UnparsedExtension<U> for PageExtension

View file

@ -207,13 +207,19 @@ impl FromApubToForm<GroupExt> for CommunityForm {
name, name,
title, title,
description, 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, creator_id: creator.id,
removed: None, removed: None,
published: group.inner.published().map(|u| u.to_owned().naive_local()), published: group.inner.published().map(|u| u.to_owned().naive_local()),
updated: group.inner.updated().map(|u| u.to_owned().naive_local()), updated: group.inner.updated().map(|u| u.to_owned().naive_local()),
deleted: None, deleted: None,
nsfw: group.ext_one.sensitive, nsfw: group.ext_one.sensitive.unwrap_or(false),
actor_id: Some(check_object_domain(group, expected_domain)?), actor_id: Some(check_object_domain(group, expected_domain)?),
local: false, local: false,
private_key: None, private_key: None,

View file

@ -85,9 +85,9 @@ impl ToApub for Post {
} }
let ext = PageExtension { let ext = PageExtension {
comments_enabled: !self.locked, comments_enabled: Some(!self.locked),
sensitive: self.nsfw, sensitive: Some(self.nsfw),
stickied: self.stickied, stickied: Some(self.stickied),
}; };
Ok(Ext1::new(page, ext)) Ok(Ext1::new(page, ext))
} }
@ -198,7 +198,7 @@ impl FromApubToForm<PageExt> for PostForm {
creator_id: creator.id, creator_id: creator.id,
community_id: community.id, community_id: community.id,
removed: None, removed: None,
locked: Some(!ext.comments_enabled), locked: ext.comments_enabled.map(|e| !e),
published: page published: page
.inner .inner
.published() .published()
@ -210,8 +210,8 @@ impl FromApubToForm<PageExt> for PostForm {
.as_ref() .as_ref()
.map(|u| u.to_owned().naive_local()), .map(|u| u.to_owned().naive_local()),
deleted: None, deleted: None,
nsfw: ext.sensitive, nsfw: ext.sensitive.unwrap_or(false),
stickied: Some(ext.stickied), stickied: ext.stickied.or(Some(false)),
embed_title: iframely_title, embed_title: iframely_title,
embed_description: iframely_description, embed_description: iframely_description,
embed_html: iframely_html, embed_html: iframely_html,