Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

message_view: Extract preserves_topics_kept_unread_by_user.

Aman Agrawal69222489b227
diff --git a/web/src/message_view.ts b/web/src/message_view.ts
index e1ad07203b6..1ff25c8ed1f 100644
--- a/web/src/message_view.ts
+++ b/web/src/message_view.ts
@@ -160,6 +160,15 @@ type TargetMessageIdInfo = {
first_unread_msg_id_pending_server_verification: number | undefined;
};
+export function preserves_topics_kept_unread_by_user(trigger: string | undefined): boolean {
+ return (
+ trigger !== undefined &&
+ ["next_topic_unread_hotkey", "old_unreads_missing", "retarget message location"].includes(
+ trigger,
+ )
+ );
+}
+
function create_and_update_message_list(
filter: Filter,
id_info: TargetMessageIdInfo,
@@ -275,12 +284,7 @@ function create_and_update_message_list(
// To keep the behaviour of `n` key consistent and the memory of
// `topics_kept_unread_by_user` as recent as possible, we clear it.
- if (
- !opts.trigger ||
- !["next_topic_unread_hotkey", "old_unreads_missing", "retarget message location"].includes(
- opts.trigger,
- )
- ) {
+ if (!preserves_topics_kept_unread_by_user(opts.trigger)) {
topic_generator.reset_topics_kept_unread_by_user();
}
diff --git a/web/tests/message_view.test.cjs b/web/tests/message_view.test.cjs
index 31c3dada9a2..094d9219208 100644
--- a/web/tests/message_view.test.cjs
+++ b/web/tests/message_view.test.cjs
@@ -1306,3 +1306,17 @@ run_test("narrow_compute_title", () => {
filter = new Filter([{operator: "dm", operand: [9999]}]);
assert.equal(narrow_title.compute_narrow_title(filter), "translated: Invalid user");
});
+
+run_test("preserves_topics_kept_unread_by_user", () => {
+ for (const trigger of [
+ "next_topic_unread_hotkey",
+ "old_unreads_missing",
+ "retarget message location",
+ ]) {
+ assert.ok(message_view.preserves_topics_kept_unread_by_user(trigger));
+ }
+
+ // `p` moves to a direct message conversation.
+ assert.ok(!message_view.preserves_topics_kept_unread_by_user("hotkey"));
+ assert.ok(!message_view.preserves_topics_kept_unread_by_user(undefined));
+});