|
5 | 5 | import Foundation
|
6 | 6 |
|
7 | 7 | extension Filter {
|
8 |
| - /// If a valueMapper was provided, then here we will try to transform the value |
9 |
| - /// using the mapper. |
10 |
| - /// |
11 |
| - /// If the mapper returns nil, the original value will be returned |
12 |
| - var mappedValue: FilterValue { |
13 |
| - valueMapper?(value) ?? value |
14 |
| - } |
15 |
| - |
16 |
| - /// If the mappedValues is an array of FilterValues, we will try to transform them using the valueMapper |
17 |
| - /// to ensure that both parts of the comparison are of the same type. |
18 |
| - /// |
19 |
| - /// If the value is not an array, this value will return nil. |
20 |
| - /// If the valueMapper isn't provided or the value mapper returns nil, the original value will be included |
21 |
| - /// in the array. |
22 |
| - var mappedArrayValue: [FilterValue]? { |
23 |
| - guard let filterArray = mappedValue as? [FilterValue] else { |
24 |
| - return nil |
25 |
| - } |
26 |
| - return filterArray.map { valueMapper?($0) ?? $0 } |
27 |
| - } |
28 |
| - |
29 |
| - /// If it can be translated, this will return |
30 |
| - /// an NSPredicate instance that is equivalent |
31 |
| - /// to the current filter. |
32 |
| - /// |
33 |
| - /// For now it's limited to ChannelList as it's not |
34 |
| - /// needed anywhere else |
| 8 | + /// Converts the current filter into an NSPredicate if it can be translated. |
35 | 9 | ///
|
36 |
| - /// The predicate will be automatically be used |
37 |
| - /// by the ChannelDTO to create the |
38 |
| - /// fetchRequest. |
| 10 | + /// This is useful to make sure the backend filters can be used to filter data in CoreData. |
39 | 11 | ///
|
40 |
| - /// - Important: |
41 |
| - /// The behaviour of the ChannelDTO, to include or not |
42 |
| - /// the predicate in the fetchRequest, it's controlled by |
43 |
| - /// `ChatClientConfig.isChannelAutomaticFilteringEnabled` |
| 12 | + /// **Note:** Extra data properties will be ignored since they are stored in binary format. |
44 | 13 | var predicate: NSPredicate? {
|
45 | 14 | guard let op = FilterOperator(rawValue: `operator`) else {
|
46 | 15 | return nil
|
@@ -234,6 +203,27 @@ extension Filter {
|
234 | 203 | return nil
|
235 | 204 | }
|
236 | 205 | }
|
| 206 | + |
| 207 | + /// If a valueMapper was provided, then here we will try to transform the value |
| 208 | + /// using the mapper. |
| 209 | + /// |
| 210 | + /// If the mapper returns nil, the original value will be returned |
| 211 | + var mappedValue: FilterValue { |
| 212 | + valueMapper?(value) ?? value |
| 213 | + } |
| 214 | + |
| 215 | + /// If the mappedValues is an array of FilterValues, we will try to transform them using the valueMapper |
| 216 | + /// to ensure that both parts of the comparison are of the same type. |
| 217 | + /// |
| 218 | + /// If the value is not an array, this value will return nil. |
| 219 | + /// If the valueMapper isn't provided or the value mapper returns nil, the original value will be included |
| 220 | + /// in the array. |
| 221 | + var mappedArrayValue: [FilterValue]? { |
| 222 | + guard let filterArray = mappedValue as? [FilterValue] else { |
| 223 | + return nil |
| 224 | + } |
| 225 | + return filterArray.map { valueMapper?($0) ?? $0 } |
| 226 | + } |
237 | 227 | }
|
238 | 228 |
|
239 | 229 | extension String {
|
|
0 commit comments