Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
message_util: Extract get_topics_for_message_ids.
Aman Agrawal93a41e95a132
diff --git a/static/js/message_util.js b/static/js/message_util.jsindex ae130e15bb6..717d8af9617 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.jsindex 1d95ca7751a..4880ecc264e 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.jsindex 1681fd5a1f1..12a7dd6b9a5 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));