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