diff --git a/docusaurus/docs/Flutter/guides/understanding_filters.mdx b/docusaurus/docs/Flutter/guides/understanding_filters.mdx index e9d72ecf..292afd07 100644 --- a/docusaurus/docs/Flutter/guides/understanding_filters.mdx +++ b/docusaurus/docs/Flutter/guides/understanding_filters.mdx @@ -104,7 +104,16 @@ Filter.autoComplete('name', 'demo') The 'exists' filter matches values that exist, or don't exist, based on the specified boolean value. ```dart -Filter.exists('name', true) +Filter.exists('name') +``` + +#### Filter.notExists + +The 'notExists' filter checks if the specified key doesn't exist. This is a simplified call to `Filter.exists` +with the value set to false. + +```dart +Filter.notExists('name') ``` #### Filter.contains diff --git a/packages/stream_chat/CHANGELOG.md b/packages/stream_chat/CHANGELOG.md index fbac9f87..07c926c2 100644 --- a/packages/stream_chat/CHANGELOG.md +++ b/packages/stream_chat/CHANGELOG.md @@ -1,5 +1,9 @@ ## Upcoming +✅ Added + +- Added `Filter.notExists`. + 🐞 Fixed - [[#710]](https://github.com/GetStream/stream-chat-flutter/issues/710) Fixed JWT requiring using `String` as id. diff --git a/packages/stream_chat/lib/src/core/models/filter.dart b/packages/stream_chat/lib/src/core/models/filter.dart index ca494bdb..108efcb2 100644 --- a/packages/stream_chat/lib/src/core/models/filter.dart +++ b/packages/stream_chat/lib/src/core/models/filter.dart @@ -167,6 +167,9 @@ class Filter extends Equatable { factory Filter.exists(String key, {bool exists = true}) => Filter._(operator: FilterOperator.exists, key: key, value: exists); + /// Matches values that don't exist. + factory Filter.notExists(String key) => Filter.exists(key, exists: false); + /// Matches any list that contains the specified values factory Filter.contains(String key, Object value) => Filter._(operator: FilterOperator.contains, key: key, value: value); diff --git a/packages/stream_chat/test/src/core/models/filter_test.dart b/packages/stream_chat/test/src/core/models/filter_test.dart index c0a8ce8f..f836d845 100644 --- a/packages/stream_chat/test/src/core/models/filter_test.dart +++ b/packages/stream_chat/test/src/core/models/filter_test.dart @@ -114,7 +114,7 @@ void main() { test('notExists', () { const key = 'testKey'; - final filter = Filter.exists(key, exists: false); + final filter = Filter.notExists(key); expect(filter.key, key); expect(filter.value, isFalse); expect(filter.operator, FilterOperator.exists.rawValue);