rtdlib/types/
message_copy_options.rs

1
2use crate::types::*;
3use crate::errors::*;
4use uuid::Uuid;
5
6
7
8
9/// Options to be used when a message content is copied without reference to the original sender. Service messages and messageInvoice can't be copied
10#[derive(Debug, Clone, Default, Serialize, Deserialize)]
11pub struct MessageCopyOptions {
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  /// True, if content of the message needs to be copied without reference to the original sender. Always true if the message is forwarded to a secret chat or is local
19  send_copy: bool,
20  /// True, if media caption of the message copy needs to be replaced. Ignored if send_copy is false
21  replace_caption: bool,
22  /// New message caption; pass null to copy message without caption. Ignored if replace_caption is false
23  new_caption: FormattedText,
24  
25}
26
27impl RObject for MessageCopyOptions {
28  #[doc(hidden)] fn td_name(&self) -> &'static str { "messageCopyOptions" }
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 MessageCopyOptions {
36  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
37  pub fn builder() -> RTDMessageCopyOptionsBuilder {
38    let mut inner = MessageCopyOptions::default();
39    inner.td_name = "messageCopyOptions".to_string();
40    inner.extra = Some(Uuid::new_v4().to_string());
41    RTDMessageCopyOptionsBuilder { inner }
42  }
43
44  pub fn send_copy(&self) -> bool { self.send_copy }
45
46  pub fn replace_caption(&self) -> bool { self.replace_caption }
47
48  pub fn new_caption(&self) -> &FormattedText { &self.new_caption }
49
50}
51
52#[doc(hidden)]
53pub struct RTDMessageCopyOptionsBuilder {
54  inner: MessageCopyOptions
55}
56
57impl RTDMessageCopyOptionsBuilder {
58  pub fn build(&self) -> MessageCopyOptions { self.inner.clone() }
59
60   
61  pub fn send_copy(&mut self, send_copy: bool) -> &mut Self {
62    self.inner.send_copy = send_copy;
63    self
64  }
65
66   
67  pub fn replace_caption(&mut self, replace_caption: bool) -> &mut Self {
68    self.inner.replace_caption = replace_caption;
69    self
70  }
71
72   
73  pub fn new_caption<T: AsRef<FormattedText>>(&mut self, new_caption: T) -> &mut Self {
74    self.inner.new_caption = new_caption.as_ref().clone();
75    self
76  }
77
78}
79
80impl AsRef<MessageCopyOptions> for MessageCopyOptions {
81  fn as_ref(&self) -> &MessageCopyOptions { self }
82}
83
84impl AsRef<MessageCopyOptions> for RTDMessageCopyOptionsBuilder {
85  fn as_ref(&self) -> &MessageCopyOptions { &self.inner }
86}
87
88
89