From a34ac516528ac899086b96bb2c9bd3bf76480f5a Mon Sep 17 00:00:00 2001 From: Leandro Borges Ferreira Date: Tue, 31 Jan 2023 14:16:58 +0100 Subject: [PATCH] Emmiting changes instead of applying on place --- .../stream_chat/lib/src/client/channel.dart | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/stream_chat/lib/src/client/channel.dart b/packages/stream_chat/lib/src/client/channel.dart index a05f9922..e9635caa 100644 --- a/packages/stream_chat/lib/src/client/channel.dart +++ b/packages/stream_chat/lib/src/client/channel.dart @@ -1762,7 +1762,14 @@ class ChannelClientState { _subscriptions.add( _channel.on(EventType.userWatchingStart).listen((event) { if (event.user != null) { - _incrementWatcher(event.user!); + final watcher = event.user; + final existingWatchers = channelState.watchers ?? []; + updateChannelState(channelState.copyWith( + watchers: [ + ...existingWatchers, + watcher!, + ], + )); } }), ); @@ -1772,7 +1779,14 @@ class ChannelClientState { _subscriptions.add( _channel.on(EventType.userWatchingStop).listen((event) { if (event.user != null) { - channelState.watchers?.remove(event.user); + final watcher = event.user; + final existingWatchers = channelState.watchers ?? []; + + updateChannelState(channelState.copyWith( + watchers: existingWatchers + .where((user) => user.id != watcher!.id) + .toList(growable: false), + )); } }), );