zulip-api 0.0.8

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

use crate::filter::NarrowTuple;
use crate::{field_access, ClientCapabilities, EventType, IncludeSubscribers};

/// Represents the request to the `Register` Zulip API.
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
pub struct Request {
    #[serde(skip_serializing_if = "Option::is_none")]
    apply_markdown: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    client_gravatar: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    include_subscribers: Option<IncludeSubscribers>,
    #[serde(skip_serializing_if = "Option::is_none")]
    slim_presence: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    presence_history_limit_days: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    event_types: Option<Vec<EventType>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    all_public_streams: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    client_capabilities: Option<ClientCapabilities>,
    #[serde(skip_serializing_if = "Option::is_none")]
    fetch_event_types: Option<Vec<EventType>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    narrow: Option<Vec<NarrowTuple>>,
}

impl Request {
    /// Creates a new [Request].
    pub const fn new() -> Self {
        Self {
            apply_markdown: None,
            client_gravatar: None,
            include_subscribers: None,
            slim_presence: None,
            presence_history_limit_days: None,
            event_types: None,
            all_public_streams: None,
            client_capabilities: None,
            fetch_event_types: None,
            narrow: None,
        }
    }
}

impl Default for Request {
    fn default() -> Self {
        Self::new()
    }
}

field_access! {
    Request {
        /// Set to `true` if you would like the content to be rendered in HTML
        /// format (otherwise the API will return the raw text that the user entered)
        apply_markdown: option { bool },
        /// Whether the client supports computing gravatars URLs. If
        /// enabled, `avatar_url` will be included in the response only
        /// if there is a Zulip avatar, and will be `null` for users who
        /// are using gravatar as their avatar. This option
        /// significantly reduces the compressed size of user data,
        /// since gravatar URLs are long, random strings and thus do not
        /// compress well. The `client_gravatar` field is set to `true` if
        /// clients can compute their own gravatars.
        ///
        /// The default value is `true` for authenticated requests and
        /// `false` for [unauthenticated requests](https://zulip.com/help/public-access-option).
        ///
        /// Passing `true` in an unauthenticated request is an error.
        ///
        /// **Changes**: Before Zulip 6.0 (feature level 149), this
        /// parameter was silently ignored and processed as though it
        /// were `false` in unauthenticated requests.
        client_gravatar: option { bool },
        /// Whether each returned channel object should include a `subscribers`
        /// field containing a list of the user IDs of its subscribers.
        include_subscribers: option { IncludeSubscribers },
        /// If `true`, the `presences` object returned in the response will be keyed
        /// by user ID and the entry for each user's presence data will be in the
        /// modern format.
        ///
        /// **Changes**: New in Zulip 3.0 (no feature level; API unstable).
        slim_presence: option { bool },
        /// Limits how far back in time to fetch user presence data. If not specified,
        /// defaults to 14 days. A value of N means that the oldest presence data
        /// fetched will be from at most N days ago.
        ///
        /// **Changes**: New in Zulip 10.0 (feature level 288).
        presence_history_limit_days: option { u64 },
        /// Whether you would like to request message events from all public
        /// channels. Useful for workflow bots that you'd like to see all new messages
        /// sent to public channels. (You can also subscribe the user to private channels).
        all_public_streams: option { bool },
        /// Dictionary containing details on features the client supports that are
        /// relevant to the format of responses sent by the server.
        client_capabilities: option { ClientCapabilities },
    }
}

field_access! {
    Request {
        /// A JSON-encoded array indicating which types of events you're interested
        /// in. Values that you might find useful include:
        event_types: option_cow_deref { [EventType], Vec<EventType> },
        /// Same as the `event_types` parameter except that the values in
        /// `fetch_event_types` are used to fetch initial data. If
        /// `fetch_event_types` is not provided, `event_types` is used and if
        /// `event_types` is not provided, this parameter defaults to `null`.
        ///
        /// Event types not supported by the server are ignored, in order to simplify
        /// the implementation of client apps that support multiple server versions.
        fetch_event_types: option_cow_deref { [EventType], Vec<EventType> },
        /// A JSON-encoded array of arrays of length 2 indicating the
        /// [narrow filter(s)](https://zulip.com/api/construct-narrow) for which you'd
        /// like to receive events for.
        ///
        /// For example, to receive events for direct messages (including
        /// group direct messages) received by the user, one can use
        /// `"narrow": [["is", "dm"]]`.
        ///
        /// Unlike the API for [fetching messages](https://zulip.com/api/get-messages),
        /// this narrow parameter is simply a filter on messages that the
        /// user receives through their channel subscriptions (or because
        /// they are a recipient of a direct message).
        ///
        /// This means that a client that requests a `narrow` filter of
        /// `[["channel", "Denmark"]]` will receive events for new messages
        /// sent to that channel while the user is subscribed to that
        /// channel. The client will not receive any message events at all
        /// if the user is not subscribed to `"Denmark"`.
        ///
        /// Newly created bot users are not usually subscribed to any
        /// channels, so bots using this API need to be
        /// [subscribed](https://zulip.com/api/subscribe) to any channels whose messages
        /// you'd like them to process using this endpoint.
        ///
        /// See the `all_public_streams` parameter for how to process all
        /// public channel messages in an organization.
        ///
        /// **Changes**: See [changes section](https://zulip.com/api/construct-narrow#changes)
        /// of search/narrow filter documentation.
        narrow: option_cow_deref { [NarrowTuple], Vec<NarrowTuple> },
    }
}