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.

hash_util: Move channel topic permalink to stream_topic_history.

Evy Kassirerb6079050d3e9
diff --git a/web/src/hash_util.ts b/web/src/hash_util.ts
index 553e54356a6..86095992f40 100644
--- a/web/src/hash_util.ts
+++ b/web/src/hash_util.ts
@@ -19,7 +19,6 @@ import {
} from "./state_data.ts";
import type {NarrowCanonicalTerm, NarrowTerm} from "./state_data.ts";
import * as stream_data from "./stream_data.ts";
-import * as stream_topic_history from "./stream_topic_history.ts";
import * as sub_store from "./sub_store.ts";
import type {StreamSubscription} from "./sub_store.ts";
import * as user_groups from "./user_groups.ts";
@@ -110,29 +109,6 @@ export function by_stream_topic_url(stream_id: number, topic: string): string {
return internal_url.by_stream_topic_url(stream_id, topic, sub_store.maybe_get_stream_name);
}
-// We use the topic permalinks if we have access to the last message
-// id of the topic in the cache, by encoding it at the end of the
-// traditional channel-topic url using a `with` operator. If client
-// cache doesn't have a message, we use the traditional link format.
-export function by_channel_topic_permalink(stream_id: number, topic: string): string {
- // From an API perspective, any message ID in the topic is a valid
- // choice. In the client code, we choose the latest message ID in
- // the topic, since display in recent conversations, the left
- // sidebar, and most other elements are placed in a way reflecting
- // the recency of the latest message in the topic.
- const target_message_id = stream_topic_history.get_latest_known_message_id_in_topic(
- stream_id,
- topic,
- );
-
- return internal_url.by_stream_topic_url(
- stream_id,
- topic,
- sub_store.maybe_get_stream_name,
- target_message_id,
- );
-}
-
// Encodes a term list into the
// corresponding hash: the # component
// of the narrow URL
diff --git a/web/src/inbox_ui.ts b/web/src/inbox_ui.ts
index d21ef5ff9d6..db1e19db1a6 100644
--- a/web/src/inbox_ui.ts
+++ b/web/src/inbox_ui.ts
@@ -686,7 +686,7 @@ function format_topic(
is_empty_string_topic: topic === "",
unread_count: topic_unread_count,
conversation_key: get_topic_key(stream_id, topic),
- topic_url: hash_util.by_channel_topic_permalink(stream_id, topic),
+ topic_url: stream_topic_history.channel_topic_permalink_hash(stream_id, topic),
latest_msg_id,
mention_in_unread: unread.topic_has_any_unread_mentions(stream_id, topic),
// The 'all_visibility_policies' field is not specific to this context,
diff --git a/web/src/recent_view_ui.ts b/web/src/recent_view_ui.ts
index 5a461fb90c6..e2027534357 100644
--- a/web/src/recent_view_ui.ts
+++ b/web/src/recent_view_ui.ts
@@ -37,6 +37,7 @@ import * as recent_view_data from "./recent_view_data.ts";
import type {ConversationData} from "./recent_view_data.ts";
import * as recent_view_util from "./recent_view_util.ts";
import * as stream_data from "./stream_data.ts";
+import * as stream_topic_history from "./stream_topic_history.ts";
import * as sub_store from "./sub_store.ts";
import * as timerender from "./timerender.ts";
import * as typeahead from "./typeahead.ts";
@@ -674,7 +675,7 @@ function format_conversation(conversation_data: ConversationData): ConversationC
const topic = last_msg.topic;
const topic_display_name = util.get_final_topic_display_name(topic);
const is_empty_string_topic = topic === "";
- const topic_url = hash_util.by_channel_topic_permalink(stream_id, topic);
+ const topic_url = stream_topic_history.channel_topic_permalink_hash(stream_id, topic);
// We hide the row according to filters or if it's muted.
// We only supply the data to the topic rows and let jquery
diff --git a/web/src/stream_list.ts b/web/src/stream_list.ts
index 74bfe404f26..4ff73a53182 100644
--- a/web/src/stream_list.ts
+++ b/web/src/stream_list.ts
@@ -1306,7 +1306,7 @@ export function on_sidebar_channel_click(
if (stream_data.is_empty_topic_only_channel(stream_id)) {
// If the channel doesn't support topics, take you
// directly to general chat regardless of settings.
- const empty_topic_url = hash_util.by_channel_topic_permalink(stream_id, "");
+ const empty_topic_url = stream_topic_history.channel_topic_permalink_hash(stream_id, "");
browser_history.go_to_location(empty_topic_url);
return;
}
diff --git a/web/src/stream_topic_history.ts b/web/src/stream_topic_history.ts
index eb28aa81508..386a6e260b1 100644
--- a/web/src/stream_topic_history.ts
+++ b/web/src/stream_topic_history.ts
@@ -2,6 +2,7 @@ import assert from "minimalistic-assert";
import * as echo_state from "./echo_state.ts";
import {FoldDict} from "./fold_dict.ts";
+import * as internal_url from "./internal_url.ts";
import * as message_util from "./message_util.ts";
import * as resolved_topics from "./resolved_topic.ts";
import * as sub_store from "./sub_store.ts";
@@ -361,6 +362,26 @@ export function get_latest_known_message_id_in_topic(
return history?.topics.get(topic_name)?.message_id;
}
+// We use the topic permalinks if we have access to the last message
+// id of the topic in the cache, by encoding it at the end of the
+// traditional channel-topic url using a `with` operator. If client
+// cache doesn't have a message, we use the traditional link format.
+export function channel_topic_permalink_hash(stream_id: number, topic: string): string {
+ // From an API perspective, any message ID in the topic is a valid
+ // choice. In the client code, we choose the latest message ID in
+ // the topic, since display in recent conversations, the left
+ // sidebar, and most other elements are placed in a way reflecting
+ // the recency of the latest message in the topic.
+ const target_message_id = get_latest_known_message_id_in_topic(stream_id, topic);
+
+ return internal_url.by_stream_topic_url(
+ stream_id,
+ topic,
+ sub_store.maybe_get_stream_name,
+ target_message_id,
+ );
+}
+
export function reset(): void {
// This is only used by tests.
stream_dict.clear();
diff --git a/web/src/topic_list_data.ts b/web/src/topic_list_data.ts
index cfdd4c1c9ea..c8743c57d32 100644
--- a/web/src/topic_list_data.ts
+++ b/web/src/topic_list_data.ts
@@ -1,6 +1,5 @@
import assert from "minimalistic-assert";
-import * as hash_util from "./hash_util.ts";
import * as narrow_state from "./narrow_state.ts";
import * as resolved_topic from "./resolved_topic.ts";
import * as stream_topic_history from "./stream_topic_history.ts";
@@ -134,7 +133,7 @@ function choose_topics(
is_followed: is_topic_followed,
is_unmuted_or_followed: is_topic_unmuted_or_followed,
is_active_topic,
- url: hash_util.by_channel_topic_permalink(stream_id, topic_name),
+ url: stream_topic_history.channel_topic_permalink_hash(stream_id, topic_name),
contains_unread_mention,
};
diff --git a/web/src/topic_popover.ts b/web/src/topic_popover.ts
index 6cb0a0fdee4..2b5024ea8d5 100644
--- a/web/src/topic_popover.ts
+++ b/web/src/topic_popover.ts
@@ -7,7 +7,6 @@ import render_left_sidebar_topic_actions_popover from "../templates/popovers/lef
import * as clipboard_handler from "./clipboard_handler.ts";
import * as confirm_dialog from "./confirm_dialog.ts";
-import * as hash_util from "./hash_util.ts";
import {$t_html} from "./i18n.ts";
import * as message_delete from "./message_delete.ts";
import * as message_edit from "./message_edit.ts";
@@ -17,6 +16,7 @@ import * as popover_menus_data from "./popover_menus_data.ts";
import * as starred_messages_ui from "./starred_messages_ui.ts";
import {realm} from "./state_data.ts";
import * as stream_popover from "./stream_popover.ts";
+import * as stream_topic_history from "./stream_topic_history.ts";
import * as ui_util from "./ui_util.ts";
import * as unread_ops from "./unread_ops.ts";
import * as user_topics from "./user_topics.ts";
@@ -36,7 +36,10 @@ function get_conversation(instance: tippy.Instance): {
const $message_header = $elt.closest(".message_header").expectOne();
stream_id = Number.parseInt($message_header.attr("data-stream-id")!, 10);
topic_name = $message_header.attr("data-topic-name")!;
- const topic_narrow_url = hash_util.by_channel_topic_permalink(stream_id, topic_name);
+ const topic_narrow_url = stream_topic_history.channel_topic_permalink_hash(
+ stream_id,
+ topic_name,
+ );
url = new URL(topic_narrow_url, realm.realm_url).href;
} else if (!instance.reference.classList.contains("topic-sidebar-menu-icon")) {
const $elt = $(instance.reference);
diff --git a/web/tests/recent_view.test.cjs b/web/tests/recent_view.test.cjs
index 3a2d20b4682..eab3403dc47 100644
--- a/web/tests/recent_view.test.cjs
+++ b/web/tests/recent_view.test.cjs
@@ -101,9 +101,11 @@ mock_esm("../src/compose_closed_ui", {
mock_esm("../src/hash_util", {
channel_url_by_user_setting: test_url,
by_stream_topic_url: test_url,
- by_channel_topic_permalink: test_permalink,
by_conversation_and_time_url: test_url,
});
+mock_esm("../src/stream_topic_history", {
+ channel_topic_permalink_hash: test_permalink,
+});
mock_esm("../src/message_list_data", {
MessageListData: class {},
});