add nsfw to servers and channels

This commit is contained in:
Zomatree
2021-08-16 00:18:14 +01:00
parent 28c4312880
commit d4f7c4a77d
7 changed files with 54 additions and 7 deletions

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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);

View File

@@ -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?;

View File

@@ -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()
}
};

View File

@@ -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?;

View File

@@ -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);