rtdlib/types/
chat_notification_settings.rs

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