From e0c8068fbdc9a8fdba1ce696d198f17870391232 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Mon, 25 Jan 2021 09:54:16 +0100 Subject: [PATCH 1/3] add messageFilter property in messageListView --- example/lib/main.dart | 4 ++-- lib/src/message_list_view.dart | 27 ++++++++++++++++++--------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index f048f584..4b8418e9 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -59,7 +59,7 @@ void _initNotifications(Client client) { if (connector.token.value != null) { client.addDevice( connector.token.value, - Platform.isAndroid ? 'firebase' : 'apn', + Platform.isAndroid ? PushProvider.firebase : PushProvider.apn, ); } }); @@ -127,7 +127,7 @@ class ChannelListPage extends StatelessWidget { '\$in': [StreamChat.of(context).user.id], } }, - // sort: [SortOption('last_message_at')], + sort: [SortOption('last_message_at')], pagination: PaginationParams( limit: 20, ), diff --git a/lib/src/message_list_view.dart b/lib/src/message_list_view.dart index f1d1a2ce..8b6876d2 100644 --- a/lib/src/message_list_view.dart +++ b/lib/src/message_list_view.dart @@ -108,6 +108,7 @@ class MessageListView extends StatefulWidget { this.onParentMessageTap, this.scrollPhysics = const AlwaysScrollableScrollPhysics(), this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual, + this.messageFilter, }) : super(key: key); /// Function used to build a custom message widget @@ -119,6 +120,9 @@ class MessageListView extends StatefulWidget { /// Function used to build a custom thread widget final ThreadBuilder threadBuilder; + /// Filter applied to the message list before rendering + final bool Function(Message) messageFilter; + /// Function called when tapping on a thread /// By default it calls [Navigator.push] using the widget built using [threadBuilder] final ThreadTapCallback onThreadTap; @@ -518,15 +522,20 @@ class _MessageListViewState extends State { .map((threads) => threads[widget.parentMessage.id]); } - _streamListener = stream - .map((messages) => - messages - ?.where((m) => - !(m.status == MessageSendingStatus.FAILED && m.isDeleted) && - m.shadowed != true) - ?.toList() ?? - []) - .listen((newMessages) { + _streamListener = stream.map((messages) { + final filteredMessages = messages + ?.where((m) => + !(m.status == MessageSendingStatus.FAILED && m.isDeleted) && + m.shadowed != true) + ?.toList() ?? + []; + + if (widget.messageFilter != null) { + return messages.where(widget.messageFilter).toList(); + } + + return filteredMessages; + }).listen((newMessages) { newMessages = newMessages.reversed.toList(); if (_messages.isEmpty || newMessages.isEmpty || From 0ef454acc63f41fdf38103034195dfd00194c0e7 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Mon, 25 Jan 2021 09:56:38 +0100 Subject: [PATCH 2/3] add loadingbuilder in messagelistview --- lib/src/message_list_view.dart | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/src/message_list_view.dart b/lib/src/message_list_view.dart index 8b6876d2..f968d850 100644 --- a/lib/src/message_list_view.dart +++ b/lib/src/message_list_view.dart @@ -109,6 +109,7 @@ class MessageListView extends StatefulWidget { this.scrollPhysics = const AlwaysScrollableScrollPhysics(), this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual, this.messageFilter, + this.loadingBuilder, }) : super(key: key); /// Function used to build a custom message widget @@ -120,6 +121,9 @@ class MessageListView extends StatefulWidget { /// Function used to build a custom thread widget final ThreadBuilder threadBuilder; + /// The builder used while loading. + final WidgetBuilder loadingBuilder; + /// Filter applied to the message list before rendering final bool Function(Message) messageFilter; @@ -308,6 +312,11 @@ class _MessageListViewState extends State { if (!snapshot.data) { return Container(); } + + if (widget.loadingBuilder != null) { + return widget.loadingBuilder(context); + } + return Center( child: Padding( padding: const EdgeInsets.all(8.0), From 9635e2cda212be232b7e49420857acec51cbacde Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Mon, 25 Jan 2021 09:58:31 +0100 Subject: [PATCH 3/3] bump version --- CHANGELOG.md | 5 +++++ pubspec.yaml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e30a47f3..578265ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.2.21 + +- Add `loadingBuilder` in `MessageListView` +- Add `messageFilter` property in `MessageListView` + ## 0.2.20+4 - Fix channelPreview when the message list is empty diff --git a/pubspec.yaml b/pubspec.yaml index 09380ccc..849339b8 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.20+4 +version: 0.2.21 repository: https://github.com/GetStream/stream-chat-flutter issue_tracker: https://github.com/GetStream/stream-chat-flutter/issues