mirror of
https://github.com/zulip/zulip.git
synced 2025-11-16 11:52:01 +00:00
message_util: Extract get_topics_for_message_ids.
This commit is contained in:
@@ -78,4 +78,23 @@ exports.get_max_message_id_in_stream = function (stream_id) {
|
|||||||
return max_message_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;
|
window.message_util = exports;
|
||||||
|
|||||||
@@ -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) {
|
exports.update_topics_of_deleted_message_ids = function (message_ids) {
|
||||||
const topics_to_update = new Map();
|
const topics_to_update = message_util.get_topics_for_message_ids(message_ids);
|
||||||
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]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const [stream_id, topic] of topics_to_update.values()) {
|
for (const [stream_id, topic] of topics_to_update.values()) {
|
||||||
const topic_dict = topic_senders.get(stream_id);
|
const topic_dict = topic_senders.get(stream_id);
|
||||||
|
|||||||
@@ -237,19 +237,7 @@ exports.topic_in_search_results = function (keyword, stream, topic) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.update_topics_of_deleted_message_ids = function (message_ids) {
|
exports.update_topics_of_deleted_message_ids = function (message_ids) {
|
||||||
const topics_to_rerender = new Map();
|
const topics_to_rerender = message_util.get_topics_for_message_ids(message_ids);
|
||||||
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]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const [stream_id, topic] of topics_to_rerender.values()) {
|
for (const [stream_id, topic] of topics_to_rerender.values()) {
|
||||||
topics.delete(get_topic_key(stream_id, topic));
|
topics.delete(get_topic_key(stream_id, topic));
|
||||||
|
|||||||
Reference in New Issue
Block a user