Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
compose-closed-ui: Use specific button label when composing to self.
Harshc8763f919ff4
diff --git a/web/src/compose_closed_ui.ts b/web/src/compose_closed_ui.tsindex 961366eea73..697f131fba5 100644--- a/web/src/compose_closed_ui.ts+++ b/web/src/compose_closed_ui.ts@@ -20,6 +20,7 @@ type RecipientLabel = {label_text: string;has_empty_string_topic?: boolean;stream_name?: string;+ is_dm_with_self?: boolean;};function get_stream_recipient_label(stream_id: number, topic: string): RecipientLabel | undefined {@@ -36,9 +37,25 @@ function get_stream_recipient_label(stream_id: number, topic: string): Recipientreturn undefined;}+function get_direct_message_recipient_label(user_ids: number[]): RecipientLabel {+ let label_text = "";+ let is_dm_with_self = false;+ if (people.is_direct_message_conversation_with_self(user_ids)) {+ is_dm_with_self = true;+ } else {+ label_text = message_store.get_pm_full_names(user_ids);+ }+ const recipient_label: RecipientLabel = {+ label_text,+ is_dm_with_self,+ };+ return recipient_label;+}+export type ReplyRecipientInformation = {stream_id?: number | undefined;topic?: string | undefined;+ user_ids?: number[] | undefined;display_reply_to?: string | undefined;};@@ -60,6 +77,9 @@ export function get_recipient_label(recipient_information.topic,);}+ if (recipient_information.user_ids !== undefined) {+ return get_direct_message_recipient_label(recipient_information.user_ids);+ }if (recipient_information.display_reply_to !== undefined) {return {label_text: recipient_information.display_reply_to};}@@ -83,7 +103,7 @@ export function get_recipient_label(}if (user_ids_string !== undefined) {const user_ids = people.user_ids_string_to_ids_array(user_ids_string);- return {label_text: message_store.get_pm_full_names(user_ids)};+ return get_direct_message_recipient_label(user_ids);}// Show the standard button text for empty narrows without// a clear reply target, e.g., an empty search view.@@ -95,7 +115,8 @@ export function get_recipient_label(if (selected_message?.is_stream) {return get_stream_recipient_label(selected_message.stream_id, selected_message.topic);}- return {label_text: selected_message.display_reply_to};+ const user_ids = people.user_ids_string_to_ids_array(selected_message.to_user_ids);+ return get_direct_message_recipient_label(user_ids);}// Fall through to show the standard button text.return undefined;@@ -205,6 +226,7 @@ export function update_recipient_text_for_reply_button(const rendered_recipient_label = render_reply_recipient_label({has_empty_string_topic: recipient_label.has_empty_string_topic,channel_name: recipient_label.stream_name,+ is_dm_with_self: recipient_label.is_dm_with_self,empty_string_topic_display_name,label_text: recipient_label.label_text,});diff --git a/web/src/hash_util.ts b/web/src/hash_util.tsindex 261cd8b79de..21f3a6846b7 100644--- a/web/src/hash_util.ts+++ b/web/src/hash_util.ts@@ -319,6 +319,39 @@ export function validate_group_settings_hash(hash: string): string {return hash;}+export function decode_dm_recipient_user_ids_from_narrow_url(narrow_url: string): number[] | null {+ try {+ const url = new URL(narrow_url, window.location.origin);+ if (url.origin !== window.location.origin || !url.hash.startsWith("#narrow")) {+ return null;+ }+ const terms = parse_narrow(url.hash.split(/\//));+ if (!terms?.[0]) {+ return null;+ }+ if (terms.length > 2) {+ return null;+ }+ if (+ terms[0].operator !== "dm" &&+ terms[1]?.operator !== "with" &&+ terms[1]?.operator !== "near"+ ) {+ return null;+ }+ if (people.is_valid_bulk_emails_for_compose(terms[0].operand.split(","))) {+ const user_ids = people.emails_strings_to_user_ids_array(terms[0].operand);+ if (!user_ids) {+ return null;+ }+ return user_ids;+ }+ return null;+ } catch {+ return null;+ }+}+export function decode_stream_topic_from_url(url_str: string,): {stream_id: number; topic_name?: string; message_id?: string} | null {diff --git a/web/src/inbox_ui.ts b/web/src/inbox_ui.tsindex 1875a21ee52..c3191a81801 100644--- a/web/src/inbox_ui.ts+++ b/web/src/inbox_ui.ts@@ -890,9 +890,19 @@ function update_closed_compose_text($row: JQuery, is_header_row: boolean): voidlet reply_recipient_information: compose_closed_ui.ReplyRecipientInformation;const is_dm = $row.parent("#inbox-direct-messages-container").length > 0;if (is_dm) {- reply_recipient_information = {- display_reply_to: $row.find(".recipients_name").text(),- };+ const $recipients_info = $row.find(".recipients_info");+ const narrow_url = $recipients_info.attr("href");+ assert(narrow_url !== undefined);+ const recipient_ids = hash_util.decode_dm_recipient_user_ids_from_narrow_url(narrow_url);+ if (recipient_ids) {+ reply_recipient_information = {+ user_ids: recipient_ids,+ };+ } else {+ reply_recipient_information = {+ display_reply_to: $recipients_info.text(),+ };+ }} else {const $stream = $row.parent(".inbox-topic-container").prev(".inbox-header");reply_recipient_information = {diff --git a/web/src/recent_view_ui.ts b/web/src/recent_view_ui.tsindex b858f4cb238..f0b9f911e36 100644--- a/web/src/recent_view_ui.ts+++ b/web/src/recent_view_ui.ts@@ -347,9 +347,19 @@ function set_table_focus(row: number, col: number, using_keyboard = false): boollet reply_recipient_information: compose_closed_ui.ReplyRecipientInformation;if (type === "private") {- reply_recipient_information = {- display_reply_to: $topic_row.find(".recent_topic_name a").text(),- };+ const $recipients_info = $topic_row.find(".recent-view-table-link");+ const narrow_url = $recipients_info.attr("href");+ assert(narrow_url !== undefined);+ const recipient_ids = hash_util.decode_dm_recipient_user_ids_from_narrow_url(narrow_url);+ if (recipient_ids) {+ reply_recipient_information = {+ user_ids: recipient_ids,+ };+ } else {+ reply_recipient_information = {+ display_reply_to: $recipients_info.text(),+ };+ }} else {const stream_name = $topic_row.find(".recent_topic_stream a").text();const stream = stream_data.get_sub_by_name(stream_name);diff --git a/web/templates/reply_recipient_label.hbs b/web/templates/reply_recipient_label.hbsindex a6dc45acc0e..da202e3314a 100644--- a/web/templates/reply_recipient_label.hbs+++ b/web/templates/reply_recipient_label.hbs@@ -1,3 +1,8 @@+{{#if is_dm_with_self}}+{{#tr}}+ Message yourself+{{/tr}}+{{else}}{{#tr}}Message <z-recipient-label></z-recipient-label>{{#*inline "z-recipient-label"}}@@ -8,3 +13,4 @@{{~/if}}{{~/inline}}{{/tr}}+{{/if}}diff --git a/web/tests/compose_closed_ui.test.cjs b/web/tests/compose_closed_ui.test.cjsindex 440aaa3c378..bbe42f81a10 100644--- a/web/tests/compose_closed_ui.test.cjs+++ b/web/tests/compose_closed_ui.test.cjs@@ -22,23 +22,38 @@ function MessageListView() {mock_esm("../src/message_list_view", {MessageListView,});-mock_esm("../src/people.ts", {- maybe_get_user_by_id: noop,-});mock_esm("../src/settings_data", {user_has_permission_for_group_setting: () => true,+ user_can_access_all_other_users: () => true,});const stream_data = zrequire("stream_data");// Code we're actually using/testingconst compose_closed_ui = zrequire("compose_closed_ui");+const people = zrequire("people");const {Filter} = zrequire("filter");const {MessageList} = zrequire("message_list");const {MessageListData} = zrequire("message_list_data");const {set_current_user, set_realm} = zrequire("state_data");-const current_user = {};+const current_user = {+ email: "[email protected]",+ user_id: 1,+ full_name: "Alice",+};set_current_user(current_user);+people.add_active_user(current_user);+people.add_active_user({+ email: "[email protected]",+ user_id: 2,+ full_name: "Bob",+});+people.add_active_user({+ email: "[email protected]",+ user_id: 3,+ full_name: "Zoe",+});+people.initialize_current_user(1);const REALM_EMPTY_TOPIC_DISPLAY_NAME = "general chat";set_realm({realm_empty_topic_display_name: REALM_EMPTY_TOPIC_DISPLAY_NAME});@@ -85,6 +100,8 @@ run_test("reply_label", () => {is_private: false,stream_id: stream_one.stream_id,topic: "first_topic",+ sent_by_me: false,+ sender_id: 2,},{id: 1,@@ -92,6 +109,8 @@ run_test("reply_label", () => {is_private: false,stream_id: stream_one.stream_id,topic: "second_topic",+ sent_by_me: false,+ sender_id: 2,},{id: 2,@@ -99,6 +118,8 @@ run_test("reply_label", () => {is_private: false,stream_id: stream_two.stream_id,topic: "third_topic",+ sent_by_me: false,+ sender_id: 2,},{id: 3,@@ -106,18 +127,24 @@ run_test("reply_label", () => {is_private: false,stream_id: stream_two.stream_id,topic: "second_topic",+ sent_by_me: false,+ sender_id: 2,},{id: 4,is_stream: false,is_private: true,- display_reply_to: "some user",+ to_user_ids: "2",+ sent_by_me: false,+ sender_id: 2,},{id: 5,is_stream: false,is_private: true,- display_reply_to: "some user, other user",+ to_user_ids: "2,3",+ sent_by_me: false,+ sender_id: 2,},{id: 6,@@ -125,6 +152,8 @@ run_test("reply_label", () => {is_private: false,stream_id: stream_two.stream_id,topic: "",+ sent_by_me: false,+ sender_id: 2,},],{},@@ -136,8 +165,8 @@ run_test("reply_label", () => {"#first_stream > second_topic","#second_stream > third_topic","#second_stream > second_topic",- "some user",- "some user, other user",+ "Bob",+ "Bob, Zoe",];// Initialize the code we're testing.@@ -188,16 +217,17 @@ run_test("test_non_message_list_input", () => {});test_reply_label("#stream test > topic test");- // Direct message row.+ // Direct message conversation with current user row.compose_closed_ui.update_recipient_text_for_reply_button({- display_reply_to: "some user",+ user_ids: [current_user.user_id],});- test_reply_label("some user");+ let label = $("#left_bar_compose_reply_button_big").html();+ assert.equal(label, "Message yourself");// Invalid data for a the reply button text.compose_closed_ui.update_recipient_text_for_reply_button({invalid_field: "something unexpected",});- const label = $("#left_bar_compose_reply_button_big").text();+ label = $("#left_bar_compose_reply_button_big").text();assert.equal(label, "translated: Compose message");});