message_events: Ask server if cannot filter locally.

For filters that cannot be applied locally, we ask the server
to determine if the `events_messages` are part of the narrow.

Fixes #21073
This commit is contained in:
Aman Agrawal
2022-02-16 05:57:48 +00:00
committed by Tim Abbott
parent a7f904cdc3
commit bda90ec5ae
2 changed files with 16 additions and 9 deletions

View File

@@ -355,19 +355,26 @@ export function update_messages(events) {
// this should be a loop over all valid message_list_data
// objects, without the rerender (which will naturally
// happen in the following code).
if (!changed_narrow) {
if (!changed_narrow && current_filter) {
let message_ids_to_remove = [];
if (current_filter && current_filter.can_apply_locally()) {
if (current_filter.can_apply_locally()) {
const predicate = current_filter.predicate();
message_ids_to_remove = event_messages.filter((msg) => !predicate(msg));
message_ids_to_remove = message_ids_to_remove.map((msg) => msg.id);
// We filter out messages that do not belong to the message
// list and then pass these to the remove messages codepath.
// While we can pass all our messages to the add messages
// codepath as the filtering is done within the method.
message_lists.current.remove_and_rerender(message_ids_to_remove);
message_lists.current.add_messages(event_messages);
} else {
// For filters that cannot be processed locally, ask server.
maybe_add_narrowed_messages(
event_messages,
message_lists.current,
message_util.add_messages,
);
}
// We filter out messages that do not belong to the message
// list and then pass these to the remove messages codepath.
// While we can pass all our messages to the add messages
// codepath as the filtering is done within the method.
message_lists.current.remove_and_rerender(message_ids_to_remove);
message_lists.current.add_messages(event_messages);
}
}

View File

@@ -13,7 +13,7 @@ export function do_unread_count_updates(messages) {
resize.resize_page_components();
}
function add_messages(messages, msg_list, opts) {
export function add_messages(messages, msg_list, opts) {
if (!messages) {
return undefined;
}