rtdlib/types/
chat_filter.rs1
2use crate::types::*;
3use crate::errors::*;
4use uuid::Uuid;
5
6
7
8
9#[derive(Debug, Clone, Default, Serialize, Deserialize)]
11pub struct ChatFilter {
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 title: String,
20 icon_name: String,
22 pinned_chat_ids: Vec<i64>,
24 included_chat_ids: Vec<i64>,
26 excluded_chat_ids: Vec<i64>,
28 exclude_muted: bool,
30 exclude_read: bool,
32 exclude_archived: bool,
34 include_contacts: bool,
36 include_non_contacts: bool,
38 include_bots: bool,
40 include_groups: bool,
42 include_channels: bool,
44
45}
46
47impl RObject for ChatFilter {
48 #[doc(hidden)] fn td_name(&self) -> &'static str { "chatFilter" }
49 #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
50 fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
51}
52
53
54
55impl ChatFilter {
56 pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
57 pub fn builder() -> RTDChatFilterBuilder {
58 let mut inner = ChatFilter::default();
59 inner.td_name = "chatFilter".to_string();
60 inner.extra = Some(Uuid::new_v4().to_string());
61 RTDChatFilterBuilder { inner }
62 }
63
64 pub fn title(&self) -> &String { &self.title }
65
66 pub fn icon_name(&self) -> &String { &self.icon_name }
67
68 pub fn pinned_chat_ids(&self) -> &Vec<i64> { &self.pinned_chat_ids }
69
70 pub fn included_chat_ids(&self) -> &Vec<i64> { &self.included_chat_ids }
71
72 pub fn excluded_chat_ids(&self) -> &Vec<i64> { &self.excluded_chat_ids }
73
74 pub fn exclude_muted(&self) -> bool { self.exclude_muted }
75
76 pub fn exclude_read(&self) -> bool { self.exclude_read }
77
78 pub fn exclude_archived(&self) -> bool { self.exclude_archived }
79
80 pub fn include_contacts(&self) -> bool { self.include_contacts }
81
82 pub fn include_non_contacts(&self) -> bool { self.include_non_contacts }
83
84 pub fn include_bots(&self) -> bool { self.include_bots }
85
86 pub fn include_groups(&self) -> bool { self.include_groups }
87
88 pub fn include_channels(&self) -> bool { self.include_channels }
89
90}
91
92#[doc(hidden)]
93pub struct RTDChatFilterBuilder {
94 inner: ChatFilter
95}
96
97impl RTDChatFilterBuilder {
98 pub fn build(&self) -> ChatFilter { self.inner.clone() }
99
100
101 pub fn title<T: AsRef<str>>(&mut self, title: T) -> &mut Self {
102 self.inner.title = title.as_ref().to_string();
103 self
104 }
105
106
107 pub fn icon_name<T: AsRef<str>>(&mut self, icon_name: T) -> &mut Self {
108 self.inner.icon_name = icon_name.as_ref().to_string();
109 self
110 }
111
112
113 pub fn pinned_chat_ids(&mut self, pinned_chat_ids: Vec<i64>) -> &mut Self {
114 self.inner.pinned_chat_ids = pinned_chat_ids;
115 self
116 }
117
118
119 pub fn included_chat_ids(&mut self, included_chat_ids: Vec<i64>) -> &mut Self {
120 self.inner.included_chat_ids = included_chat_ids;
121 self
122 }
123
124
125 pub fn excluded_chat_ids(&mut self, excluded_chat_ids: Vec<i64>) -> &mut Self {
126 self.inner.excluded_chat_ids = excluded_chat_ids;
127 self
128 }
129
130
131 pub fn exclude_muted(&mut self, exclude_muted: bool) -> &mut Self {
132 self.inner.exclude_muted = exclude_muted;
133 self
134 }
135
136
137 pub fn exclude_read(&mut self, exclude_read: bool) -> &mut Self {
138 self.inner.exclude_read = exclude_read;
139 self
140 }
141
142
143 pub fn exclude_archived(&mut self, exclude_archived: bool) -> &mut Self {
144 self.inner.exclude_archived = exclude_archived;
145 self
146 }
147
148
149 pub fn include_contacts(&mut self, include_contacts: bool) -> &mut Self {
150 self.inner.include_contacts = include_contacts;
151 self
152 }
153
154
155 pub fn include_non_contacts(&mut self, include_non_contacts: bool) -> &mut Self {
156 self.inner.include_non_contacts = include_non_contacts;
157 self
158 }
159
160
161 pub fn include_bots(&mut self, include_bots: bool) -> &mut Self {
162 self.inner.include_bots = include_bots;
163 self
164 }
165
166
167 pub fn include_groups(&mut self, include_groups: bool) -> &mut Self {
168 self.inner.include_groups = include_groups;
169 self
170 }
171
172
173 pub fn include_channels(&mut self, include_channels: bool) -> &mut Self {
174 self.inner.include_channels = include_channels;
175 self
176 }
177
178}
179
180impl AsRef<ChatFilter> for ChatFilter {
181 fn as_ref(&self) -> &ChatFilter { self }
182}
183
184impl AsRef<ChatFilter> for RTDChatFilterBuilder {
185 fn as_ref(&self) -> &ChatFilter { &self.inner }
186}
187
188
189