add channel to view if new message arrives and the channel is hidden

This commit is contained in:
Salvatore Giordano
2020-08-05 09:36:16 +02:00
parent 84af372179
commit 40bf12a922
2 changed files with 21 additions and 0 deletions
+1
View File
@@ -377,6 +377,7 @@ class _ChannelListViewState extends State<ChannelListView>
.on(
EventType.connectionRecovered,
EventType.notificationAddedToChannel,
EventType.notificationMessageNew,
EventType.channelVisible,
)
.listen((event) {
+20
View File
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:rxdart/rxdart.dart';
import 'package:stream_chat/stream_chat.dart';
import 'package:stream_chat_flutter/src/stream_chat.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
/// Widget dedicated to the management of a channel list with pagination
class ChannelsBloc extends StatefulWidget {
@@ -58,6 +59,8 @@ class ChannelsBlocState extends State<ChannelsBloc>
Stream<bool> get queryChannelsLoading =>
_queryChannelsLoadingController.stream;
List<Channel> _hiddenChannels = [];
/// Calls [client.queryChannels] updating [queryChannelsLoading] stream
Future<void> queryChannels({
Map<String, dynamic> filter,
@@ -119,6 +122,23 @@ class ChannelsBlocState extends State<ChannelsBloc>
final channel = newChannels.removeAt(index);
newChannels.insert(0, channel);
_channelsController.add(newChannels);
} else {
final hiddenIndex = _hiddenChannels.indexWhere((c) => c.cid == e.cid);
if (hiddenIndex > -1) {
newChannels.insert(0, _hiddenChannels[hiddenIndex]);
_hiddenChannels.removeAt(hiddenIndex);
_channelsController.add(newChannels);
}
}
}));
_subscriptions.add(client.on(EventType.channelHidden).listen((event) async {
final newChannels = List<Channel>.from(channels);
final channelIndex = newChannels.indexWhere((c) => c.cid == event.cid);
if (channelIndex > -1) {
final channel = newChannels.removeAt(channelIndex);
_hiddenChannels.add(channel);
_channelsController.add(newChannels);
}
}));