forked from jmug/stoatchat
feat: add discriminator and display name fields
This commit is contained in:
@@ -8,6 +8,8 @@ use rocket::State;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
|
||||
use crate::util::regex::RE_DISPLAY_NAME;
|
||||
|
||||
/// # Profile Data
|
||||
#[derive(Validate, Serialize, Deserialize, Debug, JsonSchema)]
|
||||
pub struct UserProfileData {
|
||||
@@ -24,6 +26,10 @@ pub struct UserProfileData {
|
||||
/// # User Data
|
||||
#[derive(Validate, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct DataEditUser {
|
||||
/// New display name
|
||||
#[serde(rename = "displayName")]
|
||||
#[validate(length(min = 2, max = 32), regex = "RE_DISPLAY_NAME")]
|
||||
display_name: Option<String>,
|
||||
/// Attachment Id for avatar
|
||||
#[validate(length(min = 1, max = 128))]
|
||||
avatar: Option<String>,
|
||||
@@ -84,7 +90,8 @@ pub async fn req(
|
||||
}
|
||||
|
||||
// Exit out early if nothing is changed
|
||||
if data.status.is_none()
|
||||
if data.display_name.is_none()
|
||||
&& data.status.is_none()
|
||||
&& data.profile.is_none()
|
||||
&& data.avatar.is_none()
|
||||
&& data.badges.is_none()
|
||||
|
||||
@@ -8,6 +8,7 @@ use serde::{Deserialize, Serialize};
|
||||
/// # User Lookup Information
|
||||
#[derive(Serialize, Deserialize, JsonSchema)]
|
||||
pub struct DataSendFriendRequest {
|
||||
/// Username and discriminator combo separated by #
|
||||
username: String,
|
||||
}
|
||||
|
||||
@@ -21,12 +22,16 @@ pub async fn req(
|
||||
user: User,
|
||||
data: Json<DataSendFriendRequest>,
|
||||
) -> Result<Json<User>> {
|
||||
let mut target = db.fetch_user_by_username(&data.username).await?;
|
||||
if let Some((username, discriminator)) = data.username.split_once('#') {
|
||||
let mut target = db.fetch_user_by_username(username, discriminator).await?;
|
||||
|
||||
if user.bot.is_some() || target.bot.is_some() {
|
||||
return Err(Error::IsBot);
|
||||
if user.bot.is_some() || target.bot.is_some() {
|
||||
return Err(Error::IsBot);
|
||||
}
|
||||
|
||||
user.add_friend(db, &mut target).await?;
|
||||
Ok(Json(target.with_auto_perspective(db, &user).await))
|
||||
} else {
|
||||
Err(Error::InvalidProperty)
|
||||
}
|
||||
|
||||
user.add_friend(db, &mut target).await?;
|
||||
Ok(Json(target.with_auto_perspective(db, &user).await))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user