From f79d49ce89516c713dfc04d707b78ab090a5c309 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 17 Dec 2020 10:13:39 +0100 Subject: [PATCH 1/5] expose channels setter --- lib/src/channels_bloc.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/src/channels_bloc.dart b/lib/src/channels_bloc.dart index 3af2300d..2312ff12 100644 --- a/lib/src/channels_bloc.dart +++ b/lib/src/channels_bloc.dart @@ -58,6 +58,11 @@ class ChannelsBlocState extends State final BehaviorSubject> _channelsController = BehaviorSubject(); + /// Set the current channel list + set channels(List newChannels) { + _channelsController.add(newChannels); + } + /// The stream notifying the state of queryChannel call Stream get queryChannelsLoading => _queryChannelsLoadingController.stream; From 4b88627457ca5d1dc76dea5c8d24bb3fe3b76674 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 17 Dec 2020 10:14:31 +0100 Subject: [PATCH 2/5] version bp --- CHANGELOG.md | 4 ++++ pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62efc4ac..fcf6bcf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.17+2 + +- Expose ChannelsBloc.channels setter + ## 0.2.17+1 - Fix mention tap bug diff --git a/pubspec.yaml b/pubspec.yaml index a400260e..dd5273b7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: stream_chat_flutter homepage: https://github.com/GetStream/stream-chat-flutter description: Stream Chat official Flutter SDK. Build your own chat experience using Dart and Flutter. -version: 0.2.17+1 +version: 0.2.17+2 repository: https://github.com/GetStream/stream-chat-flutter issue_tracker: https://github.com/GetStream/stream-chat-flutter/issues From 7310a905beb44822c59ad3c678b9d10ab7d75c75 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 17 Dec 2020 10:33:47 +0100 Subject: [PATCH 3/5] add change it to a function called at the end of the message.new event handler --- lib/src/channels_bloc.dart | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/src/channels_bloc.dart b/lib/src/channels_bloc.dart index 2312ff12..1d5d3f92 100644 --- a/lib/src/channels_bloc.dart +++ b/lib/src/channels_bloc.dart @@ -14,11 +14,15 @@ class ChannelsBloc extends StatefulWidget { /// Set this to true to prevent channels to be brought to the top of the list when a new message arrives final bool lockChannelsOrder; + /// Function used to sort the channels when a message.new event is received + final List Function(List) sortChannels; + /// Instantiate a new ChannelsBloc const ChannelsBloc({ Key key, this.child, this.lockChannelsOrder = false, + this.sortChannels, }) : super(key: key); @override @@ -58,11 +62,6 @@ class ChannelsBlocState extends State final BehaviorSubject> _channelsController = BehaviorSubject(); - /// Set the current channel list - set channels(List newChannels) { - _channelsController.add(newChannels); - } - /// The stream notifying the state of queryChannel call Stream get queryChannelsLoading => _queryChannelsLoadingController.stream; @@ -146,7 +145,13 @@ class ChannelsBlocState extends State } } } - _channelsController.add(newChannels); + + if (widget.sortChannels != null) { + final sortedChannels = widget.sortChannels(newChannels); + _channelsController.add(sortedChannels); + } else { + _channelsController.add(newChannels); + } })); } From 422df24e9f36b7aec818a2292c2bae2d325f4f23 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 17 Dec 2020 11:15:25 +0100 Subject: [PATCH 4/5] use comparator --- lib/src/channels_bloc.dart | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/src/channels_bloc.dart b/lib/src/channels_bloc.dart index 1d5d3f92..59dd6335 100644 --- a/lib/src/channels_bloc.dart +++ b/lib/src/channels_bloc.dart @@ -14,15 +14,15 @@ class ChannelsBloc extends StatefulWidget { /// Set this to true to prevent channels to be brought to the top of the list when a new message arrives final bool lockChannelsOrder; - /// Function used to sort the channels when a message.new event is received - final List Function(List) sortChannels; + /// Comparator used to sort the channels when a message.new event is received + final Comparator channelsComparator; /// Instantiate a new ChannelsBloc const ChannelsBloc({ Key key, this.child, this.lockChannelsOrder = false, - this.sortChannels, + this.channelsComparator, }) : super(key: key); @override @@ -146,12 +146,10 @@ class ChannelsBlocState extends State } } - if (widget.sortChannels != null) { - final sortedChannels = widget.sortChannels(newChannels); - _channelsController.add(sortedChannels); - } else { - _channelsController.add(newChannels); + if (widget.channelsComparator != null) { + newChannels.sort(widget.channelsComparator); } + _channelsController.add(newChannels); })); } From 0883728a2efa272149341f64af97095d133c333b Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 17 Dec 2020 11:19:55 +0100 Subject: [PATCH 5/5] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fcf6bcf6..c91502be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.2.17+2 -- Expose ChannelsBloc.channels setter +- Expose ChannelsBloc.channelsComparator to sort channels on message.new event ## 0.2.17+1