mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-14 05:26:59 +00:00
feat: add nsfw flag to emotes
This commit is contained in:
@@ -14,7 +14,11 @@ pub struct DataCreateEmoji {
|
||||
/// Server name
|
||||
#[validate(length(min = 1, max = 32), regex = "RE_EMOJI")]
|
||||
name: String,
|
||||
/// Parent information
|
||||
parent: EmojiParent,
|
||||
/// Whether the emoji is mature
|
||||
#[serde(default)]
|
||||
nsfw: bool,
|
||||
}
|
||||
|
||||
/// # Create New Emoji
|
||||
@@ -55,6 +59,7 @@ pub async fn create_emoji(
|
||||
return Err(Error::TooManyEmoji);
|
||||
}
|
||||
}
|
||||
EmojiParent::Detached => return Err(Error::InvalidOperation),
|
||||
};
|
||||
|
||||
// Find the relevant attachment
|
||||
@@ -67,6 +72,7 @@ pub async fn create_emoji(
|
||||
creator_id: user.id,
|
||||
name: data.name,
|
||||
animated: "image/gif" == &attachment.content_type,
|
||||
nsfw: data.nsfw,
|
||||
};
|
||||
|
||||
// Save emoji
|
||||
|
||||
@@ -111,6 +111,7 @@ impl State {
|
||||
|
||||
// Fetch all memberships with their corresponding servers.
|
||||
let members: Vec<Member> = db.fetch_all_memberships(&user.id).await?;
|
||||
|
||||
let server_ids: Vec<String> = members.iter().map(|x| x.id.server.clone()).collect();
|
||||
let servers = db.fetch_servers(&server_ids).await?;
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ impl AbstractEmoji for DummyDb {
|
||||
parent: EmojiParent::Server { id: id.into() },
|
||||
creator_id: id.into(),
|
||||
animated: false,
|
||||
nsfw: false,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Utility function to check if a boolean value is false
|
||||
pub fn if_false(t: &bool) -> bool {
|
||||
!t
|
||||
}
|
||||
|
||||
/// Information about what owns this emoji
|
||||
#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone)]
|
||||
#[serde(tag = "type")]
|
||||
@@ -21,5 +26,9 @@ pub struct Emoji {
|
||||
/// Emoji name
|
||||
pub name: String,
|
||||
/// Whether the emoji is animated
|
||||
#[serde(skip_serializing_if = "if_false", default)]
|
||||
pub animated: bool,
|
||||
/// Whether the emoji is marked as nsfw
|
||||
#[serde(skip_serializing_if = "if_false", default)]
|
||||
pub nsfw: bool,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user