#[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)]
name: category.name,
};
Ok(GroupExtension {
- category: group_category,
- sensitive,
+ category: Some(group_category),
+ sensitive: Some(sensitive),
})
}
}
#[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
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,
}
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))
}
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()
.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,