Merge pull request #1448 from GetStream/ISSUE-1432/FIxingWatchersStream

This commit is contained in:
Sahil Kumar
2023-02-09 15:48:51 +05:30
committed by GitHub
3 changed files with 49 additions and 1 deletions
+5
View File
@@ -1,5 +1,10 @@
## Upcoming
🐞 Fixed
- Fixed streamWatchers. Before it was always new, now it is possible to follow the watchers of a channel.
## Upcoming
🔄 Changed
- Cancelling a attachment upload now removes the attachment from the message.
@@ -1628,6 +1628,10 @@ class ChannelClientState {
_listenMemberUnbanned();
_listenUserStartWatching();
_listenUserStopWatching();
_startCleaningStaleTypingEvents();
_startCleaningStalePinnedMessages();
@@ -1769,6 +1773,39 @@ class ChannelClientState {
));
}
void _listenUserStartWatching() {
_subscriptions.add(
_channel.on(EventType.userWatchingStart).listen((event) {
final watcher = event.user;
if (watcher != null) {
final existingWatchers = channelState.watchers;
updateChannelState(channelState.copyWith(
watchers: [
...?existingWatchers,
watcher,
],
));
}
}),
);
}
void _listenUserStopWatching() {
_subscriptions.add(
_channel.on(EventType.userWatchingStop).listen((event) {
final watcher = event.user;
if (watcher != null) {
final existingWatchers = channelState.watchers;
updateChannelState(channelState.copyWith(
watchers: existingWatchers
?.where((user) => user.id != watcher.id)
.toList(growable: false),
));
}
}),
);
}
void _listenMemberUnbanned() {
_subscriptions.add(_channel
.on(EventType.userUnbanned)
@@ -2098,7 +2135,7 @@ class ChannelClientState {
channelStateStream.map((cs) => cs.watchers),
_channel.client.state.usersStream,
(watchers, users) => watchers!.map((e) => users[e.id] ?? e).toList(),
);
).distinct(const ListEquality().equals);
/// Channel member for the current user.
Member? get currentUserMember => members.firstWhereOrNull(
@@ -36,6 +36,12 @@ class EventType {
/// Event sent when updating a message
static const String messageUpdated = 'message.updated';
/// Event sent when a user starts watching a channel
static const String userWatchingStart = 'user.watching.start';
/// Event sent when a user stops watching a channel
static const String userWatchingStop = 'user.watching.stop';
/// Event sent when reading a message
static const String messageRead = 'message.read';