Skip to content

Commit

Permalink
Make apub extension fields optional (ref #1220)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Feb 5, 2021
1 parent f45f2ec commit 105dfc9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
8 changes: 4 additions & 4 deletions crates/apub/src/extensions/group_extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -35,8 +35,8 @@ impl GroupExtension {
name: category.name,
};
Ok(GroupExtension {
category: group_category,
sensitive,
category: Some(group_category),
sensitive: Some(sensitive),
})
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/apub/src/extensions/page_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions crates/apub/src/objects/community.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions crates/apub/src/objects/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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()
Expand All @@ -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,
Expand Down

0 comments on commit 105dfc9

Please sign in to comment.