forked from jmug/stoatchat
add nsfw to servers and channels
This commit is contained in:
@@ -57,7 +57,10 @@ pub enum Channel {
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
permissions: Option<i32>,
|
||||
},
|
||||
|
||||
#[serde(skip_serializing_if = "is_false", default)]
|
||||
nsfw: bool
|
||||
},
|
||||
TextChannel {
|
||||
#[serde(rename = "_id")]
|
||||
id: String,
|
||||
@@ -77,7 +80,10 @@ pub enum Channel {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
default_permissions: Option<i32>,
|
||||
#[serde(default = "HashMap::new", skip_serializing_if = "HashMap::is_empty")]
|
||||
role_permissions: HashMap<String, i32>
|
||||
role_permissions: HashMap<String, i32>,
|
||||
|
||||
#[serde(skip_serializing_if = "is_false", default)]
|
||||
nsfw: bool
|
||||
},
|
||||
VoiceChannel {
|
||||
#[serde(rename = "_id")]
|
||||
@@ -95,7 +101,11 @@ pub enum Channel {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
default_permissions: Option<i32>,
|
||||
#[serde(default = "HashMap::new", skip_serializing_if = "HashMap::is_empty")]
|
||||
role_permissions: HashMap<String, i32>
|
||||
role_permissions: HashMap<String, i32>,
|
||||
|
||||
#[serde(skip_serializing_if = "is_false", default)]
|
||||
nsfw: bool
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
@@ -395,3 +405,8 @@ impl Channel {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn is_false(value: &bool) -> bool {
|
||||
!value
|
||||
}
|
||||
@@ -107,6 +107,9 @@ pub struct Server {
|
||||
pub icon: Option<File>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub banner: Option<File>,
|
||||
|
||||
#[serde(skip_serializing_if = "is_false", default)]
|
||||
pub nsfw: bool
|
||||
}
|
||||
|
||||
impl Server {
|
||||
@@ -436,3 +439,7 @@ impl Server {
|
||||
})?)
|
||||
}
|
||||
}
|
||||
|
||||
fn is_false(value: &bool) -> bool {
|
||||
!value
|
||||
}
|
||||
@@ -18,6 +18,8 @@ pub struct Data {
|
||||
#[validate(length(min = 1, max = 128))]
|
||||
icon: Option<String>,
|
||||
remove: Option<RemoveChannelField>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
nsfw: Option<bool>
|
||||
}
|
||||
|
||||
#[patch("/<target>", data = "<data>")]
|
||||
@@ -86,6 +88,10 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<()> {
|
||||
remove_icon = true;
|
||||
}
|
||||
|
||||
if let Some(nsfw) = &data.nsfw {
|
||||
set.insert("nsfw", nsfw);
|
||||
}
|
||||
|
||||
let mut operations = doc! {};
|
||||
if set.len() > 0 {
|
||||
operations.insert("$set", &set);
|
||||
|
||||
@@ -20,6 +20,8 @@ pub struct Data {
|
||||
#[validate(length(min = 1, max = 36))]
|
||||
nonce: String,
|
||||
users: Vec<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
nsfw: Option<bool>
|
||||
}
|
||||
|
||||
#[post("/create", data = "<info>")]
|
||||
@@ -77,7 +79,8 @@ pub async fn req(user: User, info: Json<Data>) -> Result<Value> {
|
||||
recipients: set.into_iter().collect::<Vec<String>>(),
|
||||
icon: None,
|
||||
last_message: None,
|
||||
permissions: None
|
||||
permissions: None,
|
||||
nsfw: info.nsfw.unwrap_or_default()
|
||||
};
|
||||
|
||||
channel.clone().publish().await?;
|
||||
|
||||
@@ -32,6 +32,8 @@ pub struct Data {
|
||||
// Maximum length of 36 allows both ULIDs and UUIDs.
|
||||
#[validate(length(min = 1, max = 36))]
|
||||
nonce: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
nsfw: Option<bool>,
|
||||
}
|
||||
|
||||
#[post("/<target>/channels", data = "<info>")]
|
||||
@@ -80,7 +82,9 @@ pub async fn req(user: User, target: Ref, info: Json<Data>) -> Result<Value> {
|
||||
last_message: None,
|
||||
|
||||
default_permissions: None,
|
||||
role_permissions: HashMap::new()
|
||||
role_permissions: HashMap::new(),
|
||||
|
||||
nsfw: info.nsfw.unwrap_or_default(),
|
||||
},
|
||||
ChannelType::Voice => Channel::VoiceChannel {
|
||||
id: id.clone(),
|
||||
@@ -92,7 +96,9 @@ pub async fn req(user: User, target: Ref, info: Json<Data>) -> Result<Value> {
|
||||
icon: None,
|
||||
|
||||
default_permissions: None,
|
||||
role_permissions: HashMap::new()
|
||||
role_permissions: HashMap::new(),
|
||||
|
||||
nsfw: info.nsfw.unwrap_or_default()
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ pub struct Data {
|
||||
// Maximum length of 36 allows both ULIDs and UUIDs.
|
||||
#[validate(length(min = 1, max = 36))]
|
||||
nonce: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
nsfw: Option<bool>
|
||||
}
|
||||
|
||||
#[post("/create", data = "<info>")]
|
||||
@@ -75,6 +77,7 @@ pub async fn req(user: User, info: Json<Data>) -> Result<Value> {
|
||||
|
||||
icon: None,
|
||||
banner: None,
|
||||
nsfw: info.nsfw.unwrap_or_default()
|
||||
};
|
||||
|
||||
Channel::TextChannel {
|
||||
@@ -88,7 +91,8 @@ pub async fn req(user: User, info: Json<Data>) -> Result<Value> {
|
||||
last_message: None,
|
||||
|
||||
default_permissions: None,
|
||||
role_permissions: HashMap::new()
|
||||
role_permissions: HashMap::new(),
|
||||
nsfw: false
|
||||
}
|
||||
.publish()
|
||||
.await?;
|
||||
|
||||
@@ -18,6 +18,8 @@ pub struct Data {
|
||||
categories: Option<Vec<Category>>,
|
||||
system_messages: Option<SystemMessageChannels>,
|
||||
remove: Option<RemoveServerField>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
nsfw: Option<bool>
|
||||
}
|
||||
|
||||
#[patch("/<target>", data = "<data>")]
|
||||
@@ -105,6 +107,10 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<()> {
|
||||
set.insert("system_messages", to_bson(&system_messages).map_err(|_| Error::DatabaseError { operation: "to_document", with: "system_messages" })?);
|
||||
}
|
||||
|
||||
if let Some(nsfw) = &data.nsfw {
|
||||
set.insert("nsfw", nsfw);
|
||||
}
|
||||
|
||||
let mut operations = doc! {};
|
||||
if set.len() > 0 {
|
||||
operations.insert("$set", &set);
|
||||
|
||||
Reference in New Issue
Block a user