zulip_api/message/scheduled_message.rs
1use serde::{Deserialize, Serialize};
2
3use crate::{field_access, impl_default, impl_display};
4
5/// Represents a scheduled message.
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 ScheduledMessage {
30 #[serde(skip_serializing_if = "Option::is_none")]
31 scheduled_message_id: Option<u64>,
32 #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
33 scheduled_message_type: Option<ScheduledMessageType>,
34 #[serde(skip_serializing_if = "Option::is_none")]
35 to: Option<ScheduledMessageTo>,
36 #[serde(skip_serializing_if = "Option::is_none")]
37 topic: Option<String>,
38 #[serde(skip_serializing_if = "Option::is_none")]
39 content: Option<String>,
40 #[serde(skip_serializing_if = "Option::is_none")]
41 rendered_content: Option<String>,
42 #[serde(skip_serializing_if = "Option::is_none")]
43 scheduled_delivery_timestamp: Option<u64>,
44 #[serde(skip_serializing_if = "Option::is_none")]
45 failed: Option<bool>,
46}
47
48impl ScheduledMessage {
49 /// Creates a new [ScheduledMessage].
50 pub const fn new() -> Self {
51 ScheduledMessage {
52 scheduled_message_id: None,
53 scheduled_message_type: None,
54 to: None,
55 topic: None,
56 content: None,
57 rendered_content: None,
58 scheduled_delivery_timestamp: None,
59 failed: None,
60 }
61 }
62}
63
64field_access! {
65 ScheduledMessage {
66 scheduled_message_id: option { u64 },
67 scheduled_message_type: option { ScheduledMessageType },
68 scheduled_delivery_timestamp: option { u64 },
69 failed: option { bool },
70 }
71}
72
73field_access! {
74 ScheduledMessage {
75 to: option_ref { ScheduledMessageTo },
76 }
77}
78
79field_access! {
80 ScheduledMessage {
81 topic: option_cow_deref { str, String },
82 content: option_cow_deref { str, String },
83 rendered_content: option_cow_deref { str, String },
84 }
85}
86
87impl_default!(ScheduledMessage);
88impl_display!(ScheduledMessage);
89
90/// Represents the [ScheduledMessage] type.
91///
92/// Modified from `openapi-generator-cli` output:
93///
94/// ```shell,no_build,no_run
95/// $ openapi-generator-cli generate -g rust -i ./zerver/openapi/zulip.yaml -o zulip-openapi --skip-validate-spec
96/// ```
97///
98/// ```text
99/// /*
100/// * Zulip REST API
101/// *
102/// * Powerful open source group chat
103/// *
104/// * The version of the OpenAPI document: 1.0.0
105/// *
106/// * Generated by: https://openapi-generator.tech
107/// */
108/// ```
109///
110/// See [zerver/openapi/zulip.yaml](https://github.com/zulip/zulip/blob/main/zerver/openapi/zulip.yaml) for the original OpenAPI configuration.
111///
112/// Configuration slightly modified to work with the Rust generator of [`openapi-generator-cli`](https://openapi-generator.tech).
113#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
114#[serde(rename_all = "snake_case")]
115pub enum ScheduledMessageType {
116 Stream,
117 Private,
118}
119
120impl ScheduledMessageType {
121 /// Creates a new [ScheduledMessageType].
122 pub const fn new() -> Self {
123 Self::Stream
124 }
125}
126
127impl_default!(ScheduledMessageType);
128impl_display!(ScheduledMessageType);
129
130/// Represents the scheduled message's tentative target audience.
131///
132/// - For channel messages, it will be the unique ID of the target channel.
133/// - For direct messages, it will be an array with the target users' IDs.
134///
135/// Modified from `openapi-generator-cli` output:
136///
137/// ```shell,no_build,no_run
138/// $ openapi-generator-cli generate -g rust -i ./zerver/openapi/zulip.yaml -o zulip-openapi --skip-validate-spec
139/// ```
140///
141/// ```text
142/// /*
143/// * Zulip REST API
144/// *
145/// * Powerful open source group chat
146/// *
147/// * The version of the OpenAPI document: 1.0.0
148/// *
149/// * Generated by: https://openapi-generator.tech
150/// */
151/// ```
152///
153/// See [zerver/openapi/zulip.yaml](https://github.com/zulip/zulip/blob/main/zerver/openapi/zulip.yaml) for the original OpenAPI configuration.
154///
155/// Configuration slightly modified to work with the Rust generator of [`openapi-generator-cli`](https://openapi-generator.tech).
156#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
157#[serde(untagged)]
158pub enum ScheduledMessageTo {
159 ChannelId(u64),
160 UserIds(Vec<u64>),
161}
162
163impl ScheduledMessageTo {
164 /// Creates a new [ScheduledMessageTo].
165 pub const fn new() -> Self {
166 Self::ChannelId(0)
167 }
168}
169
170impl_default!(ScheduledMessageTo);
171impl_display!(ScheduledMessageTo);