Skip to main content

zulip_api/message/
unread_msgs.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{field_access, impl_default, impl_display};
4
5mod huddle;
6mod pm;
7mod stream;
8
9pub use huddle::UnreadMsgsHuddle;
10pub use pm::UnreadMsgsPm;
11pub use stream::UnreadMsgsStream;
12
13/// Represents a set of data structures describing the conversations containing the 50000 most recent unread messages the user has received.
14///
15/// This will usually contain every unread message the user has received, but clients should support users with even more unread messages (and not hardcode the number 50000).
16///
17/// Modified from `openapi-generator-cli` output:
18///
19/// ```shell,no_build,no_run
20/// $ openapi-generator-cli generate -g rust -i ./zerver/openapi/zulip.yaml -o zulip-openapi --skip-validate-spec
21/// ```
22///
23/// ```text
24/// /*
25/// * Zulip REST API
26/// *
27/// * Powerful open source group chat
28/// *
29/// * The version of the OpenAPI document: 1.0.0
30/// *
31/// * Generated by: https://openapi-generator.tech
32/// */
33/// ```
34///
35/// See [zerver/openapi/zulip.yaml](https://github.com/zulip/zulip/blob/main/zerver/openapi/zulip.yaml) for the original OpenAPI configuration.
36///
37/// Configuration slightly modified to work with the Rust generator of [`openapi-generator-cli`](https://openapi-generator.tech).
38#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
39pub struct UnreadMsgs {
40    #[serde(skip_serializing_if = "Option::is_none")]
41    count: Option<u64>,
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pms: Option<Vec<UnreadMsgsPm>>,
44    #[serde(skip_serializing_if = "Option::is_none")]
45    streams: Option<Vec<UnreadMsgsStream>>,
46    #[serde(skip_serializing_if = "Option::is_none")]
47    huddles: Option<Vec<UnreadMsgsHuddle>>,
48    #[serde(skip_serializing_if = "Option::is_none")]
49    mentions: Option<Vec<u64>>,
50    #[serde(skip_serializing_if = "Option::is_none")]
51    old_unreads_missing: Option<bool>,
52}
53
54impl UnreadMsgs {
55    /// Creates a new [UnreadMsgs].
56    pub const fn new() -> Self {
57        Self {
58            count: None,
59            pms: None,
60            streams: None,
61            huddles: None,
62            mentions: None,
63            old_unreads_missing: None,
64        }
65    }
66}
67
68field_access! {
69    UnreadMsgs {
70        /// The total number of unread messages to display.
71        ///
72        /// This includes one-on-one and group direct messages, as well as channel messages that are not [muted](https://zulip.com/help/mute-a-topic).
73        ///
74        /// **Changes**: Before Zulip 8.0 (feature level 213), the unmute and follow topic features were not handled correctly in calculating this field.
75        count: option { u64 },
76        /// Whether this data set was truncated because the user has too many unread messages.
77        ///
78        /// When truncation occurs, only the most recent `MAX_UNREAD_MESSAGES` (currently 50000) messages will be considered when forming this response.
79        /// When `true`, we recommend that clients display a warning,
80        /// as they are likely to produce erroneous results until reloaded with the user having fewer than `MAX_UNREAD_MESSAGES` unread messages.
81        ///
82        /// **Changes**: New in Zulip 4.0 (feature level 44).
83        old_unreads_missing: option { bool },
84    }
85}
86
87field_access! {
88    UnreadMsgs {
89        /// An array of objects where each object contains details of unread one-on-one direct messages with a specific user.
90        ///
91        /// Note that it is possible for a message that the current user sent to the specified user to be marked as unread and thus appear here.
92        pms: option_cow_deref { [UnreadMsgsPm], Vec<UnreadMsgsPm> },
93        /// An array of dictionaries where each dictionary contains details of all unread messages of a single subscribed channel.
94        ///
95        /// This includes muted channels and muted topics, even though those messages are excluded from `count`.
96        ///
97        /// **Changes**: Prior to Zulip 5.0 (feature level 90), these objects included a `sender_ids` property, which listed the set of IDs of users who had sent the unread messages.
98        streams: option_cow_deref { [UnreadMsgsStream], Vec<UnreadMsgsStream> },
99        /// An array of objects where each object contains details of unread group direct messages with a specific group of users.
100        huddles: option_cow_deref { [UnreadMsgsHuddle], Vec<UnreadMsgsHuddle> },
101        /// Array containing the IDs of all unread messages in which the user was mentioned directly,
102        /// and unread [non-muted](https://zulip.com/help/mute-a-topic) messages in which the user was mentioned through a wildcard.
103        ///
104        /// **Changes**: Before Zulip 8.0 (feature level 213), the unmute and follow topic features were not handled correctly in calculating this field.
105        mentions: option_cow_deref { [u64], Vec<u64> },
106    }
107}
108
109impl_default!(UnreadMsgs);
110impl_display!(UnreadMsgs);