forked from jmug/stoatchat
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 owner: String,
|
||||||
|
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub description: Option<String>,
|
||||||
pub channels: Vec<String>,
|
pub channels: Vec<String>,
|
||||||
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
|||||||
@@ -40,12 +40,14 @@ pub enum RemoveUserField {
|
|||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub enum RemoveChannelField {
|
pub enum RemoveChannelField {
|
||||||
Icon,
|
Icon,
|
||||||
|
Description,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub enum RemoveServerField {
|
pub enum RemoveServerField {
|
||||||
Icon,
|
Icon,
|
||||||
Banner,
|
Banner,
|
||||||
|
Description,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<()> {
|
|||||||
unset.insert("icon", 1);
|
unset.insert("icon", 1);
|
||||||
remove_icon = true;
|
remove_icon = true;
|
||||||
}
|
}
|
||||||
|
RemoveChannelField::Description => {
|
||||||
|
unset.insert("description", 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ use validator::Validate;
|
|||||||
pub struct Data {
|
pub struct Data {
|
||||||
#[validate(length(min = 1, max = 32))]
|
#[validate(length(min = 1, max = 32))]
|
||||||
name: String,
|
name: String,
|
||||||
|
#[validate(length(min = 0, max = 1024))]
|
||||||
|
description: Option<String>,
|
||||||
// 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,
|
||||||
@@ -48,6 +50,7 @@ pub async fn req(user: User, info: Json<Data>) -> Result<JsonValue> {
|
|||||||
owner: user.id.clone(),
|
owner: user.id.clone(),
|
||||||
|
|
||||||
name: info.name,
|
name: info.name,
|
||||||
|
description: info.description,
|
||||||
channels: vec![cid.clone()],
|
channels: vec![cid.clone()],
|
||||||
|
|
||||||
icon: None,
|
icon: None,
|
||||||
|
|||||||
@@ -10,8 +10,9 @@ use validator::Validate;
|
|||||||
#[derive(Validate, Serialize, Deserialize)]
|
#[derive(Validate, Serialize, Deserialize)]
|
||||||
pub struct Data {
|
pub struct Data {
|
||||||
#[validate(length(min = 1, max = 32))]
|
#[validate(length(min = 1, max = 32))]
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
|
#[validate(length(min = 0, max = 1024))]
|
||||||
|
description: Option<String>,
|
||||||
icon: Option<String>,
|
icon: Option<String>,
|
||||||
banner: Option<String>,
|
banner: Option<String>,
|
||||||
remove: Option<RemoveServerField>,
|
remove: Option<RemoveServerField>,
|
||||||
@@ -53,6 +54,9 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<()> {
|
|||||||
unset.insert("banner", 1);
|
unset.insert("banner", 1);
|
||||||
remove_banner = true;
|
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);
|
set.insert("name", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(description) = &data.description {
|
||||||
|
set.insert("description", description);
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(attachment_id) = &data.icon {
|
if let Some(attachment_id) = &data.icon {
|
||||||
let attachment = File::find_and_use(&attachment_id, "icons", "object", &target.id).await?;
|
let attachment = File::find_and_use(&attachment_id, "icons", "object", &target.id).await?;
|
||||||
set.insert(
|
set.insert(
|
||||||
|
|||||||
Reference in New Issue
Block a user