zulip_api/message/user.rs
1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5use crate::{field_access, impl_default, impl_display, BotType, ProfileData, Role};
6
7/// Represents basic data on a given Zulip user.
8///
9/// **Changes**: Removed `is_billing_admin` field in Zulip 10.0 (feature level 363), as it was replaced by the `can_manage_billing_group` realm setting.
10///
11/// Modified from `openapi-generator-cli` output:
12///
13/// ```shell,no_build,no_run
14/// $ openapi-generator-cli generate -g rust -i ./zerver/openapi/zulip.yaml -o zulip-openapi --skip-validate-spec
15/// ```
16///
17/// ```text
18/// /*
19/// * Zulip REST API
20/// *
21/// * Powerful open source group chat
22/// *
23/// * The version of the OpenAPI document: 1.0.0
24/// *
25/// * Generated by: https://openapi-generator.tech
26/// */
27/// ```
28///
29/// See [zerver/openapi/zulip.yaml](https://github.com/zulip/zulip/blob/main/zerver/openapi/zulip.yaml) for the original OpenAPI configuration.
30///
31/// Configuration slightly modified to work with the Rust generator of [`openapi-generator-cli`](https://openapi-generator.tech).
32#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
33pub struct User {
34 #[serde(skip_serializing_if = "Option::is_none")]
35 user_id: Option<u64>,
36 #[serde(skip_serializing_if = "Option::is_none")]
37 delivery_email: Option<String>,
38 #[serde(skip_serializing_if = "Option::is_none")]
39 email: Option<String>,
40 #[serde(skip_serializing_if = "Option::is_none")]
41 full_name: Option<String>,
42 #[serde(skip_serializing_if = "Option::is_none")]
43 date_joined: Option<String>,
44 #[serde(skip_serializing_if = "Option::is_none")]
45 is_active: Option<bool>,
46 #[serde(skip_serializing_if = "Option::is_none")]
47 is_owner: Option<bool>,
48 #[serde(skip_serializing_if = "Option::is_none")]
49 is_admin: Option<bool>,
50 #[serde(skip_serializing_if = "Option::is_none")]
51 is_guest: Option<bool>,
52 #[serde(skip_serializing_if = "Option::is_none")]
53 is_bot: Option<bool>,
54 #[serde(skip_serializing_if = "Option::is_none")]
55 bot_type: Option<BotType>,
56 #[serde(skip_serializing_if = "Option::is_none")]
57 bot_owner_id: Option<u64>,
58 #[serde(skip_serializing_if = "Option::is_none")]
59 role: Option<Role>,
60 #[serde(skip_serializing_if = "Option::is_none")]
61 timezone: Option<String>,
62 #[serde(skip_serializing_if = "Option::is_none")]
63 avatar_url: Option<String>,
64 #[serde(skip_serializing_if = "Option::is_none")]
65 avatar_version: Option<u64>,
66 #[serde(skip_serializing_if = "Option::is_none")]
67 profile_data: Option<HashMap<String, ProfileData>>,
68}
69
70impl User {
71 /// A dictionary containing basic data on a given Zulip user.
72 ///
73 /// **Changes**: Removed `is_billing_admin` field in Zulip 10.0 (feature level 363), as it was replaced by the `can_manage_billing_group` realm setting.
74 pub const fn new() -> Self {
75 Self {
76 user_id: None,
77 delivery_email: None,
78 email: None,
79 full_name: None,
80 date_joined: None,
81 is_active: None,
82 is_owner: None,
83 is_admin: None,
84 is_guest: None,
85 is_bot: None,
86 bot_type: None,
87 bot_owner_id: None,
88 role: None,
89 timezone: None,
90 avatar_url: None,
91 avatar_version: None,
92 profile_data: None,
93 }
94 }
95}
96
97field_access! {
98 User {
99 /// The unique ID of the user.
100 user_id: option { u64 },
101 /// A boolean specifying whether the user account has been deactivated.
102 is_active: option { bool },
103 /// A boolean specifying whether the user is an organization owner. If true, `is_admin` will also be true. **Changes**: New in Zulip 3.0 (feature level 8).
104 is_owner: option { bool },
105 /// A boolean specifying whether the user is an organization administrator.
106 is_admin: option { bool },
107 /// A boolean specifying whether the user is a guest user.
108 is_guest: option { bool },
109 /// A boolean specifying whether the user is a bot or full account.
110 is_bot: option { bool },
111 /// An integer describing the type of bot.
112 bot_type: option { BotType },
113 /// If the user is a bot (i.e. `is_bot` is true), then `bot_owner_id` is the user ID of the bot's owner (usually, whoever created the bot).
114 ///
115 /// Will be `null` for legacy bots that do not have an owner.
116 ///
117 /// **Changes**: New in Zulip 3.0 (feature level 1). In previous versions, there was a `bot_owner` field containing the email address of the bot's owner.
118 bot_owner_id: option { u64 },
119 /// [Organization-level role](https://zulip.com/api/roles-and-permissions) of the user.
120 role: option { Role },
121 /// Version for the user's avatar. Used for cache-busting requests for the user's avatar. Clients generally shouldn't need to use this; most avatar URLs sent by Zulip will already end with `?v={avatar_version}`.
122 avatar_version: option { u64 },
123 }
124}
125
126field_access! {
127 User {
128 /// The user's real email address.
129 ///
130 /// This value will be `null` if you cannot access user's real email address.
131 /// For bot users, this field is always set to the real email of the bot, because bot users always have `email_address_visibility` set to everyone.
132 ///
133 /// **Changes**: Prior to Zulip 7.0 (feature level 163), this field was present only when `email_address_visibility` was restricted and you had access to the user's real email.
134 /// As of this feature level, this field is always present, including the case when `email_address_visibility` is set to everyone (and therefore not restricted).
135 delivery_email: option_cow_deref { str, String },
136 /// The Zulip API email address of the user or bot.
137 ///
138 /// If you do not have permission to view the email address of the target user, this will be a fake email address that is usable for the Zulip API but nothing else.
139 email: option_cow_deref { str, String },
140 /// Full name of the user or bot, used for all display purposes.
141 full_name: option_cow_deref { str, String },
142 /// The time the user account was created.
143 date_joined: option_cow_deref { str, String },
144 /// The IANA identifier of the user's [profile time zone](https://zulip.com/help/change-your-timezone), which is used primarily to display the user's local time to other users.
145 timezone: option_cow_deref { str, String },
146 /// URL for the user's avatar.
147 ///
148 /// Will be `null` if the `client_gravatar` query parameter was set to `true`,
149 /// the current user has access to this user's real email address,
150 /// and this user's avatar is hosted by the Gravatar provider (i.e. this user has never uploaded an avatar).
151 ///
152 /// **Changes**: Before Zulip 7.0 (feature level 163),
153 /// access to a user's real email address was a realm-level setting.
154 /// As of this feature level, `email_address_visibility` is a user setting.
155 ///
156 /// In Zulip 3.0 (feature level 18), if the client has the `user_avatar_url_field_optional` capability, this will be missing at the server's sole discretion.
157 avatar_url: option_cow_deref { str, String },
158 }
159}
160
161field_access! {
162 User {
163 /// Only present if `is_bot` is false; bots can't have custom profile fields.
164 ///
165 /// A dictionary containing custom profile field data for the user.
166 /// Each entry maps the integer ID of a custom profile field in the organization to a dictionary containing the user's data for that field.
167 /// Generally the data includes just a single `value` key; for those custom profile fields supporting Markdown, a `rendered_value` key will also be present.
168 profile_data: option_ref { HashMap<String, ProfileData> },
169 }
170}
171
172impl_default!(User);
173impl_display!(User);