From c9543ab644701b6913daf05b74d6aa6aa921308c Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Mon, 28 Dec 2020 13:24:28 +0100 Subject: [PATCH] add shouldAddChannel to ChannelsBloc --- lib/src/channels_bloc.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/src/channels_bloc.dart b/lib/src/channels_bloc.dart index 0784cb30..81081051 100644 --- a/lib/src/channels_bloc.dart +++ b/lib/src/channels_bloc.dart @@ -17,12 +17,16 @@ class ChannelsBloc extends StatefulWidget { /// Comparator used to sort the channels when a message.new event is received final Comparator channelsComparator; + /// Function used to evaluate if a channel should be added to the list when a message.new event is received + final bool Function(Event) shouldAddChannel; + /// Instantiate a new ChannelsBloc const ChannelsBloc({ Key key, this.child, this.lockChannelsOrder = false, this.channelsComparator, + this.shouldAddChannel, }) : super(key: key); @override @@ -128,7 +132,8 @@ class ChannelsBlocState extends State final channel = newChannels.removeAt(index); newChannels.insert(0, channel); } - } else { + } else if (widget.shouldAddChannel != null && + widget.shouldAddChannel(e)) { final hiddenIndex = _hiddenChannels.indexWhere((c) => c.cid == e.cid); if (hiddenIndex > -1) { newChannels.insert(0, _hiddenChannels[hiddenIndex]);