1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
use crate::message::channel_permission::*;
use crate::{field_access, impl_default, impl_display, TopicsPolicy};
/// Represents the properties of a channel the user is subscribed to (as well as that user's personal per-channel settings).
///
/// **Changes**: Removed `email_address` field from the dictionary in Zulip 8.0 (feature level 226). Removed `role` field from the dictionary in Zulip 6.0 (feature level 133).
///
/// Modified from `openapi-generator-cli` output:
///
/// ```shell,no_build,no_run
/// $ openapi-generator-cli generate -g rust -i ./zerver/openapi/zulip.yaml -o zulip-openapi --skip-validate-spec
/// ```
///
/// ```text
/// /*
/// * Zulip REST API
/// *
/// * Powerful open source group chat
/// *
/// * The version of the OpenAPI document: 1.0.0
/// *
/// * Generated by: https://openapi-generator.tech
/// */
/// ```
///
/// See [zerver/openapi/zulip.yaml](https://github.com/zulip/zulip/blob/main/zerver/openapi/zulip.yaml) for the original OpenAPI configuration.
///
/// Configuration slightly modified to work with the Rust generator of [`openapi-generator-cli`](https://openapi-generator.tech).
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Subscription {
#[serde(skip_serializing_if = "Option::is_none")]
stream_id: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
rendered_description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
date_created: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
creator_id: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
invite_only: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
subscribers: Option<Vec<u64>>,
#[serde(skip_serializing_if = "Option::is_none")]
partial_subscribers: Option<Vec<u64>>,
#[serde(skip_serializing_if = "Option::is_none")]
desktop_notifications: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
email_notifications: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
wildcard_mentions_notify: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
push_notifications: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
audible_notifications: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pin_to_top: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
is_muted: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
in_home_view: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
is_announcement_only: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
is_web_public: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
color: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
stream_post_policy: Option<StreamPostPolicy>,
#[serde(skip_serializing_if = "Option::is_none")]
message_retention_days: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
history_public_to_subscribers: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
first_message_id: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
folder_id: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
topics_policy: Option<TopicsPolicy>,
#[serde(skip_serializing_if = "Option::is_none")]
is_recently_active: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
stream_weekly_traffic: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
can_add_subscribers_group: Option<CanAddSubscribersGroup>,
#[serde(skip_serializing_if = "Option::is_none")]
can_remove_subscribers_group: Option<CanRemoveSubscribersGroup>,
#[serde(skip_serializing_if = "Option::is_none")]
can_administer_channel_group: Option<CanAdministerChannelGroup>,
#[serde(skip_serializing_if = "Option::is_none")]
can_delete_any_message_group: Option<CanDeleteAnyMessageGroup>,
#[serde(skip_serializing_if = "Option::is_none")]
can_delete_own_message_group: Option<CanDeleteOwnMessageGroup>,
#[serde(skip_serializing_if = "Option::is_none")]
can_move_messages_out_of_channel_group: Option<CanMoveMessagesOutOfChannelGroup>,
#[serde(skip_serializing_if = "Option::is_none")]
can_move_messages_within_channel_group: Option<CanMoveMessagesWithinChannelGroup>,
#[serde(skip_serializing_if = "Option::is_none")]
can_send_message_group: Option<CanSendMessageGroup>,
#[serde(skip_serializing_if = "Option::is_none")]
can_subscribe_group: Option<CanSubscribeGroup>,
#[serde(skip_serializing_if = "Option::is_none")]
can_resolve_topics_group: Option<CanResolveTopicsGroup>,
#[serde(skip_serializing_if = "Option::is_none")]
is_archived: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
subscriber_count: Option<f64>,
}
impl Subscription {
/// Creates a new [Subscription].
pub const fn new() -> Self {
Self {
stream_id: None,
name: None,
description: None,
rendered_description: None,
date_created: None,
creator_id: None,
invite_only: None,
subscribers: None,
partial_subscribers: None,
desktop_notifications: None,
email_notifications: None,
wildcard_mentions_notify: None,
push_notifications: None,
audible_notifications: None,
pin_to_top: None,
is_muted: None,
in_home_view: None,
is_announcement_only: None,
is_web_public: None,
color: None,
stream_post_policy: None,
message_retention_days: None,
history_public_to_subscribers: None,
first_message_id: None,
folder_id: None,
topics_policy: None,
is_recently_active: None,
stream_weekly_traffic: None,
can_add_subscribers_group: None,
can_remove_subscribers_group: None,
can_administer_channel_group: None,
can_delete_any_message_group: None,
can_delete_own_message_group: None,
can_move_messages_out_of_channel_group: None,
can_move_messages_within_channel_group: None,
can_send_message_group: None,
can_subscribe_group: None,
can_resolve_topics_group: None,
is_archived: None,
subscriber_count: None,
}
}
}
field_access! {
Subscription {
/// The unique ID of a channel.
stream_id: option { u64 },
/// The UNIX timestamp for when the channel was created, in UTC seconds.
///
/// **Changes**: New in Zulip 4.0 (feature level 30).
date_created: option { u64 },
/// The ID of the user who created this channel.
///
/// A `null` value means the channel has no recorded creator,
/// which is often because the channel is very old,
/// was created during realm creation or because it was created via a data import tool or [management command](https://zulip.readthedocs.io/en/latest/production/management-commands.html).
///
/// **Changes**: New in Zulip 9.0 (feature level 254).
creator_id: option { u64 },
/// Specifies whether the channel is private or not.
///
/// Only people who have been invited can access a private channel.
invite_only: option { bool },
/// A boolean specifying whether desktop notifications are enabled for the given channel.
///
/// A `null` value means the value of this setting should be inherited from the user-level default setting, `enable_stream_desktop_notifications`, for this channel.
desktop_notifications: option { bool },
/// A boolean specifying whether email notifications are enabled for the given channel.
///
/// A `null` value means the value of this setting should be inherited from the user-level default setting, `enable_stream_email_notifications`, for this channel.
email_notifications: option { bool },
/// A boolean specifying whether wildcard mentions trigger notifications as though they were personal mentions in this channel.
///
/// A `null` value means the value of this setting should be inherited from the user-level default setting, wildcard_mentions_notify, for this channel.
wildcard_mentions_notify: option { bool },
/// A boolean specifying whether push notifications are enabled for the given channel.
///
/// A `null` value means the value of this setting should be inherited from the user-level default setting, `enable_stream_push_notifications`, for this channel.
push_notifications: option { bool },
/// A boolean specifying whether audible notifications are enabled for the given channel.
///
/// A `null` value means the value of this setting should be inherited from the user-level default setting, `enable_stream_audible_notifications`, for this channel.
audible_notifications: option { bool },
/// A boolean specifying whether the given channel has been pinned to the top.
pin_to_top: option { bool },
/// Whether the user has muted the channel. Muted channels do not count towards your total unread count and do not show up in the `Combined feed` view (previously known as `All messages`).
///
/// **Changes**: Prior to Zulip 2.1.0, this feature was represented by the more confusingly named `in_home_view` (with the opposite value, `in_home_view=!is_muted`).
is_muted: option { bool },
/// Legacy property for if the given channel is muted, with inverted meaning.
///
/// **Changes**: Deprecated in Zulip 2.1.0. Clients should use `is_muted` where available.
in_home_view: option { bool },
/// Whether only organization administrators can post to the channel.
///
/// **Changes**: Deprecated in Zulip 3.0 (feature level 1). Clients should use `stream_post_policy` instead.
is_announcement_only: option { bool },
/// Whether the channel has been configured to allow unauthenticated access to its message history from the web.
is_web_public: option { bool },
/// A deprecated representation of a superset of the users who have permission to post messages to the channel available for backwards-compatibility.
stream_post_policy: option { StreamPostPolicy },
/// Number of days that messages sent to this channel will be stored before being automatically deleted by the [message retention policy](https://zulip.com/help/message-retention-policy).
///
/// There are two special values:
///
/// - `null`, the default, means the channel will inherit the organization level setting.
/// - `-1` encodes retaining messages in this channel forever.
///
/// **Changes**: New in Zulip 3.0 (feature level 17).
message_retention_days: option { i32 },
/// Whether the history of the channel is public to its subscribers.
///
/// Currently always true for public channels (i.e. `\"invite_only\": false` implies `\"history_public_to_subscribers\": true`),
/// but clients should not make that assumption, as we may change that behavior in the future.
history_public_to_subscribers: option { bool },
/// The ID of the first message in the channel.
///
/// Intended to help clients determine whether they need to display UI like the \"show all topics\" widget that would suggest the channel has older history that can be accessed.
///
/// Is `null` for channels with no message history.
first_message_id: option { u64 },
/// The ID of the folder to which the channel belongs.
///
/// Is `null` if channel does not belong to any folder.
///
/// **Changes**: New in Zulip 11.0 (feature level 389).
folder_id: option { u64 },
topics_policy: option { TopicsPolicy },
/// Whether the channel has recent message activity.
///
/// Clients should use this to implement [hiding inactive channels](https://zulip.com/help/manage-inactive-channels).
///
/// **Changes**: New in Zulip 10.0 (feature level 323). Previously, clients implemented the demote_inactive_streams from local message history, resulting in a choppy loading experience.
is_recently_active: option { bool },
/// The average number of messages sent to the channel per week, as estimated based on recent weeks, rounded to the nearest integer.
///
/// If `null`, the channel was recently created and there is insufficient data to estimate the average traffic.
stream_weekly_traffic: option { u64 },
/// A boolean indicating whether the channel is [archived](https://zulip.com/help/archive-a-channel).
///
/// **Changes**: New in Zulip 10.0 (feature level 315). Previously, subscriptions only included active channels.
/// Note that some endpoints will never return archived channels unless the client declares explicit support for them via the `archived_channels` client capability.
is_archived: option { bool },
/// The total number of non-deactivated users (including bots) who are subscribed to the channel.
///
/// Clients are responsible for updating this value using `peer_add` and `peer_remove` events.
///
/// The server's internals cannot guarantee this value is correctly synced with `peer_add` and `peer_remove` events for the channel.
/// As a result, if a (rare) race occurs between a change in the channel's subscribers and fetching this value,
/// it is possible for a client that is correctly following the events protocol to end up with a permanently off-by-one error in the channel's subscriber count.
///
/// Clients are recommended to fetch full subscriber data for a channel in contexts where it is important to avoid this risk.
/// The official web application, for example, uses this field primarily while waiting to fetch a given channel's full subscriber list from the server.
///
/// **Changes**: New in Zulip 11.0 (feature level 394).
subscriber_count: option { f64 },
}
}
field_access! {
Subscription {
/// The name of a channel.
name: option_cow_deref { str, String },
/// The [description](https://zulip.com/help/change-the-channel-description) of the channel in [Zulip-flavored Markdown](https://zulip.com/help/format-your-message-using-markdown) format,
/// intended to be used to prepopulate UI for editing a channel's description.
///
/// See [Markdown message formatting](https://zulip.com/api/message-formatting) for details on Zulip's HTML format.
///
/// See also `rendered_description`.
description: option_cow_deref { str, String },
/// The [description](https://zulip.com/help/change-the-channel-description) of the channel rendered as HTML,
/// intended to be used when displaying the channel description in a UI.
///
/// One should use the standard Zulip rendered_markdown CSS when displaying this content so that emoji, LaTeX,
/// and other syntax work correctly.
///
/// And any client-side security logic for user-generated message content should be applied when displaying this HTML as though it were the body of a Zulip message.
///
/// See also `description`.
rendered_description: option_cow_deref { str, String },
/// A list of user IDs of users who are also subscribed to a given channel. Included only if `include_subscribers` is `true`.
subscribers: option_cow_deref { [u64], Vec<u64> },
/// If [`include_subscribers=\"partial\"`](https://zulip.com/api/get-subscriptions#parameter-include_subscribers) was requested, the server may,
/// at its discretion, send a `partial_subscribers` list rather than a `subscribers` list for channels with a large number of subscribers.
///
/// The `partial_subscribers` list contains an arbitrary subset of the channel's subscribers that is guaranteed to include all bot user
/// subscribers as well as all users who have been active in the last 14 days, but otherwise can be chosen arbitrarily by the server.
///
/// **Changes**: New in Zulip 11.0 (feature level 412).
partial_subscribers: option_cow_deref { [u64], Vec<u64> },
/// The user's personal color for the channel.
color: option_cow_deref { str, String },
}
}
field_access! {
Subscription {
can_add_subscribers_group: option_ref { CanAddSubscribersGroup },
can_remove_subscribers_group: option_ref { CanRemoveSubscribersGroup },
can_administer_channel_group: option_ref { CanAdministerChannelGroup },
can_delete_any_message_group: option_ref { CanDeleteAnyMessageGroup },
can_delete_own_message_group: option_ref { CanDeleteOwnMessageGroup },
can_move_messages_out_of_channel_group: option_ref { CanMoveMessagesOutOfChannelGroup },
can_move_messages_within_channel_group: option_ref { CanMoveMessagesWithinChannelGroup },
can_send_message_group: option_ref { CanSendMessageGroup },
can_subscribe_group: option_ref { CanSubscribeGroup },
can_resolve_topics_group: option_ref { CanResolveTopicsGroup },
}
}
impl_default!(Subscription);
impl_display!(Subscription);
/// Represents A deprecated representation of a superset of the users who
/// have permission to post messages to the channel available
/// for backwards-compatibility.
///
/// Clients should use `can_send_message_group` instead.
#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize_repr, Serialize_repr)]
pub enum StreamPostPolicy {
/// Any user can post.
AnyUser = 1,
/// Only administrators can post.
OnlyAdministrator = 2,
/// Only full members can post.
OnlyFullMember = 3,
/// Only moderators can post.
OnlyModerator = 4,
}
impl StreamPostPolicy {
/// Creates a new [StreamPostPolicy].
pub const fn new() -> Self {
Self::AnyUser
}
}
impl_default!(StreamPostPolicy);
impl_display!(StreamPostPolicy);