Servers: Add description field.

API: Allow removal of description on channels and servers.
This commit is contained in:
Paul
2021-06-06 10:55:31 +01:00
parent 380369e1c4
commit 0af4fa4be9
5 changed files with 19 additions and 1 deletions

View File

@@ -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")]

View File

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

View File

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

View File

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

View File

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