From fa2be8397dc614bc84f3ae0545e39f4a5e665fe4 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Mon, 6 Apr 2020 16:46:00 +0200 Subject: [PATCH] use a map for channels in client --- lib/src/channels_bloc.dart | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/src/channels_bloc.dart b/lib/src/channels_bloc.dart index 0ced2b82..fa111710 100644 --- a/lib/src/channels_bloc.dart +++ b/lib/src/channels_bloc.dart @@ -1,11 +1,14 @@ +import 'dart:async'; + import 'package:rxdart/rxdart.dart'; import 'package:stream_chat/stream_chat.dart'; class ChannelsBloc { final Client client; + StreamSubscription _newMessagesSubscription; ChannelsBloc(this.client) { - client.on(EventType.messageNew).listen((e) { + _newMessagesSubscription = client.on(EventType.messageNew).listen((e) { final newChannels = List.from(channels ?? []); final index = newChannels.indexWhere((c) => c.cid == e.cid); if (index > 0) { @@ -80,5 +83,6 @@ class ChannelsBloc { void dispose() { _channelsController.close(); _queryChannelsLoadingController.close(); + _newMessagesSubscription.cancel(); } }