Merge pull request #70 from GetStream/feature/lockChannelsOrder

add lockChannelsOrder property to channelsBloc
This commit is contained in:
Salvatore Giordano
2020-08-07 16:01:36 +02:00
committed by GitHub
+7 -1
View File
@@ -11,10 +11,14 @@ class ChannelsBloc extends StatefulWidget {
/// The widget child
final Widget child;
/// Set this to false to prevent channels to be brought to the top of the list when a new message arrives
final bool lockChannelsOrder;
/// Instantiate a new ChannelsBloc
const ChannelsBloc({
Key key,
this.child,
this.lockChannelsOrder = false,
}) : super(key: key);
@override
@@ -59,7 +63,7 @@ class ChannelsBlocState extends State<ChannelsBloc>
Stream<bool> get queryChannelsLoading =>
_queryChannelsLoadingController.stream;
List<Channel> _hiddenChannels = [];
final List<Channel> _hiddenChannels = [];
/// Calls [client.queryChannels] updating [queryChannelsLoading] stream
Future<void> queryChannels({
@@ -115,6 +119,7 @@ class ChannelsBlocState extends State<ChannelsBloc>
final client = StreamChat.of(context).client;
if (!widget.lockChannelsOrder) {
_subscriptions.add(client.on(EventType.messageNew).listen((e) {
final newChannels = List<Channel>.from(channels ?? []);
final index = newChannels.indexWhere((c) => c.cid == e.cid);
@@ -131,6 +136,7 @@ class ChannelsBlocState extends State<ChannelsBloc>
}
}
}));
}
_subscriptions.add(client.on(EventType.channelHidden).listen((event) async {
final newChannels = List<Channel>.from(channels);