add shouldAddChannel to ChannelsBloc
This commit is contained in:
@@ -17,12 +17,16 @@ class ChannelsBloc extends StatefulWidget {
|
|||||||
/// Comparator used to sort the channels when a message.new event is received
|
/// Comparator used to sort the channels when a message.new event is received
|
||||||
final Comparator<Channel> channelsComparator;
|
final Comparator<Channel> 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
|
/// Instantiate a new ChannelsBloc
|
||||||
const ChannelsBloc({
|
const ChannelsBloc({
|
||||||
Key key,
|
Key key,
|
||||||
this.child,
|
this.child,
|
||||||
this.lockChannelsOrder = false,
|
this.lockChannelsOrder = false,
|
||||||
this.channelsComparator,
|
this.channelsComparator,
|
||||||
|
this.shouldAddChannel,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -128,7 +132,8 @@ class ChannelsBlocState extends State<ChannelsBloc>
|
|||||||
final channel = newChannels.removeAt(index);
|
final channel = newChannels.removeAt(index);
|
||||||
newChannels.insert(0, channel);
|
newChannels.insert(0, channel);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (widget.shouldAddChannel != null &&
|
||||||
|
widget.shouldAddChannel(e)) {
|
||||||
final hiddenIndex = _hiddenChannels.indexWhere((c) => c.cid == e.cid);
|
final hiddenIndex = _hiddenChannels.indexWhere((c) => c.cid == e.cid);
|
||||||
if (hiddenIndex > -1) {
|
if (hiddenIndex > -1) {
|
||||||
newChannels.insert(0, _hiddenChannels[hiddenIndex]);
|
newChannels.insert(0, _hiddenChannels[hiddenIndex]);
|
||||||
|
|||||||
Reference in New Issue
Block a user