feat: add modify user profile
This commit is contained in:
parent
20bdb3247a
commit
62d48d61fe
|
@ -11,7 +11,10 @@ use crate::{
|
||||||
errors::{ChorusError, ChorusResult},
|
errors::{ChorusError, ChorusResult},
|
||||||
instance::{ChorusUser, Instance},
|
instance::{ChorusUser, Instance},
|
||||||
ratelimiter::ChorusRequest,
|
ratelimiter::ChorusRequest,
|
||||||
types::{LimitType, PublicUser, Snowflake, User, UserModifySchema, UserProfile, UserSettings},
|
types::{
|
||||||
|
LimitType, PublicUser, Snowflake, User, UserModifyProfileSchema, UserModifySchema,
|
||||||
|
UserProfile, UserProfileMetadata, UserSettings,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl ChorusUser {
|
impl ChorusUser {
|
||||||
|
@ -133,6 +136,22 @@ impl ChorusUser {
|
||||||
pub async fn get_user_profile(&mut self, id: Snowflake) -> ChorusResult<UserProfile> {
|
pub async fn get_user_profile(&mut self, id: Snowflake) -> ChorusResult<UserProfile> {
|
||||||
User::get_profile(self, id).await
|
User::get_profile(self, id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Modifies the current user's profile.
|
||||||
|
///
|
||||||
|
/// Returns the updated [UserProfileMetadata].
|
||||||
|
///
|
||||||
|
/// # Notes
|
||||||
|
/// This function is a wrapper around [`User::modify_profile`].
|
||||||
|
///
|
||||||
|
/// # Reference
|
||||||
|
/// See <https://docs.discord.sex/resources/user#modify-user-profile>
|
||||||
|
pub async fn modify_profile(
|
||||||
|
&mut self,
|
||||||
|
schema: UserModifyProfileSchema,
|
||||||
|
) -> ChorusResult<UserProfileMetadata> {
|
||||||
|
User::modify_profile(self, schema).await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl User {
|
impl User {
|
||||||
|
@ -247,4 +266,28 @@ impl User {
|
||||||
.deserialize_response::<UserProfile>(user)
|
.deserialize_response::<UserProfile>(user)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Modifies the current user's profile.
|
||||||
|
///
|
||||||
|
/// Returns the updated [UserProfileMetadata].
|
||||||
|
///
|
||||||
|
/// # Reference
|
||||||
|
/// See <https://docs.discord.sex/resources/user#modify-user-profile>
|
||||||
|
pub async fn modify_profile(
|
||||||
|
user: &mut ChorusUser,
|
||||||
|
schema: UserModifyProfileSchema,
|
||||||
|
) -> ChorusResult<UserProfileMetadata> {
|
||||||
|
let url_api = user.belongs_to.read().unwrap().urls.api.clone();
|
||||||
|
let request: reqwest::RequestBuilder = Client::new()
|
||||||
|
.patch(format!("{}/users/@me/profile", url_api))
|
||||||
|
.header("Authorization", user.token())
|
||||||
|
.json(&schema);
|
||||||
|
let chorus_request = ChorusRequest {
|
||||||
|
request,
|
||||||
|
limit_type: LimitType::Global,
|
||||||
|
};
|
||||||
|
chorus_request
|
||||||
|
.deserialize_response::<UserProfileMetadata>(user)
|
||||||
|
.await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use std::collections::HashMap;
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::types::Snowflake;
|
use crate::types::{Snowflake, ThemeColors};
|
||||||
|
|
||||||
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq)]
|
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
|
@ -106,3 +106,44 @@ pub struct PrivateChannelCreateSchema {
|
||||||
pub access_tokens: Option<Vec<String>>,
|
pub access_tokens: Option<Vec<String>>,
|
||||||
pub nicks: Option<HashMap<Snowflake, String>>,
|
pub nicks: Option<HashMap<Snowflake, String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq)]
|
||||||
|
/// A schema used to modify the current user's profile.
|
||||||
|
///
|
||||||
|
/// Similar to [crate::types::UserProfileMetadata]
|
||||||
|
///
|
||||||
|
/// See <https://docs.discord.sex/resources/user#modify-user-profile>
|
||||||
|
pub struct UserModifyProfileSchema {
|
||||||
|
// Note: one of these causes a 500 if it is sent
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
/// The user's new pronouns (max 40 characters)
|
||||||
|
pub pronouns: Option<String>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
/// The user's new bio (max 190 characters)
|
||||||
|
pub bio: Option<String>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
// TODO: Add banner -- do we have an image data struct
|
||||||
|
/// The user's new accent color encoded as an i32 representation of a hex color code
|
||||||
|
pub accent_color: Option<i32>,
|
||||||
|
|
||||||
|
// Note: without the skip serializing this currently (2024/07/28) causes a 500!
|
||||||
|
//
|
||||||
|
// Which in turns locks the user's account, requiring phone number verification
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
/// The user's new [ThemeColors]
|
||||||
|
pub theme_colors: Option<ThemeColors>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
/// The user's new profile popup animation particle type
|
||||||
|
pub popout_animation_particle_type: Option<Snowflake>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
/// The user's new profile emoji id
|
||||||
|
pub emoji_id: Option<Snowflake>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
/// The user's new profile ffect id
|
||||||
|
pub profile_effect_id: Option<Snowflake>,
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue