From bda90ec5ae6ee0c2582d62faa7a1e05b56e43689 Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Wed, 16 Feb 2022 05:57:48 +0000 Subject: [PATCH] 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 --- static/js/message_events.js | 23 +++++++++++++++-------- static/js/message_util.js | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/static/js/message_events.js b/static/js/message_events.js index a994b68d08..6882117731 100644 --- a/static/js/message_events.js +++ b/static/js/message_events.js @@ -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); } } diff --git a/static/js/message_util.js b/static/js/message_util.js index 5ced5c2301..56e085b60a 100644 --- a/static/js/message_util.js +++ b/static/js/message_util.js @@ -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; }