parent
15e24b9a61
commit
df32b9d65e
43 changed files with 708 additions and 234 deletions
|
@ -47,6 +47,7 @@ impl Default for ThemePreference {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[derive(Default)]
|
||||
pub struct UserSettings {
|
||||
#[serde(default)]
|
||||
pub policy_consent: bool,
|
||||
|
@ -72,23 +73,6 @@ pub struct UserSettings {
|
|||
pub disable_other_themes: bool,
|
||||
}
|
||||
|
||||
impl Default for UserSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
policy_consent: false,
|
||||
display_name: String::new(),
|
||||
biography: String::new(),
|
||||
private_profile: false,
|
||||
private_communities: false,
|
||||
theme_preference: ThemePreference::default(),
|
||||
private_last_seen: false,
|
||||
theme_hue: String::new(),
|
||||
theme_sat: String::new(),
|
||||
theme_lit: String::new(),
|
||||
disable_other_themes: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for User {
|
||||
fn default() -> Self {
|
||||
|
@ -212,7 +196,7 @@ impl User {
|
|||
return None;
|
||||
}
|
||||
|
||||
match TOTP::new(
|
||||
TOTP::new(
|
||||
totp_rs::Algorithm::SHA1,
|
||||
6,
|
||||
1,
|
||||
|
@ -220,10 +204,7 @@ impl User {
|
|||
self.totp.as_bytes().to_owned(),
|
||||
Some(issuer.unwrap_or("tetratto!".to_string())),
|
||||
self.username.clone(),
|
||||
) {
|
||||
Ok(t) => Some(t),
|
||||
Err(_) => None,
|
||||
}
|
||||
).ok()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ impl Community {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
|
||||
pub struct CommunityContext {
|
||||
#[serde(default)]
|
||||
pub display_name: String,
|
||||
|
@ -80,16 +80,6 @@ pub struct CommunityContext {
|
|||
pub is_nsfw: bool,
|
||||
}
|
||||
|
||||
impl Default for CommunityContext {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
display_name: String::new(),
|
||||
description: String::new(),
|
||||
is_nsfw: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Who can read a [`Community`].
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub enum CommunityReadAccess {
|
||||
|
@ -166,7 +156,7 @@ impl CommunityMembership {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct PostContext {
|
||||
#[serde(default = "default_comments_enabled")]
|
||||
pub comments_enabled: bool,
|
||||
|
@ -178,25 +168,47 @@ pub struct PostContext {
|
|||
pub edited: usize,
|
||||
#[serde(default)]
|
||||
pub is_nsfw: bool,
|
||||
#[serde(default)]
|
||||
pub repost: Option<RepostContext>,
|
||||
#[serde(default = "default_reposts_enabled")]
|
||||
pub reposts_enabled: bool,
|
||||
}
|
||||
|
||||
fn default_comments_enabled() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_reposts_enabled() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
impl Default for PostContext {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
comments_enabled: default_comments_enabled(),
|
||||
reposts_enabled: true,
|
||||
is_pinned: false,
|
||||
is_profile_pinned: false,
|
||||
edited: 0,
|
||||
is_nsfw: false,
|
||||
repost: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct RepostContext {
|
||||
/// Should be `false` is `repost_of` is `Some`.
|
||||
///
|
||||
/// Declares the post to be a repost of another post.
|
||||
pub is_repost: bool,
|
||||
/// Should be `None` if `is_repost` is true.
|
||||
///
|
||||
/// Sets the ID of the other post to load.
|
||||
pub reposting: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct Post {
|
||||
pub id: usize,
|
||||
pub created: usize,
|
||||
|
@ -238,4 +250,24 @@ impl Post {
|
|||
comment_count: 0,
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new [`Post`] (as a repost of the given `post_id`).
|
||||
pub fn repost(content: String, community: usize, owner: usize, post_id: usize) -> Self {
|
||||
let mut post = Self::new(content, community, None, owner);
|
||||
|
||||
post.context.repost = Some(RepostContext {
|
||||
is_repost: false,
|
||||
reposting: Some(post_id),
|
||||
});
|
||||
|
||||
post
|
||||
}
|
||||
|
||||
/// Make the given post a reposted post.
|
||||
pub fn mark_as_repost(&mut self) {
|
||||
self.context.repost = Some(RepostContext {
|
||||
is_repost: true,
|
||||
reposting: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ impl Serialize for CommunityPermission {
|
|||
}
|
||||
|
||||
struct CommunityPermissionVisitor;
|
||||
impl<'de> Visitor<'de> for CommunityPermissionVisitor {
|
||||
impl Visitor<'_> for CommunityPermissionVisitor {
|
||||
type Value = CommunityPermission;
|
||||
|
||||
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
|
|
|
@ -54,14 +54,14 @@ impl ToString for Error {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Into<ApiReturn<T>> for Error
|
||||
impl<T> From<Error> for ApiReturn<T>
|
||||
where
|
||||
T: Default + Serialize,
|
||||
{
|
||||
fn into(self) -> ApiReturn<T> {
|
||||
fn from(val: Error) -> Self {
|
||||
ApiReturn {
|
||||
ok: false,
|
||||
message: self.to_string(),
|
||||
message: val.to_string(),
|
||||
payload: T::default(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ impl Serialize for FinePermission {
|
|||
}
|
||||
|
||||
struct FinePermissionVisitor;
|
||||
impl<'de> Visitor<'de> for FinePermissionVisitor {
|
||||
impl Visitor<'_> for FinePermissionVisitor {
|
||||
type Value = FinePermission;
|
||||
|
||||
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue