diff --git a/static/js/message_util.js b/static/js/message_util.js index ae130e15bb..717d8af961 100644 --- a/static/js/message_util.js +++ b/static/js/message_util.js @@ -78,4 +78,23 @@ exports.get_max_message_id_in_stream = function (stream_id) { return max_message_id; }; +exports.get_topics_for_message_ids = function (message_ids) { + const topics = new Map(); // key = stream_id:topic + for (const msg_id of message_ids) { + // 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; + topics.set(topic_key, [message.stream_id, message.topic]); + } + } + return topics; +}; + window.message_util = exports; diff --git a/static/js/recent_senders.js b/static/js/recent_senders.js index 1d95ca7751..4880ecc264 100644 --- a/static/js/recent_senders.js +++ b/static/js/recent_senders.js @@ -74,21 +74,7 @@ exports.process_topic_edit = function (old_stream_id, old_topic, new_topic, new_ }; exports.update_topics_of_deleted_message_ids = function (message_ids) { - const topics_to_update = new Map(); - for (const msg_id of message_ids) { - // 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; - topics_to_update.set(topic_key, [message.stream_id, message.topic]); - } - } + const topics_to_update = message_util.get_topics_for_message_ids(message_ids); for (const [stream_id, topic] of topics_to_update.values()) { const topic_dict = topic_senders.get(stream_id); diff --git a/static/js/recent_topics.js b/static/js/recent_topics.js index 1681fd5a1f..12a7dd6b9a 100644 --- a/static/js/recent_topics.js +++ b/static/js/recent_topics.js @@ -237,19 +237,7 @@ exports.topic_in_search_results = function (keyword, stream, topic) { }; exports.update_topics_of_deleted_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]); - } - } + const topics_to_rerender = message_util.get_topics_for_message_ids(message_ids); for (const [stream_id, topic] of topics_to_rerender.values()) { topics.delete(get_topic_key(stream_id, topic));