rust_tdlib/types/
search_messages.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Searches for messages in all chats except secret chats. Returns the results in reverse chronological order (i.e., in order of decreasing (date, chat_id, message_id)). For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct SearchMessages {
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    /// Chat list in which to search messages; pass null to search in all chats regardless of their chat list. Only Main and Archive chat lists are supported
14
15    #[serde(skip_serializing_if = "ChatList::_is_default")]
16    chat_list: ChatList,
17    /// Query to search for
18
19    #[serde(default)]
20    query: String,
21    /// The date of the message starting from which the results need to be fetched. Use 0 or any date in the future to get results from the last message
22
23    #[serde(default)]
24    offset_date: i32,
25    /// The chat identifier of the last found message, or 0 for the first request
26
27    #[serde(default)]
28    offset_chat_id: i64,
29    /// The message identifier of the last found message, or 0 for the first request
30
31    #[serde(default)]
32    offset_message_id: i64,
33    /// The maximum number of messages to be returned; up to 100. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
34
35    #[serde(default)]
36    limit: i32,
37    /// Additional filter for messages to search; pass null to search for all messages. Filters searchMessagesFilterMention, searchMessagesFilterUnreadMention, searchMessagesFilterFailedToSend and searchMessagesFilterPinned are unsupported in this function
38
39    #[serde(skip_serializing_if = "SearchMessagesFilter::_is_default")]
40    filter: SearchMessagesFilter,
41    /// If not 0, the minimum date of the messages to return
42
43    #[serde(default)]
44    min_date: i32,
45    /// If not 0, the maximum date of the messages to return
46
47    #[serde(default)]
48    max_date: i32,
49
50    #[serde(rename(serialize = "@type"))]
51    td_type: String,
52}
53
54impl RObject for SearchMessages {
55    #[doc(hidden)]
56    fn extra(&self) -> Option<&str> {
57        self.extra.as_deref()
58    }
59    #[doc(hidden)]
60    fn client_id(&self) -> Option<i32> {
61        self.client_id
62    }
63}
64
65impl RFunction for SearchMessages {}
66
67impl SearchMessages {
68    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
69        Ok(serde_json::from_str(json.as_ref())?)
70    }
71    pub fn builder() -> SearchMessagesBuilder {
72        let mut inner = SearchMessages::default();
73        inner.extra = Some(Uuid::new_v4().to_string());
74
75        inner.td_type = "searchMessages".to_string();
76
77        SearchMessagesBuilder { inner }
78    }
79
80    pub fn chat_list(&self) -> &ChatList {
81        &self.chat_list
82    }
83
84    pub fn query(&self) -> &String {
85        &self.query
86    }
87
88    pub fn offset_date(&self) -> i32 {
89        self.offset_date
90    }
91
92    pub fn offset_chat_id(&self) -> i64 {
93        self.offset_chat_id
94    }
95
96    pub fn offset_message_id(&self) -> i64 {
97        self.offset_message_id
98    }
99
100    pub fn limit(&self) -> i32 {
101        self.limit
102    }
103
104    pub fn filter(&self) -> &SearchMessagesFilter {
105        &self.filter
106    }
107
108    pub fn min_date(&self) -> i32 {
109        self.min_date
110    }
111
112    pub fn max_date(&self) -> i32 {
113        self.max_date
114    }
115}
116
117#[doc(hidden)]
118pub struct SearchMessagesBuilder {
119    inner: SearchMessages,
120}
121
122#[deprecated]
123pub type RTDSearchMessagesBuilder = SearchMessagesBuilder;
124
125impl SearchMessagesBuilder {
126    pub fn build(&self) -> SearchMessages {
127        self.inner.clone()
128    }
129
130    pub fn chat_list<T: AsRef<ChatList>>(&mut self, chat_list: T) -> &mut Self {
131        self.inner.chat_list = chat_list.as_ref().clone();
132        self
133    }
134
135    pub fn query<T: AsRef<str>>(&mut self, query: T) -> &mut Self {
136        self.inner.query = query.as_ref().to_string();
137        self
138    }
139
140    pub fn offset_date(&mut self, offset_date: i32) -> &mut Self {
141        self.inner.offset_date = offset_date;
142        self
143    }
144
145    pub fn offset_chat_id(&mut self, offset_chat_id: i64) -> &mut Self {
146        self.inner.offset_chat_id = offset_chat_id;
147        self
148    }
149
150    pub fn offset_message_id(&mut self, offset_message_id: i64) -> &mut Self {
151        self.inner.offset_message_id = offset_message_id;
152        self
153    }
154
155    pub fn limit(&mut self, limit: i32) -> &mut Self {
156        self.inner.limit = limit;
157        self
158    }
159
160    pub fn filter<T: AsRef<SearchMessagesFilter>>(&mut self, filter: T) -> &mut Self {
161        self.inner.filter = filter.as_ref().clone();
162        self
163    }
164
165    pub fn min_date(&mut self, min_date: i32) -> &mut Self {
166        self.inner.min_date = min_date;
167        self
168    }
169
170    pub fn max_date(&mut self, max_date: i32) -> &mut Self {
171        self.inner.max_date = max_date;
172        self
173    }
174}
175
176impl AsRef<SearchMessages> for SearchMessages {
177    fn as_ref(&self) -> &SearchMessages {
178        self
179    }
180}
181
182impl AsRef<SearchMessages> for SearchMessagesBuilder {
183    fn as_ref(&self) -> &SearchMessages {
184        &self.inner
185    }
186}