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.

topic_link_util: Add support for empty topics in the frontend.

Kislay Verma1ece5ad15e96
diff --git a/web/src/topic_link_util.ts b/web/src/topic_link_util.ts
index 4502ba74cc3..cac23899de6 100644
--- a/web/src/topic_link_util.ts
+++ b/web/src/topic_link_util.ts
@@ -4,6 +4,7 @@ import assert from "minimalistic-assert";
import * as hash_util from "./hash_util.ts";
import * as stream_data from "./stream_data.ts";
+import * as util from "./util.ts";
const invalid_stream_topic_regex = /[`>*&[\]]|(\$\$)/g;
@@ -64,14 +65,15 @@ export function get_topic_link_content(
const escape = html_escape_markdown_syntax_characters;
if (topic_name !== undefined) {
const stream_topic_url = hash_util.by_stream_topic_url(stream_id, topic_name);
+ const topic_display_name = util.get_final_topic_display_name(topic_name);
if (message_id !== undefined) {
return {
- text: `#${escape(stream_name)} > ${escape(topic_name)} @ 💬`,
+ text: `#${escape(stream_name)} > ${escape(topic_display_name)} @ 💬`,
url: `${stream_topic_url}/near/${message_id}`,
};
}
return {
- text: `#${escape(stream_name)} > ${escape(topic_name)}`,
+ text: `#${escape(stream_name)} > ${escape(topic_display_name)}`,
url: stream_topic_url,
};
}
diff --git a/web/tests/topic_link_util.test.cjs b/web/tests/topic_link_util.test.cjs
index d30faaf0aae..54924327937 100644
--- a/web/tests/topic_link_util.test.cjs
+++ b/web/tests/topic_link_util.test.cjs
@@ -13,6 +13,9 @@ mock_esm("../src/user_settings", {
web_channel_default_view: settings_config.web_channel_default_view_values.channel_feed.code,
},
});
+mock_esm("../src/state_data", {
+ realm: {realm_empty_topic_display_name: "general chat"},
+});
const sweden_stream = {
name: "Sweden",
@@ -125,6 +128,23 @@ run_test("stream_topic_link_syntax_test", () => {
"[#Sweden > &a[b](#narrow/channel/1-Sweden/topic/.26a.5Bb)",
);
+ assert.equal(topic_link_util.get_stream_topic_link_syntax("Sweden", ""), "#**Sweden>**");
+
+ assert.equal(
+ topic_link_util.get_stream_topic_link_syntax("$$MONEY$$", ""),
+ "[#$$MONEY$$ > translated: general chat](#narrow/channel/6-.24.24MONEY.24.24/topic/)",
+ );
+
+ assert.equal(
+ topic_link_util.get_fallback_markdown_link("Sweden", "abc", 123),
+ "[#Sweden > abc @ 💬](#narrow/channel/1-Sweden/topic/abc/near/123)",
+ );
+
+ assert.equal(
+ topic_link_util.get_fallback_markdown_link("Sweden", "", 123),
+ "[#Sweden > translated: general chat @ 💬](#narrow/channel/1-Sweden/topic//near/123)",
+ );
+
// Only for full coverage of the module.
assert.equal(topic_link_util.escape_invalid_stream_topic_characters("Sweden"), "Sweden");
assert.equal(