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.

stream_type_icon: Render stream privacy icons in message references.

Aadyot19083c059e8a8
diff --git a/web/src/rendered_markdown.ts b/web/src/rendered_markdown.ts
index 46d39ab519b..90540328086 100644
--- a/web/src/rendered_markdown.ts
+++ b/web/src/rendered_markdown.ts
@@ -5,6 +5,7 @@ import assert from "minimalistic-assert";
import render_channel_message_link from "../templates/channel_message_link.hbs";
import code_buttons_container from "../templates/code_buttons_container.hbs";
+import render_decorated_channel_name from "../templates/decorated_channel_name.hbs";
import render_markdown_audio from "../templates/markdown_audio.hbs";
import render_markdown_timestamp from "../templates/markdown_timestamp.hbs";
import render_mention_content_wrapper from "../templates/mention_content_wrapper.hbs";
@@ -218,12 +219,12 @@ export const update_elements = ($content: JQuery): void => {
if (stream_id && $(this).find(".highlight").length === 0) {
// Display the current name for stream if it is not
// being displayed in search highlight.
- const stream_name = sub_store.maybe_get_stream_name(stream_id);
- if (stream_name !== undefined) {
- // If the stream has been deleted,
- // sub_store.maybe_get_stream_name might return
- // undefined. Otherwise, display the current stream name.
- $(this).text("#" + stream_name);
+ const sub = sub_store.get(stream_id);
+ if (sub !== undefined) {
+ // If the stream has been deleted, sub_store.get
+ // might return undefined. Otherwise, display the
+ // current stream name.
+ $(this).html(render_decorated_channel_name({stream: sub, inline_with_text: true}));
}
}
});
@@ -233,8 +234,8 @@ export const update_elements = ($content: JQuery): void => {
assert(narrow_url !== undefined);
const channel_topic = hash_util.decode_stream_topic_from_url(narrow_url);
assert(channel_topic !== null);
- const channel_name = sub_store.maybe_get_stream_name(channel_topic.stream_id);
- if (channel_name !== undefined && $(this).find(".highlight").length === 0) {
+ const sub = sub_store.get(channel_topic.stream_id);
+ if (sub !== undefined && $(this).find(".highlight").length === 0) {
// Display the current channel name if it hasn't been deleted
// and not being displayed in search highlight.
// TODO: Ideally, we should NOT skip this if only topic is highlighted,
@@ -243,7 +244,7 @@ export const update_elements = ($content: JQuery): void => {
assert(topic_name !== undefined);
const topic_display_name = util.get_final_topic_display_name(topic_name);
const context = {
- channel_name,
+ channel_name: sub.name,
topic_display_name,
is_empty_string_topic: topic_name === "",
href: narrow_url,
@@ -251,6 +252,7 @@ export const update_elements = ($content: JQuery): void => {
if ($(this).hasClass("stream-topic")) {
const topic_link_html = render_topic_link({
channel_id: channel_topic.stream_id,
+ stream: sub,
...context,
});
$(this).replaceWith($(topic_link_html));
diff --git a/web/styles/rendered_markdown.css b/web/styles/rendered_markdown.css
index 47ea1ab1195..b0963945894 100644
--- a/web/styles/rendered_markdown.css
+++ b/web/styles/rendered_markdown.css
@@ -334,8 +334,11 @@
}
.stream-topic {
- /* Display whitespace within topics. */
- white-space: pre-wrap;
+ /* Display whitespace within channel and topic names. */
+ .stream-topic-inner,
+ .decorated-channel-name {
+ white-space: pre;
+ }
}
.user-group-mention {
diff --git a/web/templates/topic_link.hbs b/web/templates/topic_link.hbs
index 46bc8e2fb07..9db585d8c97 100644
--- a/web/templates/topic_link.hbs
+++ b/web/templates/topic_link.hbs
@@ -1,13 +1,21 @@
{{#if is_empty_string_topic}}
<a class="stream-topic" data-stream-id="{{channel_id}}" href="{{href}}">
{{~!-- squash whitespace --~}}
- #{{channel_name}} &gt; <span class="empty-topic-display">{{topic_display_name}}</span>
+ {{#if stream~}}
+ {{~> decorated_channel_name stream=stream inline_with_text=true show_colored_icon=false}}
+ {{~else~}}
+ #{{channel_name}}
+ {{~/if}} &gt; <span class="empty-topic-display">{{topic_display_name}}</span>
{{~!-- squash whitespace --~}}
</a>
{{~else}}
<a class="stream-topic" data-stream-id="{{channel_id}}" href="{{href}}">
{{~!-- squash whitespace --~}}
- #{{channel_name}} &gt; {{topic_display_name}}
+ {{#if stream~}}
+ {{~> decorated_channel_name stream=stream inline_with_text=true show_colored_icon=false}}
+ {{~else~}}
+ #{{channel_name}}
+ {{~/if}} &gt; {{topic_display_name}}
{{~!-- squash whitespace --~}}
</a>
{{~/if}}
diff --git a/web/tests/rendered_markdown.test.cjs b/web/tests/rendered_markdown.test.cjs
index 374eaa772ec..c1551c412af 100644
--- a/web/tests/rendered_markdown.test.cjs
+++ b/web/tests/rendered_markdown.test.cjs
@@ -420,6 +420,12 @@ run_test("stream-links", ({mock_template}) => {
$content.set_find_results("a.stream", $stream);
$content.set_find_results("a.stream-topic, a.message-link", $stream_topic);
+ let stream_name_context;
+ mock_template("decorated_channel_name.hbs", true, (data, html) => {
+ stream_name_context = data;
+ return html;
+ });
+
let topic_link_context;
let topic_link_rendered_html;
mock_template("topic_link.hbs", true, (data, html) => {
@@ -434,10 +440,14 @@ run_test("stream-links", ({mock_template}) => {
rm.update_elements($content);
- // Final asserts
- assert.equal($stream.text(), `#${stream.name}`);
+ // Verify decorated_channel_name was called with the correct stream.
+ assert.ok(stream_name_context, "decorated_channel_name should be called");
+ assert.equal(stream_name_context.stream.stream_id, stream.stream_id);
+ assert.equal(stream_name_context.stream.name, stream.name);
+
assert.deepEqual(topic_link_context, {
channel_id: stream.stream_id,
+ stream,
channel_name: stream.name,
topic_display_name: "topic name > still the topic name",
is_empty_string_topic: false,
@@ -473,6 +483,7 @@ run_test("topic-link (empty string topic)", ({mock_template}) => {
// Final assert
assert.deepEqual(topic_link_context, {
channel_id: stream.stream_id,
+ stream,
channel_name: stream.name,
topic_display_name: `translated: ${REALM_EMPTY_TOPIC_DISPLAY_NAME}`,
is_empty_string_topic: true,
@@ -811,6 +822,153 @@ run_test("code playground multiple", ({override, mock_template}) => {
assert.equal($view_code.attr("aria-haspopup"), "true");
});
+run_test("stream-private", ({mock_template}) => {
+ // Setup
+ const private_stream = {
+ stream_id: 88,
+ name: "secret-stream",
+ invite_only: true,
+ is_web_public: false,
+ is_archived: false,
+ };
+ stream_data.add_sub_for_tests(private_stream);
+
+ const $content = get_content_element();
+ const $stream = $.create("a.stream");
+ $stream.attr("data-stream-id", private_stream.stream_id);
+ $stream.set_find_results(".highlight", []);
+
+ const $topic = $.create("a.stream-topic");
+ $topic.attr("href", `/#narrow/channel/${private_stream.stream_id}-secret-stream/topic/test`);
+ $topic.set_find_results(".highlight", []);
+ $topic.addClass("stream-topic");
+ $topic[0].replaceWith = noop;
+
+ $content.set_find_results("a.stream", $stream);
+ $content.set_find_results("a.stream-topic, a.message-link", $topic);
+
+ let stream_name_context;
+ mock_template("decorated_channel_name.hbs", true, (data, html) => {
+ stream_name_context = data;
+ return html;
+ });
+
+ let topic_link_context;
+ mock_template("topic_link.hbs", true, (data, html) => {
+ topic_link_context = data;
+ return html;
+ });
+
+ rm.update_elements($content);
+
+ // Verify decorated_channel_name was called with the private stream.
+ assert.ok(stream_name_context, "decorated_channel_name should be called");
+ assert.ok(stream_name_context.stream.invite_only, "Stream should be private");
+
+ // Verify topic_link was called with the private stream.
+ assert.ok(topic_link_context, "topic_link should be called");
+ assert.ok(topic_link_context.stream.invite_only, "Topic stream should be private");
+});
+
+run_test("stream-web-public", ({mock_template}) => {
+ // Setup
+ const web_public_stream = {
+ stream_id: 99,
+ name: "web-public-stream",
+ invite_only: false,
+ is_web_public: true,
+ is_archived: false,
+ };
+ stream_data.add_sub_for_tests(web_public_stream);
+
+ const $content = get_content_element();
+ const $stream = $.create("a.stream");
+ $stream.attr("data-stream-id", web_public_stream.stream_id);
+ $stream.set_find_results(".highlight", []);
+
+ const $topic = $.create("a.stream-topic");
+ $topic.attr(
+ "href",
+ `/#narrow/channel/${web_public_stream.stream_id}-web-public-stream/topic/test`,
+ );
+ $topic.set_find_results(".highlight", []);
+ $topic.addClass("stream-topic");
+ $topic[0].replaceWith = noop;
+
+ $content.set_find_results("a.stream", $stream);
+ $content.set_find_results("a.stream-topic, a.message-link", $topic);
+
+ let stream_name_context;
+ mock_template("decorated_channel_name.hbs", true, (data, html) => {
+ stream_name_context = data;
+ return html;
+ });
+
+ let topic_link_context;
+ mock_template("topic_link.hbs", true, (data, html) => {
+ topic_link_context = data;
+ return html;
+ });
+
+ rm.update_elements($content);
+
+ // Verify decorated_channel_name was called with the web-public stream.
+ assert.ok(stream_name_context, "decorated_channel_name should be called");
+ assert.ok(stream_name_context.stream.is_web_public, "Stream should be web-public");
+
+ // Verify topic_link was called with the web-public stream.
+ assert.ok(topic_link_context, "topic_link should be called");
+ assert.ok(topic_link_context.stream.is_web_public, "Topic stream should be web-public");
+});
+
+run_test("stream-archived", ({mock_template}) => {
+ // Setup
+ const archived_stream = {
+ stream_id: 77,
+ name: "old-stream",
+ invite_only: false,
+ is_web_public: false,
+ is_archived: true,
+ };
+ stream_data.add_sub_for_tests(archived_stream);
+
+ const $content = get_content_element();
+ const $stream = $.create("a.stream");
+ $stream.attr("data-stream-id", archived_stream.stream_id);
+ $stream.set_find_results(".highlight", []);
+
+ const $topic = $.create("a.stream-topic");
+ $topic.attr("href", `/#narrow/channel/${archived_stream.stream_id}-old-stream/topic/test`);
+ $topic.set_find_results(".highlight", []);
+ $topic.addClass("stream-topic");
+ $topic[0].replaceWith = noop;
+
+ $content.set_find_results("a.stream", $stream);
+ $content.set_find_results("a.stream-topic, a.message-link", $topic);
+
+ let stream_name_context;
+ mock_template("decorated_channel_name.hbs", true, (data, html) => {
+ stream_name_context = data;
+ return html;
+ });
+
+ let topic_link_context;
+ mock_template("topic_link.hbs", true, (data, html) => {
+ topic_link_context = data;
+ return html;
+ });
+
+ rm.update_elements($content);
+
+ // Verify decorated_channel_name was called with the archived stream.
+ assert.ok(stream_name_context, "decorated_channel_name should be called");
+ assert.ok(stream_name_context.stream.is_archived, "Stream should be archived");
+
+ // Verify topic_link was called with the archived stream.
+ assert.ok(topic_link_context, "topic_link should be called");
+ assert.ok(topic_link_context.stream.is_archived, "Topic stream should be archived");
+});
+
run_test("rtl", () => {
const $content = get_content_element();