Skip to content

Commit 2eb3158

Browse files
authored
feat(llc, persistence): add support for filter_tags in channel (#2461)
1 parent 52f1ea2 commit 2eb3158

File tree

13 files changed

+179
-3
lines changed

13 files changed

+179
-3
lines changed

packages/stream_chat/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
✅ Added
44

5+
- Added support for `filterTags` in channels.
56
- Added support for `Channel.markUnreadByTimestamp` and `Client.markChannelUnreadByTimestamp`
67
methods to mark all messages after a given timestamp as unread.
78
- Added support for `hideHistoryBefore` in `Channel.addMembers` and `Client.addChannelMembers` to

packages/stream_chat/lib/src/client/channel.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,14 @@ class Channel {
432432
return state!.channelStateStream.map((cs) => cs.channel?.messageCount);
433433
}
434434

435+
/// List of filter tags applied to this channel.
436+
///
437+
/// Generally used for filtering channels while querying.
438+
List<String>? get filterTags {
439+
_checkInitialized();
440+
return state!._channelState.channel?.filterTags;
441+
}
442+
435443
/// Channel id.
436444
String? get id => state?._channelState.channel?.id ?? _id;
437445

packages/stream_chat/lib/src/core/models/channel_model.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class ChannelModel {
3232
bool? hidden,
3333
DateTime? truncatedAt,
3434
this.messageCount,
35+
this.filterTags,
3536
}) : assert(
3637
(cid != null && cid.contains(':')) || (id != null && type != null),
3738
'provide either a cid or an id and type',
@@ -159,6 +160,12 @@ class ChannelModel {
159160
@JsonKey(includeToJson: false)
160161
final int? messageCount;
161162

163+
/// List of filter tags applied to the channel.
164+
///
165+
/// This is generally used for querying filtered channels based on tags.
166+
@JsonKey(includeToJson: false)
167+
final List<String>? filterTags;
168+
162169
/// Known top level fields.
163170
/// Useful for [Serializer] methods.
164171
static const topLevelFields = [
@@ -178,6 +185,7 @@ class ChannelModel {
178185
'team',
179186
'cooldown',
180187
'message_count',
188+
'filter_tags',
181189
];
182190

183191
/// Serialize to json
@@ -207,6 +215,7 @@ class ChannelModel {
207215
bool? hidden,
208216
DateTime? truncatedAt,
209217
int? messageCount,
218+
List<String>? filterTags,
210219
}) =>
211220
ChannelModel(
212221
id: id ?? this.id,
@@ -234,6 +243,7 @@ class ChannelModel {
234243
: DateTime.parse(extraData?['truncated_at'] as String)) ??
235244
this.truncatedAt,
236245
messageCount: messageCount ?? this.messageCount,
246+
filterTags: filterTags ?? this.filterTags,
237247
);
238248

239249
/// Returns a new [ChannelModel] that is a combination of this channelModel
@@ -261,6 +271,7 @@ class ChannelModel {
261271
hidden: other.hidden,
262272
truncatedAt: other.truncatedAt,
263273
messageCount: other.messageCount,
274+
filterTags: other.filterTags,
264275
);
265276
}
266277
}

packages/stream_chat/lib/src/core/models/channel_model.g.dart

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/stream_chat/test/src/client/channel_test.dart

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6357,6 +6357,71 @@ void main() {
63576357
});
63586358
});
63596359

6360+
group('Channel filterTags', () {
6361+
late final client = MockStreamChatClient();
6362+
const channelId = 'test-channel-id';
6363+
const channelType = 'test-channel-type';
6364+
6365+
setUpAll(() {
6366+
// detached loggers
6367+
when(() => client.detachedLogger(any())).thenAnswer((invocation) {
6368+
final name = invocation.positionalArguments.first;
6369+
return _createLogger(name);
6370+
});
6371+
6372+
final retryPolicy = RetryPolicy(
6373+
shouldRetry: (_, __, ___) => false,
6374+
delayFactor: Duration.zero,
6375+
);
6376+
when(() => client.retryPolicy).thenReturn(retryPolicy);
6377+
6378+
// fake clientState
6379+
final clientState = FakeClientState();
6380+
when(() => client.state).thenReturn(clientState);
6381+
6382+
// client logger
6383+
when(() => client.logger).thenReturn(_createLogger('mock-client-logger'));
6384+
});
6385+
6386+
test('should return filterTags from channel state', () {
6387+
final channelModel = ChannelModel(
6388+
id: channelId,
6389+
type: channelType,
6390+
filterTags: ['tag1', 'tag2'],
6391+
);
6392+
6393+
final channelState = ChannelState(channel: channelModel);
6394+
final testChannel = Channel.fromState(client, channelState);
6395+
addTearDown(testChannel.dispose);
6396+
6397+
expect(testChannel.filterTags, equals(['tag1', 'tag2']));
6398+
});
6399+
6400+
test('should update filterTags when channel state is updated', () {
6401+
final channelModel = ChannelModel(
6402+
id: channelId,
6403+
type: channelType,
6404+
filterTags: ['tag1', 'tag2'],
6405+
);
6406+
6407+
final channelState = ChannelState(channel: channelModel);
6408+
final testChannel = Channel.fromState(client, channelState);
6409+
addTearDown(testChannel.dispose);
6410+
6411+
expect(testChannel.filterTags, equals(['tag1', 'tag2']));
6412+
6413+
final updatedChannel = channelModel.copyWith(
6414+
filterTags: ['tag3', 'tag4', 'tag5'],
6415+
);
6416+
6417+
testChannel.state?.updateChannelState(
6418+
testChannel.state!.channelState.copyWith(channel: updatedChannel),
6419+
);
6420+
6421+
expect(testChannel.filterTags, equals(['tag3', 'tag4', 'tag5']));
6422+
});
6423+
});
6424+
63606425
group('Typing Indicator', () {
63616426
const channelId = 'test-channel-id';
63626427
const channelType = 'test-channel-type';

packages/stream_chat/test/src/core/models/channel_test.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,14 @@ void main() {
317317

318318
expect(channel.truncatedAt, isNull);
319319
});
320+
321+
test('should parse filterTags from json correctly', () {
322+
final channel = ChannelModel.fromJson({
323+
'id': 'test',
324+
'type': 'livestream',
325+
'filter_tags': ['tag1', 'tag2', 'tag3'],
326+
});
327+
328+
expect(channel.filterTags, equals(['tag1', 'tag2', 'tag3']));
329+
});
320330
}

packages/stream_chat_persistence/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Upcoming
2+
3+
✅ Added
4+
5+
- Added support for `ChannelModel.filterTags` field.
6+
17
## 9.21.0
28

39
- Updated `stream_chat` dependency to [`9.21.0`](https://pub.dev/packages/stream_chat/changelog).

packages/stream_chat_persistence/lib/src/db/drift_chat_database.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class DriftChatDatabase extends _$DriftChatDatabase {
5555

5656
// you should bump this number whenever you change or add a table definition.
5757
@override
58-
int get schemaVersion => 26;
58+
int get schemaVersion => 27;
5959

6060
@override
6161
MigrationStrategy get migration => MigrationStrategy(

0 commit comments

Comments
 (0)