mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-14 21:47:02 +00:00
Servers: Add description field.
API: Allow removal of description on channels and servers.
This commit is contained in:
@@ -42,6 +42,8 @@ pub struct Server {
|
||||
pub owner: String,
|
||||
|
||||
pub name: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub description: Option<String>,
|
||||
pub channels: Vec<String>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
||||
@@ -40,12 +40,14 @@ pub enum RemoveUserField {
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub enum RemoveChannelField {
|
||||
Icon,
|
||||
Description,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub enum RemoveServerField {
|
||||
Icon,
|
||||
Banner,
|
||||
Description,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
|
||||
@@ -57,6 +57,9 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<()> {
|
||||
unset.insert("icon", 1);
|
||||
remove_icon = true;
|
||||
}
|
||||
RemoveChannelField::Description => {
|
||||
unset.insert("description", 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ use validator::Validate;
|
||||
pub struct Data {
|
||||
#[validate(length(min = 1, max = 32))]
|
||||
name: String,
|
||||
#[validate(length(min = 0, max = 1024))]
|
||||
description: Option<String>,
|
||||
// Maximum length of 36 allows both ULIDs and UUIDs.
|
||||
#[validate(length(min = 1, max = 36))]
|
||||
nonce: String,
|
||||
@@ -48,6 +50,7 @@ pub async fn req(user: User, info: Json<Data>) -> Result<JsonValue> {
|
||||
owner: user.id.clone(),
|
||||
|
||||
name: info.name,
|
||||
description: info.description,
|
||||
channels: vec![cid.clone()],
|
||||
|
||||
icon: None,
|
||||
|
||||
@@ -10,8 +10,9 @@ use validator::Validate;
|
||||
#[derive(Validate, Serialize, Deserialize)]
|
||||
pub struct Data {
|
||||
#[validate(length(min = 1, max = 32))]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
name: Option<String>,
|
||||
#[validate(length(min = 0, max = 1024))]
|
||||
description: Option<String>,
|
||||
icon: Option<String>,
|
||||
banner: Option<String>,
|
||||
remove: Option<RemoveServerField>,
|
||||
@@ -53,6 +54,9 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<()> {
|
||||
unset.insert("banner", 1);
|
||||
remove_banner = true;
|
||||
}
|
||||
RemoveServerField::Description => {
|
||||
unset.insert("description", 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +64,10 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<()> {
|
||||
set.insert("name", name);
|
||||
}
|
||||
|
||||
if let Some(description) = &data.description {
|
||||
set.insert("description", description);
|
||||
}
|
||||
|
||||
if let Some(attachment_id) = &data.icon {
|
||||
let attachment = File::find_and_use(&attachment_id, "icons", "object", &target.id).await?;
|
||||
set.insert(
|
||||
|
||||
Reference in New Issue
Block a user