rive_models/
user.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5use crate::attachment::Attachment;
6
7/// User's relationship with another user (or themselves)
8#[derive(Deserialize, Debug, Clone, PartialEq)]
9pub enum RelationshipStatus {
10    None,
11    User,
12    Friend,
13    Outgoing,
14    Incoming,
15    Blocked,
16    BlockedOther,
17}
18
19/// Relationship entry indicating current status with other user
20#[derive(Deserialize, Debug, Clone)]
21pub struct Relationship {
22    #[serde(rename = "_id")]
23    pub id: String,
24    pub status: RelationshipStatus,
25}
26
27/// Mutual servers and friends
28#[derive(Deserialize, Debug, Clone)]
29pub struct Mutuals {
30    /// Array of mutual user IDs that both users are friends with
31    pub users: Vec<String>,
32    /// Array of mutual server IDs that both users are in
33    pub servers: Vec<String>,
34}
35
36/// Presence status
37#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
38pub enum Presence {
39    /// User is online
40    Online,
41    /// User is not currently available
42    Idle,
43    /// User is focusing / will only receive mentions
44    Focus,
45    /// User is busy / will not receive any notifications
46    Busy,
47    /// User appears to be offline
48    Invisible,
49}
50
51/// User's active status
52#[derive(Serialize, Deserialize, Debug, Clone, Default)]
53pub struct UserStatus {
54    /// Custom status text
55    #[serde(skip_serializing_if = "Option::is_none")]
56    pub text: Option<String>,
57    /// Current presence option
58    #[serde(skip_serializing_if = "Option::is_none")]
59    pub presence: Option<Presence>,
60}
61
62/// User's profile
63#[derive(Deserialize, Debug, Clone, Default)]
64pub struct UserProfile {
65    /// Text content on user's profile
66    pub content: Option<String>,
67    /// Background visible on user's profile
68    pub background: Option<Attachment>,
69}
70
71/// Partial user's profile
72///
73/// This object not contains additional background attachment data
74#[derive(Serialize, Deserialize, Debug, Clone)]
75pub struct PartialUserProfile {
76    /// Text to set as user profile description
77    #[serde(skip_serializing_if = "Option::is_none")]
78    content: Option<String>,
79    /// Attachment Id for background
80    #[serde(skip_serializing_if = "Option::is_none")]
81    background: Option<String>,
82}
83
84bitflags::bitflags! {
85    /// User badge bitfield
86    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
87    pub struct Badges: u64 {
88        /// Revolt Developer
89        const Developer = 1 << 0;
90        /// Helped translate Revolt
91        const Translator = 1 << 1;
92        /// Monetarily supported Revolt
93        const Supporter = 1 << 2;
94        /// Responsibly disclosed a security issue
95        const ResponsibleDisclosure = 1 << 3;
96        /// Revolt Founder
97        const Founder = 1 << 4;
98        /// Platform moderator
99        const PlatformModeration = 1 << 5;
100        /// Active monetary supporter
101        const ActiveSupporter = 1 << 6;
102        /// 🦊🦝
103        const Paw = 1 << 7;
104        /// Joined as one of the first 1000 users in 2021
105        const EarlyAdopter = 1 << 8;
106        /// Amogus
107        const ReservedRelevantJokeBadge1 = 1 << 9;
108        /// Low resolution troll face
109        const ReservedRelevantJokeBadge2 = 1 << 10;
110    }
111}
112crate::impl_serde_bitflags!(Badges);
113
114bitflags::bitflags! {
115    /// User flag enum
116    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
117    pub struct UserFlags: u64 {
118        /// User has been suspended from the platform
119        const Suspended = 1;
120        /// User has deleted their account
121        const Deleted = 2;
122        /// User was banned off the platform
123        const Banned = 4;
124        /// User was marked as spam and removed from platform
125        const Spam = 8;
126    }
127}
128crate::impl_serde_bitflags!(UserFlags);
129
130/// Bot information for if the user is a bot
131#[derive(Deserialize, Debug, Clone)]
132pub struct BotInformation {
133    /// Id of the owner of this bot
134    pub owner: String,
135}
136
137/// Representiation of a User on Revolt.
138#[derive(Deserialize, Debug, Clone)]
139pub struct User {
140    /// Unique Id
141    #[serde(rename = "_id")]
142    pub id: String,
143    /// Username
144    pub username: String,
145    /// User discriminator (four numbers after the username)
146    pub discriminator: String,
147    /// User's display name
148    pub display_name: Option<String>,
149    /// Avatar attachment
150    pub avatar: Option<Attachment>,
151    /// Relationships with other users
152    pub relations: Option<Vec<Relationship>>,
153
154    /// Bitfield of user badges
155    pub badges: Option<i32>,
156    /// User's current status
157    pub status: Option<UserStatus>,
158    /// User's profile page
159    pub profile: Option<UserProfile>,
160
161    /// Enum of user flags
162    pub flags: Option<UserFlags>,
163    /// Whether this user is privileged
164    #[serde(default)]
165    pub privileged: bool,
166    /// Bot information
167    pub bot: Option<BotInformation>,
168
169    /// Current session user's relationship with this user
170    pub relationship: Option<RelationshipStatus>,
171    /// Whether this user is currently online
172    pub online: Option<bool>,
173}
174
175/// Partial representiation of a User on Revolt.
176#[derive(Deserialize, Debug, Clone)]
177pub struct PartialUser {
178    /// Unique Id
179    #[serde(rename = "_id")]
180    pub id: Option<String>,
181    /// Username
182    pub username: Option<String>,
183    /// User discriminator
184    pub discriminator: Option<String>,
185    /// Display name
186    pub display_name: Option<String>,
187    /// Avatar attachment
188    pub avatar: Option<Attachment>,
189    /// Relationships with other users
190    pub relations: Option<Vec<Relationship>>,
191
192    /// Bitfield of user badges
193    pub badges: Option<i32>,
194    /// User's current status
195    pub status: Option<UserStatus>,
196    /// User's profile page
197    pub profile: Option<UserProfile>,
198
199    /// Enum of user flags
200    pub flags: Option<UserFlags>,
201    /// Whether this user is privileged
202    pub privileged: Option<bool>,
203    /// Bot information
204    pub bot: Option<BotInformation>,
205
206    /// Current session user's relationship with this user
207    pub relationship: Option<RelationshipStatus>,
208    /// Whether this user is currently online
209    pub online: Option<bool>,
210}
211
212/// Optional fields on user object
213#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
214pub enum FieldsUser {
215    Avatar,
216    StatusText,
217    StatusPresence,
218    ProfileContent,
219    ProfileBackground,
220    DisplayName,
221}
222
223/// HashMap of user settings
224/// Each key is mapped to a tuple consisting of the
225/// revision timestamp and serialised data (in JSON format)
226pub type UserSettings = HashMap<String, (i64, String)>;