rust_tdlib/types/
chat_notification_settings.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Contains information about notification settings for a chat
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct ChatNotificationSettings {
8    #[doc(hidden)]
9    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
10    extra: Option<String>,
11    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
12    client_id: Option<i32>,
13    /// If true, mute_for is ignored and the value for the relevant type of chat is used instead
14
15    #[serde(default)]
16    use_default_mute_for: bool,
17    /// Time left before notifications will be unmuted, in seconds
18
19    #[serde(default)]
20    mute_for: i32,
21    /// If true, sound is ignored and the value for the relevant type of chat is used instead
22
23    #[serde(default)]
24    use_default_sound: bool,
25    /// The name of an audio file to be used for notification sounds; only applies to iOS applications
26
27    #[serde(default)]
28    sound: String,
29    /// If true, show_preview is ignored and the value for the relevant type of chat is used instead
30
31    #[serde(default)]
32    use_default_show_preview: bool,
33    /// True, if message content must be displayed in notifications
34
35    #[serde(default)]
36    show_preview: bool,
37    /// If true, disable_pinned_message_notifications is ignored and the value for the relevant type of chat is used instead
38
39    #[serde(default)]
40    use_default_disable_pinned_message_notifications: bool,
41    /// If true, notifications for incoming pinned messages will be created as for an ordinary unread message
42
43    #[serde(default)]
44    disable_pinned_message_notifications: bool,
45    /// If true, disable_mention_notifications is ignored and the value for the relevant type of chat is used instead
46
47    #[serde(default)]
48    use_default_disable_mention_notifications: bool,
49    /// If true, notifications for messages with mentions will be created as for an ordinary unread message
50
51    #[serde(default)]
52    disable_mention_notifications: bool,
53}
54
55impl RObject for ChatNotificationSettings {
56    #[doc(hidden)]
57    fn extra(&self) -> Option<&str> {
58        self.extra.as_deref()
59    }
60    #[doc(hidden)]
61    fn client_id(&self) -> Option<i32> {
62        self.client_id
63    }
64}
65
66impl ChatNotificationSettings {
67    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
68        Ok(serde_json::from_str(json.as_ref())?)
69    }
70    pub fn builder() -> ChatNotificationSettingsBuilder {
71        let mut inner = ChatNotificationSettings::default();
72        inner.extra = Some(Uuid::new_v4().to_string());
73
74        ChatNotificationSettingsBuilder { inner }
75    }
76
77    pub fn use_default_mute_for(&self) -> bool {
78        self.use_default_mute_for
79    }
80
81    pub fn mute_for(&self) -> i32 {
82        self.mute_for
83    }
84
85    pub fn use_default_sound(&self) -> bool {
86        self.use_default_sound
87    }
88
89    pub fn sound(&self) -> &String {
90        &self.sound
91    }
92
93    pub fn use_default_show_preview(&self) -> bool {
94        self.use_default_show_preview
95    }
96
97    pub fn show_preview(&self) -> bool {
98        self.show_preview
99    }
100
101    pub fn use_default_disable_pinned_message_notifications(&self) -> bool {
102        self.use_default_disable_pinned_message_notifications
103    }
104
105    pub fn disable_pinned_message_notifications(&self) -> bool {
106        self.disable_pinned_message_notifications
107    }
108
109    pub fn use_default_disable_mention_notifications(&self) -> bool {
110        self.use_default_disable_mention_notifications
111    }
112
113    pub fn disable_mention_notifications(&self) -> bool {
114        self.disable_mention_notifications
115    }
116}
117
118#[doc(hidden)]
119pub struct ChatNotificationSettingsBuilder {
120    inner: ChatNotificationSettings,
121}
122
123#[deprecated]
124pub type RTDChatNotificationSettingsBuilder = ChatNotificationSettingsBuilder;
125
126impl ChatNotificationSettingsBuilder {
127    pub fn build(&self) -> ChatNotificationSettings {
128        self.inner.clone()
129    }
130
131    pub fn use_default_mute_for(&mut self, use_default_mute_for: bool) -> &mut Self {
132        self.inner.use_default_mute_for = use_default_mute_for;
133        self
134    }
135
136    pub fn mute_for(&mut self, mute_for: i32) -> &mut Self {
137        self.inner.mute_for = mute_for;
138        self
139    }
140
141    pub fn use_default_sound(&mut self, use_default_sound: bool) -> &mut Self {
142        self.inner.use_default_sound = use_default_sound;
143        self
144    }
145
146    pub fn sound<T: AsRef<str>>(&mut self, sound: T) -> &mut Self {
147        self.inner.sound = sound.as_ref().to_string();
148        self
149    }
150
151    pub fn use_default_show_preview(&mut self, use_default_show_preview: bool) -> &mut Self {
152        self.inner.use_default_show_preview = use_default_show_preview;
153        self
154    }
155
156    pub fn show_preview(&mut self, show_preview: bool) -> &mut Self {
157        self.inner.show_preview = show_preview;
158        self
159    }
160
161    pub fn use_default_disable_pinned_message_notifications(
162        &mut self,
163        use_default_disable_pinned_message_notifications: bool,
164    ) -> &mut Self {
165        self.inner.use_default_disable_pinned_message_notifications =
166            use_default_disable_pinned_message_notifications;
167        self
168    }
169
170    pub fn disable_pinned_message_notifications(
171        &mut self,
172        disable_pinned_message_notifications: bool,
173    ) -> &mut Self {
174        self.inner.disable_pinned_message_notifications = disable_pinned_message_notifications;
175        self
176    }
177
178    pub fn use_default_disable_mention_notifications(
179        &mut self,
180        use_default_disable_mention_notifications: bool,
181    ) -> &mut Self {
182        self.inner.use_default_disable_mention_notifications =
183            use_default_disable_mention_notifications;
184        self
185    }
186
187    pub fn disable_mention_notifications(
188        &mut self,
189        disable_mention_notifications: bool,
190    ) -> &mut Self {
191        self.inner.disable_mention_notifications = disable_mention_notifications;
192        self
193    }
194}
195
196impl AsRef<ChatNotificationSettings> for ChatNotificationSettings {
197    fn as_ref(&self) -> &ChatNotificationSettings {
198        self
199    }
200}
201
202impl AsRef<ChatNotificationSettings> for ChatNotificationSettingsBuilder {
203    fn as_ref(&self) -> &ChatNotificationSettings {
204        &self.inner
205    }
206}