rtdlib/types/
message_send_options.rs

1
2use crate::types::*;
3use crate::errors::*;
4use uuid::Uuid;
5
6
7
8
9/// Options to be used when a message is sent
10#[derive(Debug, Clone, Default, Serialize, Deserialize)]
11pub struct MessageSendOptions {
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  /// Pass true to disable notification for the message
19  disable_notification: bool,
20  /// Pass true if the message is sent from the background
21  from_background: bool,
22  /// Message scheduling state; pass null to send message immediately. Messages sent to a secret chat, live location messages and self-destructing messages can't be scheduled
23  scheduling_state: MessageSchedulingState,
24  
25}
26
27impl RObject for MessageSendOptions {
28  #[doc(hidden)] fn td_name(&self) -> &'static str { "messageSendOptions" }
29  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
30  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
31}
32
33
34
35impl MessageSendOptions {
36  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
37  pub fn builder() -> RTDMessageSendOptionsBuilder {
38    let mut inner = MessageSendOptions::default();
39    inner.td_name = "messageSendOptions".to_string();
40    inner.extra = Some(Uuid::new_v4().to_string());
41    RTDMessageSendOptionsBuilder { inner }
42  }
43
44  pub fn disable_notification(&self) -> bool { self.disable_notification }
45
46  pub fn from_background(&self) -> bool { self.from_background }
47
48  pub fn scheduling_state(&self) -> &MessageSchedulingState { &self.scheduling_state }
49
50}
51
52#[doc(hidden)]
53pub struct RTDMessageSendOptionsBuilder {
54  inner: MessageSendOptions
55}
56
57impl RTDMessageSendOptionsBuilder {
58  pub fn build(&self) -> MessageSendOptions { self.inner.clone() }
59
60   
61  pub fn disable_notification(&mut self, disable_notification: bool) -> &mut Self {
62    self.inner.disable_notification = disable_notification;
63    self
64  }
65
66   
67  pub fn from_background(&mut self, from_background: bool) -> &mut Self {
68    self.inner.from_background = from_background;
69    self
70  }
71
72   
73  pub fn scheduling_state<T: AsRef<MessageSchedulingState>>(&mut self, scheduling_state: T) -> &mut Self {
74    self.inner.scheduling_state = scheduling_state.as_ref().clone();
75    self
76  }
77
78}
79
80impl AsRef<MessageSendOptions> for MessageSendOptions {
81  fn as_ref(&self) -> &MessageSendOptions { self }
82}
83
84impl AsRef<MessageSendOptions> for RTDMessageSendOptionsBuilder {
85  fn as_ref(&self) -> &MessageSendOptions { &self.inner }
86}
87
88
89