js: Fix dependency cycle in unread.js.

The import of recent_topics_ui.js from unread.js generates an import
loop. To remove this, we need to move the logic for rerendering recent
topics after update_message_for_mention out of the low-level unread.js
data module.

Since the logic was conditional on `content_edited` being true, and
that parameter is only passed in the message_events.js code path, we
can do this by just making the function return a boolean for whether
this rerender may be required, and moving the rerender logic to that
calling module.
This commit is contained in:
Hardik Dharmani
2023-03-11 22:07:17 +05:30
committed by Tim Abbott
parent b46e7ef78e
commit 2c30bbbf74
2 changed files with 12 additions and 7 deletions

View File

@@ -23,6 +23,7 @@ import {page_params} from "./page_params";
import * as pm_list from "./pm_list";
import * as recent_senders from "./recent_senders";
import * as recent_topics_ui from "./recent_topics_ui";
import * as recent_topics_util from "./recent_topics_util";
import * as stream_list from "./stream_list";
import * as stream_topic_history from "./stream_topic_history";
import * as sub_store from "./sub_store";
@@ -225,7 +226,10 @@ export function update_messages(events) {
msg.raw_content = event.content;
}
unread.update_message_for_mention(msg, any_message_content_edited);
if (unread.update_message_for_mention(msg, any_message_content_edited)) {
const topic_key = recent_topics_util.get_topic_key(msg.stream_id, msg.topic);
recent_topics_ui.inplace_rerender(topic_key);
}
// new_topic will be undefined if the topic is unchanged.
const new_topic = util.get_edit_event_topic(event);

View File

@@ -2,7 +2,6 @@ import * as blueslip from "./blueslip";
import {FoldDict} from "./fold_dict";
import * as message_store from "./message_store";
import * as people from "./people";
import * as recent_topics_ui from "./recent_topics_ui";
import * as recent_topics_util from "./recent_topics_util";
import * as settings_config from "./settings_config";
import * as stream_data from "./stream_data";
@@ -637,10 +636,14 @@ export function process_unread_message(message) {
}
export function update_message_for_mention(message, content_edited = false) {
// Returns true if this is a stream message whose content was
// changed, and thus the caller might need to trigger a rerender
// of UI elements displaying whether the message's topic contains
// an unread mention of the user.
if (!message.unread) {
unread_mentions_counter.delete(message.id);
remove_message_from_unread_mention_topics(message.id);
return;
return false;
}
const is_unmuted_mention =
@@ -657,11 +660,9 @@ export function update_message_for_mention(message, content_edited = false) {
}
if (content_edited && message.type === "stream") {
// We only need to update recent topics here if this was a content change in an unread
// mention, since in other cases recent topics gets rerendered by other functions.
const topic_key = recent_topics_util.get_topic_key(message.stream_id, message.topic);
recent_topics_ui.inplace_rerender(topic_key);
return true;
}
return false;
}
export function mark_as_read(message_id) {