Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
compose_closed_ui: Store recipient metadata in reply button label state.
Pratik Chandaedc4ffceba9a
diff --git a/web/src/compose_closed_ui.ts b/web/src/compose_closed_ui.tsindex 4a31d269fb4..7a63d54e7e0 100644--- a/web/src/compose_closed_ui.ts+++ b/web/src/compose_closed_ui.ts@@ -23,6 +23,7 @@ type RecipientLabel = {stream?: StreamSubscription;topic_display_name?: string;is_dm_with_self?: boolean;+ user_ids?: number[];};function get_stream_recipient_label(stream_id: number, topic: string): RecipientLabel | undefined {@@ -50,6 +51,7 @@ function get_direct_message_recipient_label(user_ids: number[]): RecipientLabelconst recipient_label: RecipientLabel = {label_text,is_dm_with_self,+ user_ids,};return recipient_label;}@@ -210,12 +212,15 @@ export function update_buttons(update_type?: string): void {// Based on whether there's a selected channel message in// the current message list.disable_reply_button = should_disable_compose_reply_button_for_stream();- } else {- // Default case for most views.- set_standard_text_for_reply_button();}update_new_conversation_button(update_type === "stream" ? "stream" : "non-specific");+ // We omit recipient_information here, so update_reply_button_with_recipient_context+ // derives the reply target from the current message list: the selected+ // message, or the narrowed conversation in an empty view. (The Inbox+ // and Recent Conversations views instead pass the reply target from+ // their focused row.)+ update_reply_button_with_recipient_context();update_reply_button_state(disable_reply_button);}@@ -232,12 +237,22 @@ function set_reply_button_label(label: string): void {export function set_standard_text_for_reply_button(): void {set_reply_button_label($t({defaultMessage: "Compose message"}));+ const $compose_reply_button_wrapper = $(+ "#legacy-closed-compose-box .compose-reply-button-wrapper",+ );+ // Clear any stale recipient context from a previous reply target.+ $compose_reply_button_wrapper.removeAttr("data-stream-id");+ $compose_reply_button_wrapper.removeAttr("data-user-ids-string");+ $compose_reply_button_wrapper.removeAttr("data-reply-button-type");}-export function update_recipient_text_for_reply_button(+export function update_reply_button_with_recipient_context(recipient_information?: ReplyRecipientInformation,): void {const recipient_label = get_recipient_label(recipient_information);+ const $compose_reply_button_wrapper = $(+ "#legacy-closed-compose-box .compose-reply-button-wrapper",+ );if (recipient_label !== undefined) {const empty_string_topic_display_name = util.get_final_topic_display_name("");const rendered_recipient_label = render_reply_recipient_label({@@ -248,6 +263,32 @@ export function update_recipient_text_for_reply_button(empty_string_topic_display_name,label_text: recipient_label.label_text,});+ // We store the recipient state so that update_reply_button_state+ // can use that information without re-examining the message list+ // or narrow state. The state is reset/unset by+ // set_standard_text_for_reply_button().+ if (recipient_label.stream) {+ // Channel message recipient.+ $compose_reply_button_wrapper.removeAttr("data-user-ids-string");+ $compose_reply_button_wrapper.attr(+ "data-stream-id",+ recipient_label.stream.stream_id.toString(),+ );+ } else if (recipient_label.user_ids) {+ // Direct message recipient.+ $compose_reply_button_wrapper.removeAttr("data-stream-id");+ $compose_reply_button_wrapper.attr(+ "data-user-ids-string",+ recipient_label.user_ids.join(","),+ );+ } else {+ // Fallback case: recipient label from display_reply_to+ // text when we couldn't decode user IDs from the narrow+ // URL. We can't check permissions, so we leave the+ // button enabled.+ $compose_reply_button_wrapper.removeAttr("data-stream-id");+ $compose_reply_button_wrapper.removeAttr("data-user-ids-string");+ }$("#left_bar_compose_reply_button_big").html(rendered_recipient_label);} else {set_standard_text_for_reply_button();@@ -273,7 +314,7 @@ export function initialize(): void {// message_selected events can occur with Recent Conversations// open due to the combined feed view loading in the background,// so we only update if message feed is visible.- update_recipient_text_for_reply_button();+ update_reply_button_with_recipient_context();update_reply_button_state(!can_user_reply_to_message(message_lists.current!.selected_id()),);diff --git a/web/src/inbox_ui.ts b/web/src/inbox_ui.tsindex c0af6b8b0be..b62698a4a7a 100644--- a/web/src/inbox_ui.ts+++ b/web/src/inbox_ui.ts@@ -1647,7 +1647,7 @@ function update_closed_compose_text($row: JQuery, is_header_row: boolean): voidtopic: $row.find(".inbox-topic-name a").text(),};}- compose_closed_ui.update_recipient_text_for_reply_button(reply_recipient_information);+ compose_closed_ui.update_reply_button_with_recipient_context(reply_recipient_information);}export function get_focused_row_message(): {message?: Message | undefined} & (diff --git a/web/src/message_view.ts b/web/src/message_view.tsindex 4395bd6e3ad..fe82c61b7e6 100644--- a/web/src/message_view.ts+++ b/web/src/message_view.ts@@ -1623,7 +1623,7 @@ function handle_post_view_change(} else {compose_closed_ui.update_buttons();}- compose_closed_ui.update_recipient_text_for_reply_button();+ compose_closed_ui.update_reply_button_with_recipient_context();message_view_header.render_title_area();diff --git a/web/src/recent_view_ui.ts b/web/src/recent_view_ui.tsindex e1c4eb71f61..b5891ad0a71 100644--- a/web/src/recent_view_ui.ts+++ b/web/src/recent_view_ui.ts@@ -503,7 +503,7 @@ function set_table_focus(row: number, col: number, using_keyboard = false): booltopic: $topic_row.find(".recent-view-conversation-link").text(),};}- compose_closed_ui.update_recipient_text_for_reply_button(reply_recipient_information);+ compose_closed_ui.update_reply_button_with_recipient_context(reply_recipient_information);return true;}diff --git a/web/tests/compose_closed_ui.test.cjs b/web/tests/compose_closed_ui.test.cjsindex a57daecd13a..68b7348b450 100644--- a/web/tests/compose_closed_ui.test.cjs+++ b/web/tests/compose_closed_ui.test.cjs@@ -204,7 +204,7 @@ run_test("reply_label", ({mock_template}) => {run_test("empty_narrow", () => {message_lists.current.visibly_empty = () => true;- compose_closed_ui.update_recipient_text_for_reply_button();+ compose_closed_ui.update_reply_button_with_recipient_context();const label = $("#left_bar_compose_reply_button_big").text();assert.equal(label, "translated: Compose message");});@@ -225,21 +225,21 @@ run_test("test_non_message_list_input", ({mock_template}) => {stream_data.add_sub_for_tests(stream);// Channel and topic row.- compose_closed_ui.update_recipient_text_for_reply_button({+ compose_closed_ui.update_reply_button_with_recipient_context({stream_id: stream.stream_id,topic: "topic test",});test_reply_label("<rendered-channel-stub:stream test> > topic test");// Direct message conversation with current user row.- compose_closed_ui.update_recipient_text_for_reply_button({+ compose_closed_ui.update_reply_button_with_recipient_context({user_ids: [current_user.user_id],});let label = $("#left_bar_compose_reply_button_big").html();assert.equal(label, "translated: Write yourself a note");// Invalid data for a the reply button text.- compose_closed_ui.update_recipient_text_for_reply_button({+ compose_closed_ui.update_reply_button_with_recipient_context({invalid_field: "something unexpected",});label = $("#left_bar_compose_reply_button_big").text();