Skip to main content

mutiny_rs/model/
user.rs

1use crate::model::file::File;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Serialize, Deserialize, Clone)]
5pub struct User {
6    #[serde(rename = "_id")]
7    pub id: String,
8    pub online: bool,
9    pub discriminator: String,
10    pub relationship: RelationshipStatus,
11    #[serde(skip_serializing_if = "Vec::is_empty", default)]
12    pub relations: Vec<Relationship>,
13    pub username: String,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub avatar: Option<File>,
16    #[serde(skip_serializing_if = "crate::model::if_zero_u32", default)]
17    pub badges: u32,
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub bot: Option<BotInformation>,
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub display_name: Option<String>,
22    #[serde(skip_serializing_if = "crate::model::if_zero_u32", default)]
23    pub flags: u32,
24    #[serde(skip_serializing_if = "crate::model::if_false", default)]
25    pub privileged: bool,
26    pub status: Option<UserStatus>,
27}
28#[derive(Debug, Serialize, Deserialize, Clone)]
29pub struct BotInformation {
30    #[serde(rename = "owner")]
31    pub owner_id: String,
32}
33#[derive(Debug, Serialize, Deserialize, Clone)]
34pub struct UserStatus {
35    pub text: Option<String>,
36    pub presence: Option<Presence>,
37}
38
39#[derive(Debug, Serialize, Deserialize, Clone)]
40pub enum Presence {
41    Online,
42    Idle,
43    Focus,
44    Busy,
45    Invisible,
46}
47
48/// User's relationship with another user (or themselves)
49#[derive(Debug, Serialize, Deserialize, Default, PartialEq, Clone)]
50pub enum RelationshipStatus {
51    /// No relationship with other user
52    #[default]
53    None,
54    /// Other user is us
55    User,
56    /// Friends with the other user
57    Friend,
58    /// Pending friend request to user
59    Outgoing,
60    /// Incoming friend request from user
61    Incoming,
62    /// Blocked this user
63    Blocked,
64    /// Blocked by this user
65    BlockedOther,
66}
67
68#[derive(Debug, Serialize, Deserialize, Clone)]
69/// Relationship entry indicating current status with other user
70pub struct Relationship {
71    /// Other user's Id
72    pub user_id: String,
73    /// Relationship status with them
74    pub status: RelationshipStatus,
75}
76#[derive(Debug, Serialize)]
77/// New user profile data
78pub struct DataUserProfile {
79    /// Text to set as user profile description
80    pub content: Option<String>,
81    /// Attachment ID for background
82    pub background: Option<String>,
83}
84#[derive(Debug, Serialize)]
85/// Optional fields on user object
86pub enum FieldsUser {
87    Avatar,
88    StatusText,
89    StatusPresence,
90    ProfileContent,
91    ProfileBackground,
92    DisplayName,
93
94    /// Internal field, ignore this.
95    Internal,
96}
97#[derive(Default, Serialize)]
98pub struct DataEditUser {
99    /// New display name
100    pub display_name: Option<String>,
101    /// Attachment Id for avatar
102    pub avatar: Option<String>,
103    /// New user status
104    pub status: Option<UserStatus>,
105    /// New user profile data
106    ///
107    /// This is applied as a partial.
108    pub profile: Option<DataUserProfile>,
109
110    /// Bitfield of user badges
111    pub badges: Option<i32>,
112    /// Enum of user flags
113    pub flags: Option<i32>,
114
115    /// Fields to remove from user object
116    pub remove: Option<Vec<FieldsUser>>,
117}
118impl DataEditUser {
119    pub fn new() -> Self {
120        Self::default()
121    }
122}
123impl User {
124    /// Turns the user object into a mentionable string
125    pub fn to_string(&self) -> String {
126        format!("<@{}>", self.id)
127    }
128}