From 79c0d7fbabc04e1a98b49bcc5a65aef7f2474b9d Mon Sep 17 00:00:00 2001 From: Lauryn Menard Date: Thu, 17 Nov 2022 15:42:56 +0100 Subject: [PATCH] recent-conversations: Update logic for processing messages. As of 550a32b, when private messages were added to recent conversations, `recent_topics_data.process_message` will always return true. Updates `recent_topics_data.process_message` for no return value. Also, removes the `topic_data_changed` logic from `recent_topics_ui.process_messages` and instead checks for messages to process before updating the data and calling the rerender. `recent_topics_ui.complete_rerender` first checks for whether the recent conversations view is visible before rerendering. --- static/js/recent_topics_data.js | 4 ---- static/js/recent_topics_ui.js | 13 +++---------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/static/js/recent_topics_data.js b/static/js/recent_topics_data.js index b8e868876c..ccc21a192c 100644 --- a/static/js/recent_topics_data.js +++ b/static/js/recent_topics_data.js @@ -4,9 +4,6 @@ import {get_key_from_message} from "./recent_topics_util"; export const topics = new Map(); // Key is stream-id:topic. export function process_message(msg) { - // This function returns if topic_data - // has changed or not. - // Initialize topic and pm data // Key for private message is the user id's // to whom the message is begin sent. @@ -34,7 +31,6 @@ export function process_message(msg) { // message fetched in the topic. Ideally we would want this to be attached // to topic info fetched from backend, which is currently not a thing. topic_data.participated = is_ours || topic_data.participated; - return true; } function get_sorted_topics() { diff --git a/static/js/recent_topics_ui.js b/static/js/recent_topics_ui.js index ee3ae55db1..e26c142a6f 100644 --- a/static/js/recent_topics_ui.js +++ b/static/js/recent_topics_ui.js @@ -298,17 +298,10 @@ export function process_messages(messages) { // the UX can be bad if user wants to scroll down the list as // the UI will be returned to the beginning of the list on every // update. - // - // Only rerender if topic_data actually - // changed. - let topic_data_changed = false; - for (const msg of messages) { - if (process_message(msg)) { - topic_data_changed = true; + if (messages.length > 0) { + for (const msg of messages) { + process_message(msg); } - } - - if (topic_data_changed) { complete_rerender(); } }