rust_tdlib/types/
chat_filter.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Represents a filter of user chats
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct ChatFilter {
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    /// The title of the filter; 1-12 characters without line feeds
14
15    #[serde(default)]
16    title: String,
17    /// The chosen icon name for short filter representation. If non-empty, must be one of "All", "Unread", "Unmuted", "Bots", "Channels", "Groups", "Private", "Custom", "Setup", "Cat", "Crown", "Favorite", "Flower", "Game", "Home", "Love", "Mask", "Party", "Sport", "Study", "Trade", "Travel", "Work". If empty, use getChatFilterDefaultIconName to get default icon name for the filter
18
19    #[serde(default)]
20    icon_name: String,
21    /// The chat identifiers of pinned chats in the filtered chat list
22
23    #[serde(default)]
24    pinned_chat_ids: Vec<i64>,
25    /// The chat identifiers of always included chats in the filtered chat list
26
27    #[serde(default)]
28    included_chat_ids: Vec<i64>,
29    /// The chat identifiers of always excluded chats in the filtered chat list
30
31    #[serde(default)]
32    excluded_chat_ids: Vec<i64>,
33    /// True, if muted chats need to be excluded
34
35    #[serde(default)]
36    exclude_muted: bool,
37    /// True, if read chats need to be excluded
38
39    #[serde(default)]
40    exclude_read: bool,
41    /// True, if archived chats need to be excluded
42
43    #[serde(default)]
44    exclude_archived: bool,
45    /// True, if contacts need to be included
46
47    #[serde(default)]
48    include_contacts: bool,
49    /// True, if non-contact users need to be included
50
51    #[serde(default)]
52    include_non_contacts: bool,
53    /// True, if bots need to be included
54
55    #[serde(default)]
56    include_bots: bool,
57    /// True, if basic groups and supergroups need to be included
58
59    #[serde(default)]
60    include_groups: bool,
61    /// True, if channels need to be included
62
63    #[serde(default)]
64    include_channels: bool,
65}
66
67impl RObject for ChatFilter {
68    #[doc(hidden)]
69    fn extra(&self) -> Option<&str> {
70        self.extra.as_deref()
71    }
72    #[doc(hidden)]
73    fn client_id(&self) -> Option<i32> {
74        self.client_id
75    }
76}
77
78impl ChatFilter {
79    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
80        Ok(serde_json::from_str(json.as_ref())?)
81    }
82    pub fn builder() -> ChatFilterBuilder {
83        let mut inner = ChatFilter::default();
84        inner.extra = Some(Uuid::new_v4().to_string());
85
86        ChatFilterBuilder { inner }
87    }
88
89    pub fn title(&self) -> &String {
90        &self.title
91    }
92
93    pub fn icon_name(&self) -> &String {
94        &self.icon_name
95    }
96
97    pub fn pinned_chat_ids(&self) -> &Vec<i64> {
98        &self.pinned_chat_ids
99    }
100
101    pub fn included_chat_ids(&self) -> &Vec<i64> {
102        &self.included_chat_ids
103    }
104
105    pub fn excluded_chat_ids(&self) -> &Vec<i64> {
106        &self.excluded_chat_ids
107    }
108
109    pub fn exclude_muted(&self) -> bool {
110        self.exclude_muted
111    }
112
113    pub fn exclude_read(&self) -> bool {
114        self.exclude_read
115    }
116
117    pub fn exclude_archived(&self) -> bool {
118        self.exclude_archived
119    }
120
121    pub fn include_contacts(&self) -> bool {
122        self.include_contacts
123    }
124
125    pub fn include_non_contacts(&self) -> bool {
126        self.include_non_contacts
127    }
128
129    pub fn include_bots(&self) -> bool {
130        self.include_bots
131    }
132
133    pub fn include_groups(&self) -> bool {
134        self.include_groups
135    }
136
137    pub fn include_channels(&self) -> bool {
138        self.include_channels
139    }
140}
141
142#[doc(hidden)]
143pub struct ChatFilterBuilder {
144    inner: ChatFilter,
145}
146
147#[deprecated]
148pub type RTDChatFilterBuilder = ChatFilterBuilder;
149
150impl ChatFilterBuilder {
151    pub fn build(&self) -> ChatFilter {
152        self.inner.clone()
153    }
154
155    pub fn title<T: AsRef<str>>(&mut self, title: T) -> &mut Self {
156        self.inner.title = title.as_ref().to_string();
157        self
158    }
159
160    pub fn icon_name<T: AsRef<str>>(&mut self, icon_name: T) -> &mut Self {
161        self.inner.icon_name = icon_name.as_ref().to_string();
162        self
163    }
164
165    pub fn pinned_chat_ids(&mut self, pinned_chat_ids: Vec<i64>) -> &mut Self {
166        self.inner.pinned_chat_ids = pinned_chat_ids;
167        self
168    }
169
170    pub fn included_chat_ids(&mut self, included_chat_ids: Vec<i64>) -> &mut Self {
171        self.inner.included_chat_ids = included_chat_ids;
172        self
173    }
174
175    pub fn excluded_chat_ids(&mut self, excluded_chat_ids: Vec<i64>) -> &mut Self {
176        self.inner.excluded_chat_ids = excluded_chat_ids;
177        self
178    }
179
180    pub fn exclude_muted(&mut self, exclude_muted: bool) -> &mut Self {
181        self.inner.exclude_muted = exclude_muted;
182        self
183    }
184
185    pub fn exclude_read(&mut self, exclude_read: bool) -> &mut Self {
186        self.inner.exclude_read = exclude_read;
187        self
188    }
189
190    pub fn exclude_archived(&mut self, exclude_archived: bool) -> &mut Self {
191        self.inner.exclude_archived = exclude_archived;
192        self
193    }
194
195    pub fn include_contacts(&mut self, include_contacts: bool) -> &mut Self {
196        self.inner.include_contacts = include_contacts;
197        self
198    }
199
200    pub fn include_non_contacts(&mut self, include_non_contacts: bool) -> &mut Self {
201        self.inner.include_non_contacts = include_non_contacts;
202        self
203    }
204
205    pub fn include_bots(&mut self, include_bots: bool) -> &mut Self {
206        self.inner.include_bots = include_bots;
207        self
208    }
209
210    pub fn include_groups(&mut self, include_groups: bool) -> &mut Self {
211        self.inner.include_groups = include_groups;
212        self
213    }
214
215    pub fn include_channels(&mut self, include_channels: bool) -> &mut Self {
216        self.inner.include_channels = include_channels;
217        self
218    }
219}
220
221impl AsRef<ChatFilter> for ChatFilter {
222    fn as_ref(&self) -> &ChatFilter {
223        self
224    }
225}
226
227impl AsRef<ChatFilter> for ChatFilterBuilder {
228    fn as_ref(&self) -> &ChatFilter {
229        &self.inner
230    }
231}