Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
messages: Add muted user avatar and user name.
apoorvapendse073f830609da
diff --git a/static/images/muted-user/muted-sender.png b/static/images/muted-user/muted-sender.pngnew file mode 100644index 00000000000..cb020f0906fBinary files /dev/null and b/static/images/muted-user/muted-sender.png differdiff --git a/web/src/message_list_view.ts b/web/src/message_list_view.tsindex 7cd672d10c4..bf725fd7e69 100644--- a/web/src/message_list_view.ts+++ b/web/src/message_list_view.ts@@ -601,7 +601,7 @@ export class MessageListView {/*If the message needs to be hidden because the sender was muted, we doa few things:- 1. Hide the sender avatar and name.+ 1. Replace the sender's avatar with that of a muted sender and name them as "Muted sender".2. Hide reactions on that message.3. Do not give a background color to that message even if it mentions thecurrent user.@@ -648,7 +648,7 @@ export class MessageListView {} else {mention_classname = undefined;}- let include_sender = existing_include_sender && !is_hidden;+ let include_sender = existing_include_sender;if (is_revealed) {// If the message is to be revealed, we show the sender anyways, because the// the first message in the group (which would hold the sender) can still be@@ -663,7 +663,9 @@ export class MessageListView {message.sender_id,);- const small_avatar_url = people.small_avatar_url(message);+ const small_avatar_url = is_hidden+ ? people.get_muted_user_avatar_url()+ : people.small_avatar_url(message);let background_color;if (message.type === "stream") {background_color = stream_data.get_color(message.stream_id);diff --git a/web/src/people.ts b/web/src/people.tsindex b69a37f832f..437575a4455 100644--- a/web/src/people.ts+++ b/web/src/people.ts@@ -1052,6 +1052,10 @@ export function small_avatar_url(message: Message): string {return gravatar_url_for_email(email);}+export function get_muted_user_avatar_url(): string {+ return "/static/images/muted-user/muted-sender.png";+}+export function is_valid_user_id_for_compose(user_id: number): boolean {if (cross_realm_dict.has(user_id)) {return true;diff --git a/web/styles/message_row.css b/web/styles/message_row.cssindex c59c2b7207f..2fed6e1376b 100644--- a/web/styles/message_row.css+++ b/web/styles/message_row.css@@ -55,6 +55,16 @@}}+ &.muted-message-sender {+ .sender_info_hover {+ pointer-events: none;+ }++ .inline-profile-picture-wrapper {+ pointer-events: none;+ }+ }+&.sender_info_hovered {.sender_name {cursor: pointer;@@ -411,6 +421,10 @@grid. */margin-top: var(--message-box-vertical-margin);}++ .muted-sender-avatar {+ opacity: 0.5;+ }}.status-message {@@ -493,6 +507,12 @@overflow: hidden;text-overflow: ellipsis;}++ .muted {+ opacity: 0.5;+ user-select: none;+ cursor: default;+ }}}}diff --git a/web/templates/message_avatar.hbs b/web/templates/message_avatar.hbsindex f857942ba69..7954aac82b0 100644--- a/web/templates/message_avatar.hbs+++ b/web/templates/message_avatar.hbs@@ -1,6 +1,6 @@-<div class="u-{{msg/sender_id}} message-avatar sender_info_hover view_user_card_tooltip no-select" aria-hidden="true" data-is-bot="{{sender_is_bot}}">+<div class="u-{{msg/sender_id}} message-avatar {{#unless is_hidden}}sender_info_hover view_user_card_tooltip{{/unless}} no-select" aria-hidden="true" data-is-bot="{{sender_is_bot}}"><div class="inline-profile-picture-wrapper">- <div class="inline_profile_picture {{#if sender_is_guest}} guest-avatar{{/if}} {{#if sender_is_deactivated}} deactivated {{/if}}">+ <div class="inline_profile_picture {{#if sender_is_guest}} guest-avatar{{/if}} {{#if sender_is_deactivated}} deactivated {{/if}} {{#if is_hidden}} muted-sender-avatar {{/if}}"><img loading="lazy" src="{{small_avatar_url}}" alt="" class="no-drag"/>{{#if sender_is_deactivated}}<i class="fa fa-ban deactivated-user-icon"></i>diff --git a/web/templates/message_body.hbs b/web/templates/message_body.hbsindex 7f49cace1d6..336a25461a7 100644--- a/web/templates/message_body.hbs+++ b/web/templates/message_body.hbs@@ -4,8 +4,8 @@<span class="message_sender">{{#if include_sender}}<span class="sender_info_hover sender_name" role="button" tabindex="0">- <span class="view_user_card_tooltip sender_name_text" data-is-bot="{{sender_is_bot}}">- {{> user_full_name name=msg/sender_full_name should_add_guest_user_indicator=should_add_guest_indicator_for_sender}}+ <span class="{{#unless is_hidden}}view_user_card_tooltip{{/unless}} sender_name_text" data-is-bot="{{sender_is_bot}}">+ {{> user_full_name name=msg/sender_full_name should_add_guest_user_indicator=should_add_guest_indicator_for_sender is_hidden=is_hidden}}</span>{{#unless status_message}}{{> status_emoji msg/status_emoji_info}}diff --git a/web/templates/single_message.hbs b/web/templates/single_message.hbsindex f0b44e8230a..81c6925a667 100644--- a/web/templates/single_message.hbs+++ b/web/templates/single_message.hbs@@ -1,5 +1,5 @@<div id="message-row-{{message_list_id}}-{{msg/id}}" data-message-id="{{msg/id}}"- class="message_row{{#unless msg/is_stream}} private-message{{/unless}}{{#if include_sender}} messagebox-includes-sender{{/if}}{{#if mention_classname}} {{mention_classname}}{{/if}}{{#if msg.unread}} unread{{/if}} {{#if msg.locally_echoed}}locally-echoed{{/if}} selectable_row"+ class="message_row{{#unless msg/is_stream}} private-message{{/unless}}{{#if include_sender}} messagebox-includes-sender{{/if}}{{#if mention_classname}} {{mention_classname}}{{/if}}{{#if msg.unread}} unread{{/if}} {{#if msg.locally_echoed}}locally-echoed{{/if}} selectable_row {{#if is_hidden}}muted-message-sender{{/if}}"role="listitem">{{#if want_date_divider}}<div class="unread_marker date_unread_marker"><div class="unread-marker-fill"></div></div>diff --git a/web/templates/user_full_name.hbs b/web/templates/user_full_name.hbsindex f6b1bacd17f..63a2925f3c3 100644--- a/web/templates/user_full_name.hbs+++ b/web/templates/user_full_name.hbs@@ -1,6 +1,9 @@{{#if should_add_guest_user_indicator}}<span class="user-name">{{name}}</span> <i class="guest-indicator">({{t 'guest' }})</i>{{else}}+{{#if is_hidden}}<span class="user-name muted">{{t 'Muted user'}}</span>+{{else}}<span class="user-name">{{name}}</span>{{/if}}+{{/if}}{{#if is_current_user}} <span class="my_user_status">{{t '(you)'}}</span>{{/if}}diff --git a/web/tests/message_list_view.test.cjs b/web/tests/message_list_view.test.cjsindex acc30e127f2..a6401574ce1 100644--- a/web/tests/message_list_view.test.cjs+++ b/web/tests/message_list_view.test.cjs@@ -26,6 +26,7 @@ mock_esm("../src/people", {sender_is_deactivated: () => false,should_add_guest_user_indicator: () => false,small_avatar_url: () => "fake/small/avatar/url",+ get_muted_user_avatar_url: () => "fake/muted_user/avatar/url",maybe_get_user_by_id: noop,});@@ -310,15 +311,18 @@ test("muted_message_vars", () => {muted_users.add_muted_user(10);result = calculate_variables(list, messages);- // Check that `is_hidden` is true and `include_sender` is false on all messages.+ // Check that `is_hidden` is true on all messages and `include_sender` is true for the first one.assert.equal(result[0].is_hidden, true);assert.equal(result[1].is_hidden, true);assert.equal(result[2].is_hidden, true);- assert.equal(result[0].include_sender, false);+ assert.equal(result[0].include_sender, true);assert.equal(result[1].include_sender, false);assert.equal(result[2].include_sender, false);+ // Ensure that `small_avatar_url` is the Muted sender avatar URL.+ assert.equal(result[0].small_avatar_url, "fake/muted_user/avatar/url");+// Additionally test that, both there is no mention classname even on that message// which has a mention, since we don't want to display muted mentions so visibly.assert.equal(result[1].mention_classname, undefined);@@ -336,6 +340,9 @@ test("muted_message_vars", () => {assert.equal(result[1].include_sender, true);assert.equal(result[2].include_sender, true);+ // Ensure that `small_avatar_url` is now set to the sender's avatar URL.+ assert.equal(result[0].small_avatar_url, "fake/small/avatar/url");+// Additionally test that the message with a mention is marked as such.assert.equal(result[1].mention_classname, "group_mention");@@ -343,14 +350,19 @@ test("muted_message_vars", () => {is_revealed = false;result = calculate_variables(list, messages, is_revealed);- // Check that `is_hidden` is false and `include_sender` is false on all messages.+ // Check that `is_hidden` is true and `include_sender` is true on all messages.assert.equal(result[0].is_hidden, true);assert.equal(result[1].is_hidden, true);assert.equal(result[2].is_hidden, true);- assert.equal(result[0].include_sender, false);- assert.equal(result[1].include_sender, false);- assert.equal(result[2].include_sender, false);+ assert.equal(result[0].include_sender, true);+ assert.equal(result[1].include_sender, true);+ assert.equal(result[2].include_sender, true);++ // Ensure that `small_avatar_url` is the Muted sender avatar URL.+ assert.equal(result[0].small_avatar_url, "fake/muted_user/avatar/url");+ assert.equal(result[1].small_avatar_url, "fake/muted_user/avatar/url");+ assert.equal(result[2].small_avatar_url, "fake/muted_user/avatar/url");// Additionally test that, both there is no mention classname even on that message// which has a mention, since we don't want to display hidden mentions so visibly.diff --git a/web/tests/people.test.cjs b/web/tests/people.test.cjsindex 6bf4974c08d..f40ca1a0644 100644--- a/web/tests/people.test.cjs+++ b/web/tests/people.test.cjs@@ -1004,6 +1004,7 @@ run_test("message_methods", () => {people.add_active_user(leo);people.add_active_user(ashton);+ assert.equal(people.get_muted_user_avatar_url(), "/static/images/muted-user/muted-sender.png");// We don't rely on Maria to have all flags set explicitly--// undefined values are just treated as falsy.assert.equal(maria.is_guest, undefined);