Skip to main content

zulip_api/message/
default_channel_group.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{field_access, impl_cow, impl_default, impl_display};
4
5/// Represents details of a default channel group.
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 DefaultChannelGroup {
30    #[serde(skip_serializing_if = "Option::is_none")]
31    name: Option<String>,
32    #[serde(skip_serializing_if = "Option::is_none")]
33    description: Option<String>,
34    #[serde(skip_serializing_if = "Option::is_none")]
35    id: Option<u64>,
36    #[serde(skip_serializing_if = "Option::is_none")]
37    streams: Option<Vec<u64>>,
38}
39
40impl DefaultChannelGroup {
41    /// Dictionary containing details of a default channel group.
42    pub const fn new() -> Self {
43        Self {
44            name: None,
45            description: None,
46            id: None,
47            streams: None,
48        }
49    }
50}
51
52field_access! {
53    DefaultChannelGroup {
54        /// Name of the default channel group.
55        name: option_cow_deref { str, String },
56        /// Description of the default channel group.
57        description: option_cow_deref { str, String },
58        /// An array of IDs of all the channels in the default stream group.
59        ///
60        /// **Changes**: Before Zulip 10.0 (feature level 330), we sent array of dictionaries where each dictionary contained details about a single stream in the default stream group.
61        streams: option_cow_deref { [u64], Vec<u64> },
62    }
63}
64
65field_access! {
66    DefaultChannelGroup {
67        /// The ID of the default channel group.
68        id: option { u64 },
69    }
70}
71
72impl_cow!(DefaultChannelGroup);
73impl_default!(DefaultChannelGroup);
74impl_display!(DefaultChannelGroup);
75
76#[cfg(test)]
77mod tests {
78    use super::*;
79
80    #[test]
81    fn test_default_channel_group() {
82        let name = "test name";
83        let description = "test description";
84        let id = 1;
85        let streams = [1u64];
86
87        let group = DefaultChannelGroup::new()
88            .with_name(name)
89            .with_description(description)
90            .with_id(id)
91            .with_streams(streams.as_ref());
92        let group_json = group.to_string();
93
94        assert_eq!(serde_json::to_string(&group).unwrap(), group_json);
95        assert_eq!(
96            serde_json::from_str::<DefaultChannelGroup>(&group_json).unwrap(),
97            group
98        );
99
100        assert_eq!(group.name(), Some(name));
101        assert_eq!(group.description(), Some(description));
102        assert_eq!(group.id(), Some(id));
103        assert_eq!(group.streams(), Some(streams.as_ref()));
104    }
105}