handle channel.deleted
This commit is contained in:
@@ -104,14 +104,15 @@ class ChannelsBlocState extends State<ChannelsBloc>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamSubscription _newMessagesSubscription;
|
final List<StreamSubscription> _subscriptions = [];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
_newMessagesSubscription =
|
final client = StreamChat.of(context).client;
|
||||||
StreamChat.of(context).client.on(EventType.messageNew).listen((e) {
|
|
||||||
|
_subscriptions.add(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) {
|
||||||
@@ -119,14 +120,20 @@ class ChannelsBlocState extends State<ChannelsBloc>
|
|||||||
newChannels.insert(0, channel);
|
newChannels.insert(0, channel);
|
||||||
_channelsController.add(newChannels);
|
_channelsController.add(newChannels);
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
|
|
||||||
|
_subscriptions.add(client.on(EventType.channelDeleted).listen((e) {
|
||||||
|
final channel = e.channel;
|
||||||
|
_channelsController
|
||||||
|
.add(channels..removeWhere((c) => c.cid == channel.cid));
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_channelsController.close();
|
_channelsController.close();
|
||||||
_queryChannelsLoadingController.close();
|
_queryChannelsLoadingController.close();
|
||||||
_newMessagesSubscription.cancel();
|
_subscriptions.forEach((s) => s.cancel());
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user