From 5142bdd317710733e4f2fdcc7d122a5cff6e984a Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Thu, 6 Aug 2020 11:58:21 -0700 Subject: [PATCH] recent_topics: Fix exception processing old deleted messages. When old messages are deleted, they may not be present in message_store when we receive the event notifying the client about their deletion. --- static/js/recent_senders.js | 7 ++++++- static/js/recent_topics.js | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/static/js/recent_senders.js b/static/js/recent_senders.js index bd24a6e06e..77239aefdb 100644 --- a/static/js/recent_senders.js +++ b/static/js/recent_senders.js @@ -76,8 +76,13 @@ exports.process_topic_edit = function (old_stream_id, old_topic, new_topic, new_ exports.update_topics_of_message_ids = function (message_ids) { const topics_to_update = new Map(); for (const msg_id of message_ids) { - // Note: message_store retians data of msg post deletion. + // message_store still has data on deleted messages when this runs. const message = message_store.get(msg_id); + if (message === undefined) { + // We may not have the deleted message cached locally in + // message_store; if so, we can just skip processing it. + continue; + } if (message.type === "stream") { // Create unique keys for stream_id and topic. const topic_key = message.stream_id + ":" + message.topic; diff --git a/static/js/recent_topics.js b/static/js/recent_topics.js index 3019a38721..f699aa4ef5 100644 --- a/static/js/recent_topics.js +++ b/static/js/recent_topics.js @@ -238,6 +238,11 @@ exports.update_topics_of_message_ids = function (message_ids) { const topics_to_rerender = new Map(); for (const msg_id of message_ids) { const message = message_store.get(msg_id); + if (message === undefined) { + // We may not have the deleted message cached locally in + // message_store; if so, we can just skip processing it. + continue; + } if (message.type === "stream") { const topic_key = get_topic_key(message.stream_id, message.topic); topics_to_rerender.set(topic_key, [message.stream_id, message.topic]);