@@ -5,17 +5,19 @@ import 'package:flutter/foundation.dart';
5
5
class FieldPredicate <T > {
6
6
final String _operand;
7
7
String ? _value;
8
- List <String >? _values;
8
+ List <String ?>? _values;
9
+ bool _useValue;
9
10
10
- FieldPredicate .equals (T value) : _operand = '==' , _value = value.toString ();
11
- FieldPredicate .notEquals (T value) : _operand = '!=' , _value = value.toString ();
12
- FieldPredicate .oneOf (List <T > values) : _operand = 'oneOf' , _values = values.map ((value) => value.toString ()) .toList ();
13
- FieldPredicate .notOneOf (List <T > values) : _operand = '!oneOf' , _values = values.map ((value) => value.toString ()) .toList ();
11
+ FieldPredicate .equals (T value) : _operand = '==' , _value = ( value != null ? value .toString () : null ), _useValue = true ;
12
+ FieldPredicate .notEquals (T value) : _operand = '!=' , _value = ( value != null ? value .toString () : null ), _useValue = true ;
13
+ FieldPredicate .oneOf (List <T > values) : _operand = 'oneOf' , _values = values.map ((value) => ( value != null ? value .toString () : null )) .toList (), _useValue = false ;
14
+ FieldPredicate .notOneOf (List <T > values) : _operand = '!oneOf' , _values = values.map ((value) => ( value != null ? value .toString () : null )) .toList (), _useValue = false ;
14
15
15
16
FieldPredicate .of (FieldPredicate <T > other)
16
17
: _operand = other._operand,
17
18
_value = other._value,
18
- _values = (other._values != null ? List <String >.of (other._values! ) : null );
19
+ _values = (other._values != null ? List <String ?>.of (other._values! ) : null ),
20
+ _useValue = other._useValue;
19
21
20
22
@override
21
23
String toString () {
@@ -27,7 +29,7 @@ class FieldPredicate<T> {
27
29
28
30
result.add (_operand);
29
31
30
- if (_value != null ) {
32
+ if (_useValue ) {
31
33
result.add (_value);
32
34
}
33
35
@@ -59,13 +61,18 @@ class FieldPredicate<T> {
59
61
return false ;
60
62
}
61
63
64
+ if (_useValue != other._useValue) {
65
+ return false ;
66
+ }
67
+
62
68
return true ;
63
69
}
64
70
65
71
int get hashCode => Object .hash (
66
72
_operand,
67
73
_value,
68
74
(_values != null ? Object .hashAll (_values! ) : _values),
75
+ _useValue,
69
76
);
70
77
}
71
78
@@ -113,6 +120,10 @@ class CustomFieldPredicate extends FieldPredicate<String> {
113
120
return false ;
114
121
}
115
122
123
+ if (_useValue != other._useValue) {
124
+ return false ;
125
+ }
126
+
116
127
if (_exists != other._exists) {
117
128
return false ;
118
129
}
@@ -124,6 +135,7 @@ class CustomFieldPredicate extends FieldPredicate<String> {
124
135
_operand,
125
136
_value,
126
137
(_values != null ? Object .hashAll (_values! ) : _values),
138
+ _useValue,
127
139
_exists,
128
140
);
129
141
}
@@ -223,13 +235,17 @@ class ConversationPredicate {
223
235
/// Only select conversations that have the last message sent in a particular time interval.
224
236
final NumberPredicate ? lastMessageTs;
225
237
226
- const ConversationPredicate ({this .access, this .custom, this .hasUnreadMessages, this .lastMessageTs});
238
+ /// Only select conversations that have the subject set to particular values.
239
+ final FieldPredicate <String ?>? subject;
240
+
241
+ const ConversationPredicate ({this .access, this .custom, this .hasUnreadMessages, this .lastMessageTs, this .subject});
227
242
228
243
ConversationPredicate .of (ConversationPredicate other)
229
244
: access = (other.access != null ? FieldPredicate <ConversationAccessLevel >.of (other.access! ) : null ),
230
245
custom = (other.custom != null ? Map <String , CustomFieldPredicate >.of (other.custom! ) : null ),
231
246
hasUnreadMessages = other.hasUnreadMessages,
232
- lastMessageTs = (other.lastMessageTs != null ? NumberPredicate .of (other.lastMessageTs! ) : null );
247
+ lastMessageTs = (other.lastMessageTs != null ? NumberPredicate .of (other.lastMessageTs! ) : null ),
248
+ subject = (other.subject != null ? FieldPredicate <String ?>.of (other.subject! ) : null );
233
249
234
250
@override
235
251
String toString () {
@@ -255,6 +271,10 @@ class ConversationPredicate {
255
271
result['lastMessageTs' ] = lastMessageTs;
256
272
}
257
273
274
+ if (subject != null ) {
275
+ result['subject' ] = subject;
276
+ }
277
+
258
278
return result;
259
279
}
260
280
@@ -283,6 +303,10 @@ class ConversationPredicate {
283
303
return false ;
284
304
}
285
305
306
+ if (subject != other.subject) {
307
+ return false ;
308
+ }
309
+
286
310
return true ;
287
311
}
288
312
@@ -292,6 +316,7 @@ class ConversationPredicate {
292
316
(custom != null ? Object .hashAll (custom! .values) : custom),
293
317
hasUnreadMessages,
294
318
lastMessageTs,
319
+ subject,
295
320
);
296
321
}
297
322
0 commit comments