Skip to main content

zulip_api/message/
user_topic.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{field_access, impl_default, impl_display, VisibilityPolicy};
4
5/// Represents the user's configuration for a given topic.
6///
7/// Modified from `openapi-generator-cli` output:
8///
9/// ```shell,no_build,no_run
10/// $ openapi-generator-cli generate -g rust -i ./zerver/openapi/zulip.yaml -o zulip-openapi --skip-validate-spec
11/// ```
12///
13/// ```text
14/// /*
15/// * Zulip REST API
16/// *
17/// * Powerful open source group chat
18/// *
19/// * The version of the OpenAPI document: 1.0.0
20/// *
21/// * Generated by: https://openapi-generator.tech
22/// */
23/// ```
24///
25/// See [zerver/openapi/zulip.yaml](https://github.com/zulip/zulip/blob/main/zerver/openapi/zulip.yaml) for the original OpenAPI configuration.
26///
27/// Configuration slightly modified to work with the Rust generator of [`openapi-generator-cli`](https://openapi-generator.tech).
28#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
29pub struct UserTopic {
30    #[serde(skip_serializing_if = "Option::is_none")]
31    stream_id: Option<u64>,
32    #[serde(skip_serializing_if = "Option::is_none")]
33    topic_name: Option<String>,
34    #[serde(skip_serializing_if = "Option::is_none")]
35    last_updated: Option<u64>,
36    #[serde(skip_serializing_if = "Option::is_none")]
37    visibility_policy: Option<VisibilityPolicy>,
38}
39
40impl UserTopic {
41    /// Creates a new [UserTopic].
42    pub const fn new() -> UserTopic {
43        UserTopic {
44            stream_id: None,
45            topic_name: None,
46            last_updated: None,
47            visibility_policy: None,
48        }
49    }
50}
51
52field_access! {
53    UserTopic {
54        /// The ID of the channel to which the topic belongs.
55        stream_id: option { u64 },
56        /// An integer UNIX timestamp representing when the user-topic relationship was changed.
57        last_updated: option { u64 },
58        /// An integer indicating the user's visibility configuration for the topic.
59        visibility_policy: option { VisibilityPolicy },
60    }
61}
62
63field_access! {
64    UserTopic {
65        /// The name of the topic.
66        ///
67        /// Note that the empty string topic may have been rewritten by the server to the value of `realm_empty_topic_display_name` found in the
68        /// [`POST /register`](https://zulip.com/api/register-queue) response depending on the value of the `empty_topic_name`
69        /// [client capability](https://zulip.com/api/register-queue#parameter-client_capabilities).
70        ///
71        /// **Changes**: The `empty_topic_name` client capability is new in Zulip 10.0 (feature level 334).
72        topic_name: option_cow_deref { str, String },
73    }
74}
75
76impl_default!(UserTopic);
77impl_display!(UserTopic);