Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
compose_reply: Use new channel syntax in forwarded message context.
sandeep045bd6c1c334
diff --git a/web/src/compose_reply.ts b/web/src/compose_reply.tsindex 4b358ce44b3..5762169cbf9 100644--- a/web/src/compose_reply.ts+++ b/web/src/compose_reply.ts@@ -13,7 +13,6 @@ import * as hash_util from "./hash_util.ts";import {$t} from "./i18n.ts";import * as inbox_ui from "./inbox_ui.ts";import * as inbox_util from "./inbox_util.ts";-import * as internal_url from "./internal_url.ts";import * as message_fetch_raw_content from "./message_fetch_raw_content.ts";import * as message_lists from "./message_lists.ts";import * as message_store from "./message_store.ts";@@ -377,20 +376,14 @@ function generate_sender_only_quote_context(message: Message): string {function generate_channel_message_quote_context(message: Message): string {assert(message.type === "stream");const sender_mention = generate_sender_mention(message);- const topic_url = internal_url.by_stream_topic_url(- message.stream_id,- message.topic,- sub_store.maybe_get_stream_name,- message.id,- );const channel_name = sub_store.maybe_get_stream_name(message.stream_id)!;- const topic_link_text = topic_link_util.get_stream_topic_link_syntax(+ const topic_link = topic_link_util.get_stream_topic_link_syntax(channel_name,message.topic,- true,+ message.id.toString(),);// Final message looks like:- // @_**Iago|5** [said](link to message) in [#channel > topic](topic URL):+ // @_**Iago|5** [said](link to message) in #**channel>topic**:// ```quote// message content// ```@@ -402,7 +395,7 @@ function generate_channel_message_quote_context(message: Message): string {{username: sender_mention,link_to_message: hash_util.by_conversation_and_time_url(message),- topic_link: topic_link_util.as_markdown_link_syntax(topic_link_text, topic_url),+ topic_link,},);}diff --git a/web/src/topic_link_util.ts b/web/src/topic_link_util.tsindex 109e495084d..33445b80fe7 100644--- a/web/src/topic_link_util.ts+++ b/web/src/topic_link_util.ts@@ -126,7 +126,6 @@ export function get_fallback_markdown_link(stream_name: string,topic_name?: string,message_id?: string,- only_link_text = false,): string {// Helper that should only be called by other methods in this file.@@ -138,25 +137,30 @@ export function get_fallback_markdown_link(topic_name,message_id,});- return only_link_text ? label_text_markdown : as_markdown_link_syntax(label_text_markdown, url);+ return as_markdown_link_syntax(label_text_markdown, url);}export function get_stream_topic_link_syntax(stream_name: string,topic_name: string,- only_link_text = false,+ message_id?: string,): string {// If the topic/stream name would produce an invalid #**stream>topic** syntax, fall back- // to markdown link syntax. If only_link_text is true, only the link label is returned.+ // to markdown link syntax.if (will_produce_broken_stream_topic_link(topic_name) ||will_produce_broken_stream_topic_link(stream_name)) {- return get_fallback_markdown_link(stream_name, topic_name, undefined, only_link_text);- }-- if (only_link_text) {- return `#${stream_name} > ${topic_name}`;+ if (message_id !== undefined) {+ const stream = stream_data.get_sub(stream_name);+ assert(stream !== undefined);+ const stream_topic_url = hash_util.by_stream_topic_url(stream.stream_id, topic_name);+ const topic_display_name = util.get_final_topic_display_name(topic_name);+ const escape = html_escape_markdown_syntax_characters;+ const label = `#${escape(stream_name)} > ${escape(topic_display_name)}`;+ return as_markdown_link_syntax(label, `${stream_topic_url}/with/${message_id}`);+ }+ return get_fallback_markdown_link(stream_name, topic_name);}return `#**${stream_name}>${topic_name}**`;}diff --git a/web/tests/compose_actions.test.cjs b/web/tests/compose_actions.test.cjsindex 4c08d501edf..b1da228502e 100644--- a/web/tests/compose_actions.test.cjs+++ b/web/tests/compose_actions.test.cjs@@ -907,8 +907,9 @@ test("quote_messages", ({disallow, override, override_rewire}) => {const url_encoded_topic_name = ".5Bzulip.2Fzulip.3Etopic.5D";const near_url = `http://zulip.zulipdev.com/#narrow/channel/${selected_message.stream_id}-${channel_object.name}/topic/${url_encoded_topic_name}/near/${selected_message.id}`;- const with_url = `#narrow/channel/${selected_message.stream_id}-${channel_object.name}/topic/${url_encoded_topic_name}/with/${selected_message.id}`;- const topic_link_syntax = `[#${channel_object.name} > ${html_entity_encoded_topic_name}](${with_url})`;+ const fallback_stream_id = stream_data.get_stream_id(channel_object.name);+ const fallback_url = `#narrow/channel/${fallback_stream_id}-${channel_object.name}/topic/${url_encoded_topic_name}/with/${selected_message.id}`;+ const topic_link_syntax = `[#${channel_object.name} > ${html_entity_encoded_topic_name}](${fallback_url})`;const fence = "```";expected_replacement = `translated: @_**${selected_message.sender_full_name}|${selected_message.sender_id}** [said](${near_url}) in ${topic_link_syntax}:diff --git a/web/tests/lib/compose_helpers.cjs b/web/tests/lib/compose_helpers.cjsindex 818b650db59..9433f019050 100644--- a/web/tests/lib/compose_helpers.cjs+++ b/web/tests/lib/compose_helpers.cjs@@ -188,8 +188,7 @@ function forward_channel_message_template(opts) {const channel_name = name;const {sender_full_name, sender_id, id, topic} = selected_message;const near_url = `http://zulip.zulipdev.com/#narrow/channel/${stream_id}-${channel_name}/topic/${topic}/near/${id}`;- const with_url = `#narrow/channel/${stream_id}-${channel_name}/topic/${topic}/with/${id}`;- const topic_link = `[#${channel_name} > ${topic}](${with_url})`;+ const topic_link = `#**${channel_name}>${topic}**`;return `translated: @_**${sender_full_name}|${sender_id}** [said](${near_url}) in ${topic_link}:${fence}quote${content}