zulip-api 0.0.8

Client library for interacting with the Zulip API
Documentation
use serde::{Deserialize, Serialize};

use crate::{field_access, impl_default, impl_display};

mod huddle;
mod pm;
mod stream;

pub use huddle::UnreadMsgsHuddle;
pub use pm::UnreadMsgsPm;
pub use stream::UnreadMsgsStream;

/// Represents a set of data structures describing the conversations containing the 50000 most recent unread messages the user has received.
///
/// 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).
///
/// 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 UnreadMsgs {
    #[serde(skip_serializing_if = "Option::is_none")]
    count: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pms: Option<Vec<UnreadMsgsPm>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    streams: Option<Vec<UnreadMsgsStream>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    huddles: Option<Vec<UnreadMsgsHuddle>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    mentions: Option<Vec<u64>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    old_unreads_missing: Option<bool>,
}

impl UnreadMsgs {
    /// Creates a new [UnreadMsgs].
    pub const fn new() -> Self {
        Self {
            count: None,
            pms: None,
            streams: None,
            huddles: None,
            mentions: None,
            old_unreads_missing: None,
        }
    }
}

field_access! {
    UnreadMsgs {
        /// The total number of unread messages to display.
        ///
        /// 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).
        ///
        /// **Changes**: Before Zulip 8.0 (feature level 213), the unmute and follow topic features were not handled correctly in calculating this field.
        count: option { u64 },
        /// Whether this data set was truncated because the user has too many unread messages.
        ///
        /// When truncation occurs, only the most recent `MAX_UNREAD_MESSAGES` (currently 50000) messages will be considered when forming this response.
        /// When `true`, we recommend that clients display a warning,
        /// as they are likely to produce erroneous results until reloaded with the user having fewer than `MAX_UNREAD_MESSAGES` unread messages.
        ///
        /// **Changes**: New in Zulip 4.0 (feature level 44).
        old_unreads_missing: option { bool },
    }
}

field_access! {
    UnreadMsgs {
        /// An array of objects where each object contains details of unread one-on-one direct messages with a specific user.
        ///
        /// 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.
        pms: option_cow_deref { [UnreadMsgsPm], Vec<UnreadMsgsPm> },
        /// An array of dictionaries where each dictionary contains details of all unread messages of a single subscribed channel.
        ///
        /// This includes muted channels and muted topics, even though those messages are excluded from `count`.
        ///
        /// **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.
        streams: option_cow_deref { [UnreadMsgsStream], Vec<UnreadMsgsStream> },
        /// An array of objects where each object contains details of unread group direct messages with a specific group of users.
        huddles: option_cow_deref { [UnreadMsgsHuddle], Vec<UnreadMsgsHuddle> },
        /// Array containing the IDs of all unread messages in which the user was mentioned directly,
        /// and unread [non-muted](https://zulip.com/help/mute-a-topic) messages in which the user was mentioned through a wildcard.
        ///
        /// **Changes**: Before Zulip 8.0 (feature level 213), the unmute and follow topic features were not handled correctly in calculating this field.
        mentions: option_cow_deref { [u64], Vec<u64> },
    }
}

impl_default!(UnreadMsgs);
impl_display!(UnreadMsgs);