unread: Move some functions.

Moved these functions to be able to access `unread_topic_counter`
inside them.
This commit is contained in:
Aman Agrawal 2022-11-01 16:50:52 +00:00 committed by Tim Abbott
parent 8810203a4c
commit 2e480b0b09
1 changed files with 23 additions and 23 deletions

View File

@ -42,29 +42,6 @@ const unread_messages = new Set();
// for how we can refresh it efficiently. // for how we can refresh it efficiently.
export const unread_mention_topics = new Map(); export const unread_mention_topics = new Map();
function add_message_to_unread_mention_topics(message_id) {
const message = message_store.get(message_id);
if (message.type !== "stream") {
return;
}
const topic_key = recent_topics_util.get_topic_key(message.stream_id, message.topic);
if (unread_mention_topics.has(topic_key)) {
unread_mention_topics.get(topic_key).add(message_id);
}
unread_mention_topics.set(topic_key, new Set([message_id]));
}
function remove_message_from_unread_mention_topics(message_id) {
const message = message_store.get(message_id);
if (message.type !== "stream") {
return;
}
const topic_key = recent_topics_util.get_topic_key(message.stream_id, message.topic);
if (unread_mention_topics.has(topic_key)) {
unread_mention_topics.get(topic_key).delete(message_id);
}
}
class Bucketer { class Bucketer {
// Maps item_id => bucket_key for items present in a bucket. // Maps item_id => bucket_key for items present in a bucket.
reverse_lookup = new Map(); reverse_lookup = new Map();
@ -468,6 +445,29 @@ class UnreadTopicCounter {
} }
const unread_topic_counter = new UnreadTopicCounter(); const unread_topic_counter = new UnreadTopicCounter();
function add_message_to_unread_mention_topics(message_id) {
const message = message_store.get(message_id);
if (message.type !== "stream") {
return;
}
const topic_key = recent_topics_util.get_topic_key(message.stream_id, message.topic);
if (unread_mention_topics.has(topic_key)) {
unread_mention_topics.get(topic_key).add(message_id);
}
unread_mention_topics.set(topic_key, new Set([message_id]));
}
function remove_message_from_unread_mention_topics(message_id) {
const message = message_store.get(message_id);
if (message.type !== "stream") {
return;
}
const topic_key = recent_topics_util.get_topic_key(message.stream_id, message.topic);
if (unread_mention_topics.has(topic_key)) {
unread_mention_topics.get(topic_key).delete(message_id);
}
}
export function clear_and_populate_unread_mention_topics() { export function clear_and_populate_unread_mention_topics() {
// The unread_mention_topics is an important data structure for // The unread_mention_topics is an important data structure for
// efficiently querying whether a given stream/topic pair contains // efficiently querying whether a given stream/topic pair contains