Merge pull request #233 from GetStream/feature/messageFilter

This commit is contained in:
Deven Joshi
2021-01-25 14:38:01 +05:30
committed by GitHub
4 changed files with 35 additions and 12 deletions
+5
View File
@@ -1,3 +1,8 @@
## 0.2.21
- Add `loadingBuilder` in `MessageListView`
- Add `messageFilter` property in `MessageListView`
## 0.2.20+4 ## 0.2.20+4
- Fix channelPreview when the message list is empty - Fix channelPreview when the message list is empty
+2 -2
View File
@@ -59,7 +59,7 @@ void _initNotifications(Client client) {
if (connector.token.value != null) { if (connector.token.value != null) {
client.addDevice( client.addDevice(
connector.token.value, 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], '\$in': [StreamChat.of(context).user.id],
} }
}, },
// sort: [SortOption('last_message_at')], sort: [SortOption('last_message_at')],
pagination: PaginationParams( pagination: PaginationParams(
limit: 20, limit: 20,
), ),
+27 -9
View File
@@ -108,6 +108,8 @@ class MessageListView extends StatefulWidget {
this.onParentMessageTap, this.onParentMessageTap,
this.scrollPhysics = const AlwaysScrollableScrollPhysics(), this.scrollPhysics = const AlwaysScrollableScrollPhysics(),
this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual, this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual,
this.messageFilter,
this.loadingBuilder,
}) : super(key: key); }) : super(key: key);
/// Function used to build a custom message widget /// Function used to build a custom message widget
@@ -119,6 +121,12 @@ class MessageListView extends StatefulWidget {
/// Function used to build a custom thread widget /// Function used to build a custom thread widget
final ThreadBuilder threadBuilder; final ThreadBuilder threadBuilder;
/// The builder used while loading.
final WidgetBuilder loadingBuilder;
/// Filter applied to the message list before rendering
final bool Function(Message) messageFilter;
/// Function called when tapping on a thread /// Function called when tapping on a thread
/// By default it calls [Navigator.push] using the widget built using [threadBuilder] /// By default it calls [Navigator.push] using the widget built using [threadBuilder]
final ThreadTapCallback onThreadTap; final ThreadTapCallback onThreadTap;
@@ -304,6 +312,11 @@ class _MessageListViewState extends State<MessageListView> {
if (!snapshot.data) { if (!snapshot.data) {
return Container(); return Container();
} }
if (widget.loadingBuilder != null) {
return widget.loadingBuilder(context);
}
return Center( return Center(
child: Padding( child: Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
@@ -518,15 +531,20 @@ class _MessageListViewState extends State<MessageListView> {
.map((threads) => threads[widget.parentMessage.id]); .map((threads) => threads[widget.parentMessage.id]);
} }
_streamListener = stream _streamListener = stream.map((messages) {
.map((messages) => final filteredMessages = messages
messages ?.where((m) =>
?.where((m) => !(m.status == MessageSendingStatus.FAILED && m.isDeleted) &&
!(m.status == MessageSendingStatus.FAILED && m.isDeleted) && m.shadowed != true)
m.shadowed != true) ?.toList() ??
?.toList() ?? [];
[])
.listen((newMessages) { if (widget.messageFilter != null) {
return messages.where(widget.messageFilter).toList();
}
return filteredMessages;
}).listen((newMessages) {
newMessages = newMessages.reversed.toList(); newMessages = newMessages.reversed.toList();
if (_messages.isEmpty || if (_messages.isEmpty ||
newMessages.isEmpty || newMessages.isEmpty ||
+1 -1
View File
@@ -1,7 +1,7 @@
name: stream_chat_flutter name: stream_chat_flutter
homepage: https://github.com/GetStream/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. 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 repository: https://github.com/GetStream/stream-chat-flutter
issue_tracker: https://github.com/GetStream/stream-chat-flutter/issues issue_tracker: https://github.com/GetStream/stream-chat-flutter/issues