add messageFilter property in messageListView
This commit is contained in:
@@ -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,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ 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,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
/// Function used to build a custom message widget
|
/// Function used to build a custom message widget
|
||||||
@@ -119,6 +120,9 @@ 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;
|
||||||
|
|
||||||
|
/// 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;
|
||||||
@@ -518,15 +522,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 ||
|
||||||
|
|||||||
Reference in New Issue
Block a user