message_link: Add support for empty string topic in syntax.

This commit adds support for empty string as a valid topic name
in syntax for linking to channel messages.

The server stores it after empty string is replaced with
`realm_empty_topic_display_name` and wrapped with an <em> tag.

The web client parses the rendered_content and updates
the topic_name part in the HTML with topic_name in user's language
+ wraps it in a <span> tag with 'empty-topic-display' css class.
This commit is contained in:
Prakhar Pratyush
2025-01-28 22:01:25 +05:30
committed by Tim Abbott
parent 53dc5198c6
commit 0788942a68
11 changed files with 137 additions and 18 deletions

View File

@@ -143,7 +143,7 @@ const get_content_element = () => {
$content.set_find_results(".topic-mention", $array([]));
$content.set_find_results(".user-group-mention", $array([]));
$content.set_find_results("a.stream", $array([]));
$content.set_find_results("a.stream-topic", $array([]));
$content.set_find_results("a.stream-topic, a.message-link", $array([]));
$content.set_find_results("time", $array([]));
$content.set_find_results("span.timestamp-error", $array([]));
$content.set_find_results(".emoji", $array([]));
@@ -422,10 +422,11 @@ run_test("stream-links", ({mock_template}) => {
`/#narrow/channel/${stream.stream_id}-random/topic/topic.20name.20.3E.20still.20the.20topic.20name`,
);
$stream_topic.replaceWith = noop;
$stream_topic.hasClass = (class_name) => class_name === "stream-topic";
$stream_topic.text("#random > topic name > still the topic name");
$content.set_find_results("a.stream", $array([$stream]));
$content.set_find_results("a.stream-topic", $array([$stream_topic]));
$content.set_find_results("a.stream-topic, a.message-link", $array([$stream_topic]));
let topic_link_context;
let topic_link_rendered_html;
@@ -460,8 +461,9 @@ run_test("topic-link (empty string topic)", ({mock_template}) => {
$channel_topic.set_find_results(".highlight", false);
$channel_topic.attr("href", `/#narrow/channel/${stream.stream_id}-random/topic/`);
$channel_topic.replaceWith = noop;
$channel_topic.hasClass = (class_name) => class_name === "stream-topic";
$channel_topic.html(`#random &gt; <em>${REALM_EMPTY_TOPIC_DISPLAY_NAME}</em>`);
$content.set_find_results("a.stream-topic", $array([$channel_topic]));
$content.set_find_results("a.stream-topic, a.message-link", $array([$channel_topic]));
let topic_link_context;
let topic_link_rendered_html;
@@ -487,6 +489,45 @@ run_test("topic-link (empty string topic)", ({mock_template}) => {
assert.ok(topic_link_rendered_html.includes("empty-topic-display"));
});
run_test("message-links", ({mock_template}) => {
// Setup
const $content = get_content_element();
const $channel_topic_message = $.create("a.message-link");
$channel_topic_message.set_find_results(".highlight", false);
$channel_topic_message.attr(
"href",
`/#narrow/channel/${stream.stream_id}-${stream.name}/topic//near/123`,
);
$channel_topic_message.replaceWith = noop;
$channel_topic_message.hasClass = (class_name) => class_name === "message-link";
$channel_topic_message.html(
`#${stream.name} &gt; <em>${REALM_EMPTY_TOPIC_DISPLAY_NAME}</em> @ 💬`,
);
$content.set_find_results("a.stream-topic, a.message-link", $array([$channel_topic_message]));
let channel_message_link_context;
let channel_message_link_rendered_html;
mock_template("channel_message_link.hbs", true, (data, html) => {
channel_message_link_context = data;
channel_message_link_rendered_html = html;
return html;
});
// Initial assert
assert.equal($channel_topic_message.html(), "#test &gt; <em>general chat</em> @ 💬");
rm.update_elements($content);
// Final asserts
assert.deepEqual(channel_message_link_context, {
channel_name: stream.name,
topic_display_name: `translated: ${REALM_EMPTY_TOPIC_DISPLAY_NAME}`,
is_empty_string_topic: true,
href: `/#narrow/channel/${stream.stream_id}-test/topic//near/123`,
});
assert.ok(channel_message_link_rendered_html.includes("empty-topic-display"));
});
run_test("timestamp without time", () => {
const $content = get_content_element();
const $timestamp = $.create("timestamp without actual time");