1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
use crate::{message::{
signalproxy::translation::{Network, NetworkMap, NetworkList},
Syncable, Class,
}, primitive::Variant};
use libquassel_derive::{sync, NetworkList, NetworkMap};
#[derive(Default, Debug, Clone, PartialEq, NetworkList, NetworkMap)]
pub struct IgnoreListManager {
#[quassel(name = "IgnoreList")]
#[network(variant = "VariantMap", network, map)]
pub ignore_list: Vec<IgnoreListItem>,
}
impl IgnoreListManager {
/// Get a reference to a specific ignore list by ID.
pub fn ignore_list_item(&self, rule: &str) -> Option<&IgnoreListItem> {
if let Some(position) = self
.ignore_list
.iter()
.position(|item| item.ignore_rule.as_str() == rule)
{
self.ignore_list.get(position)
} else {
None
}
}
/// Get a mutable reference to a specific highlight rule by ID.
pub fn ignore_list_item_mut(&mut self, rule: &str) -> Option<&mut IgnoreListItem> {
if let Some(position) = self
.ignore_list
.iter()
.position(|item| item.ignore_rule.as_str() == rule)
{
self.ignore_list.get_mut(position)
} else {
None
}
}
pub fn request_add_ignore_list_item(
&self,
IgnoreListItem {
ignore_type,
ignore_rule,
is_regex,
strictness,
scope,
scope_rule,
is_active,
}: IgnoreListItem,
) {
sync!(
"requestAddIgnoreListItem",
[
ignore_type,
ignore_rule,
is_regex,
strictness,
scope,
scope_rule,
is_active
]
)
}
pub fn request_remove_ignore_list_item(&self, rule: String) {
sync!("requestRemoveIgnoreListItem", [rule])
}
pub fn request_toggle_ignore_rule(&self, rule: String) {
sync!("requestToggleIgnoreRule", [rule])
}
pub fn add_ignore_list_item(&mut self, item: IgnoreListItem) {
#[cfg(feature = "server")]
sync!(
"addIgnoreListItem",
[
item.ignore_type,
item.ignore_rule.clone(),
item.is_regex,
item.strictness,
item.scope,
item.scope_rule.clone(),
item.is_active
]
);
if self.ignore_list_item(&item.ignore_rule).is_none() {
self.ignore_list.push(item)
};
}
pub fn remove_ignore_list_item(&mut self, rule: &str) {
if let Some(position) = self
.ignore_list
.iter()
.position(|item| item.ignore_rule.as_str() == rule)
{
self.ignore_list.remove(position);
};
#[cfg(feature = "server")]
sync!("removeIgnoreListItem", [rule])
}
pub fn toggle_ignore_rule(&mut self, rule: &str) {
if let Some(item) = self.ignore_list_item_mut(rule) {
item.is_active = !item.is_active
}
#[cfg(feature = "server")]
sync!("toggleIgnoreRule", [rule])
}
}
#[cfg(feature = "client")]
impl crate::message::StatefulSyncableClient for IgnoreListManager {
fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
where
Self: Sized,
{
match msg.slot_name.as_str() {
"addIgnoreListItem" => self.add_ignore_list_item(IgnoreListItem {
ignore_type: get_param!(msg),
ignore_rule: get_param!(msg),
is_regex: get_param!(msg),
strictness: get_param!(msg),
scope: get_param!(msg),
scope_rule: get_param!(msg),
is_active: get_param!(msg),
}),
"removeIgnoreListItem" => {
let rule: String = get_param!(msg);
self.remove_ignore_list_item(&rule);
}
"toggleIgnoreRule" => {
let rule: String = get_param!(msg);
self.toggle_ignore_rule(&rule);
}
_ => (),
}
}
}
#[cfg(feature = "server")]
impl crate::message::StatefulSyncableServer for IgnoreListManager {
fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
where
Self: Sized,
{
match msg.slot_name.as_str() {
"requestAddIgnoreListItem" => self.add_ignore_list_item(IgnoreListItem {
ignore_type: get_param!(msg),
ignore_rule: get_param!(msg),
is_regex: get_param!(msg),
strictness: get_param!(msg),
scope: get_param!(msg),
scope_rule: get_param!(msg),
is_active: get_param!(msg),
}),
"requestRemoveIgnoreListItem" => {
let rule: String = get_param!(msg);
self.remove_ignore_list_item(&rule);
}
"requestToggleIgnoreRule" => {
let rule: String = get_param!(msg);
self.toggle_ignore_rule(&rule);
}
_ => (),
}
}
}
impl Syncable for IgnoreListManager {
const CLASS: Class = Class::IgnoreListManager;
}
#[derive(Debug, Clone, PartialEq, NetworkMap)]
#[network(repr = "maplist")]
pub struct IgnoreListItem {
#[network(rename = "ignoreType", type = "i32")]
pub ignore_type: IgnoreType,
#[network(rename = "ignoreRule", variant = "StringList")]
pub ignore_rule: String,
#[network(rename = "isRegEx")]
pub is_regex: bool,
#[network(rename = "strictness", type = "i32")]
pub strictness: StrictnessType,
#[network(rename = "scope", type = "i32")]
pub scope: ScopeType,
#[network(rename = "scopeRule", variant = "StringList")]
pub scope_rule: String,
#[network(rename = "isActive")]
pub is_active: bool,
}
/////////////////////////////////////
//////////////////////////////////////
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum IgnoreType {
SenderIgnore = 0x00,
MessageIgnore = 0x01,
CtcpIgnore = 0x02,
}
impl From<IgnoreType> for Variant {
fn from(value: IgnoreType) -> Self {
Variant::i32(value as i32)
}
}
impl From<Variant> for IgnoreType {
fn from(value: Variant) -> Self {
IgnoreType::try_from(value).unwrap()
}
}
impl From<IgnoreType> for i32 {
fn from(value: IgnoreType) -> Self {
value as i32
}
}
impl TryFrom<i32> for IgnoreType {
type Error = &'static str;
fn try_from(value: i32) -> Result<Self, Self::Error> {
match value {
0x00 => Ok(IgnoreType::SenderIgnore),
0x01 => Ok(IgnoreType::MessageIgnore),
0x02 => Ok(IgnoreType::CtcpIgnore),
_ => Err("no matching IgnoreType found"),
}
}
}
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum StrictnessType {
UnmatchedStrictness = 0x00,
SoftStrictness = 0x01,
HardStrictness = 0x02,
}
impl From<StrictnessType> for Variant {
fn from(value: StrictnessType) -> Self {
Variant::i32(value as i32)
}
}
impl From<Variant> for StrictnessType {
fn from(value: Variant) -> Self {
StrictnessType::try_from(value).unwrap()
}
}
impl From<StrictnessType> for i32 {
fn from(value: StrictnessType) -> Self {
value as i32
}
}
impl TryFrom<i32> for StrictnessType {
type Error = &'static str;
fn try_from(value: i32) -> Result<Self, Self::Error> {
match value {
0x00 => Ok(StrictnessType::UnmatchedStrictness),
0x01 => Ok(StrictnessType::SoftStrictness),
0x02 => Ok(StrictnessType::HardStrictness),
_ => Err("no matching StrictnessType found"),
}
}
}
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ScopeType {
GlobalScope = 0x00,
NetworkScope = 0x01,
ChannelScope = 0x02,
}
impl From<ScopeType> for Variant {
fn from(value: ScopeType) -> Self {
Variant::i32(value as i32)
}
}
impl From<Variant> for ScopeType {
fn from(value: Variant) -> Self {
ScopeType::try_from(value).unwrap()
}
}
impl From<ScopeType> for i32 {
fn from(value: ScopeType) -> Self {
value as i32
}
}
impl TryFrom<i32> for ScopeType {
type Error = &'static str;
fn try_from(value: i32) -> Result<Self, Self::Error> {
match value {
0x00 => Ok(ScopeType::GlobalScope),
0x01 => Ok(ScopeType::NetworkScope),
0x02 => Ok(ScopeType::ChannelScope),
_ => Err("no matching ScopeType found"),
}
}
}
|