use a map for channels in client
This commit is contained in:
@@ -1,11 +1,14 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:rxdart/rxdart.dart';
|
import 'package:rxdart/rxdart.dart';
|
||||||
import 'package:stream_chat/stream_chat.dart';
|
import 'package:stream_chat/stream_chat.dart';
|
||||||
|
|
||||||
class ChannelsBloc {
|
class ChannelsBloc {
|
||||||
final Client client;
|
final Client client;
|
||||||
|
StreamSubscription _newMessagesSubscription;
|
||||||
|
|
||||||
ChannelsBloc(this.client) {
|
ChannelsBloc(this.client) {
|
||||||
client.on(EventType.messageNew).listen((e) {
|
_newMessagesSubscription = client.on(EventType.messageNew).listen((e) {
|
||||||
final newChannels = List<Channel>.from(channels ?? []);
|
final newChannels = List<Channel>.from(channels ?? []);
|
||||||
final index = newChannels.indexWhere((c) => c.cid == e.cid);
|
final index = newChannels.indexWhere((c) => c.cid == e.cid);
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
@@ -80,5 +83,6 @@ class ChannelsBloc {
|
|||||||
void dispose() {
|
void dispose() {
|
||||||
_channelsController.close();
|
_channelsController.close();
|
||||||
_queryChannelsLoadingController.close();
|
_queryChannelsLoadingController.close();
|
||||||
|
_newMessagesSubscription.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user