Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
compose-closed-ui: Clarify object and type for reply to button.
Lauryn Menardb48134a03ef2
diff --git a/web/src/compose_closed_ui.ts b/web/src/compose_closed_ui.tsindex 83f5c8c43c6..0c679d46ebd 100644--- a/web/src/compose_closed_ui.ts+++ b/web/src/compose_closed_ui.ts@@ -33,13 +33,15 @@ function get_stream_recipient_label(stream_id: number, topic: string): Recipientreturn undefined;}-type ComposeClosedMessage = {+export type ReplyRecipientInformation = {stream_id?: number | undefined;- topic?: string;+ topic?: string | undefined;display_reply_to?: string | undefined;};-export function get_recipient_label(message?: ComposeClosedMessage): RecipientLabel | undefined {+export function get_recipient_label(+ recipient_information?: ReplyRecipientInformation,+): RecipientLabel | undefined {// TODO: This code path is bit of a type-checking disaster; we mix// actual message objects with fake objects containing just a// couple fields, both those constructed here and potentially@@ -48,7 +50,7 @@ export function get_recipient_label(message?: ComposeClosedMessage): RecipientLareturn undefined;}- if (message === undefined) {+ if (recipient_information === undefined) {if (message_lists.current.visibly_empty()) {// For empty narrows where there's a clear reply target,// i.e. stream+topic or a single direct message conversation,@@ -62,15 +64,21 @@ export function get_recipient_label(message?: ComposeClosedMessage): RecipientLareturn {label_text: message_store.get_pm_full_names(user_ids)};}} else {- message = message_lists.current.selected_message();+ recipient_information = message_lists.current.selected_message();}}- if (message) {- if (message.stream_id !== undefined && message.topic !== undefined) {- return get_stream_recipient_label(message.stream_id, message.topic);- } else if (message.display_reply_to) {- return {label_text: message.display_reply_to};+ if (recipient_information) {+ if (+ recipient_information.stream_id !== undefined &&+ recipient_information.topic !== undefined+ ) {+ return get_stream_recipient_label(+ recipient_information.stream_id,+ recipient_information.topic,+ );+ } else if (recipient_information.display_reply_to) {+ return {label_text: recipient_information.display_reply_to};}}return undefined;@@ -171,8 +179,10 @@ export function set_standard_text_for_reply_button(): void {set_reply_button_label($t({defaultMessage: "Compose message"}));}-export function update_recipient_text_for_reply_button(message?: ComposeClosedMessage): void {- const recipient_label = get_recipient_label(message);+export function update_recipient_text_for_reply_button(+ recipient_information?: ReplyRecipientInformation,+): void {+ const recipient_label = get_recipient_label(recipient_information);if (recipient_label !== undefined) {const empty_string_topic_display_name = util.get_final_topic_display_name("");const rendered_recipient_label = render_reply_recipient_label({diff --git a/web/src/inbox_ui.ts b/web/src/inbox_ui.tsindex e3ef6748406..57ec3910858 100644--- a/web/src/inbox_ui.ts+++ b/web/src/inbox_ui.ts@@ -875,30 +875,25 @@ export function revive_current_focus(): void {}function update_closed_compose_text($row: JQuery, is_header_row: boolean): void {- // TODO: This fake "message" object is designed to allow using the- // get_recipient_label helper inside compose_closed_ui. Surely- // there's a more readable way to write this code.- // Similar code is present in recent view.-if (is_header_row) {compose_closed_ui.set_standard_text_for_reply_button();return;}- let message;+ let reply_recipient_information: compose_closed_ui.ReplyRecipientInformation;const is_dm = $row.parent("#inbox-direct-messages-container").length > 0;if (is_dm) {- message = {+ reply_recipient_information = {display_reply_to: $row.find(".recipients_name").text(),};} else {const $stream = $row.parent(".inbox-topic-container").prev(".inbox-header");- message = {+ reply_recipient_information = {stream_id: Number($stream.attr("data-stream-id")),topic: $row.find(".inbox-topic-name a").text(),};}- compose_closed_ui.update_recipient_text_for_reply_button(message);+ compose_closed_ui.update_recipient_text_for_reply_button(reply_recipient_information);}export function get_focused_row_message(): {message?: Message | undefined} & (diff --git a/web/src/recent_view_ui.ts b/web/src/recent_view_ui.tsindex ff76fbad11e..cadb804276c 100644--- a/web/src/recent_view_ui.ts+++ b/web/src/recent_view_ui.ts@@ -340,24 +340,20 @@ function set_table_focus(row: number, col: number, using_keyboard = false): bool}}- // TODO: This fake "message" object is designed to allow using the- // get_recipient_label helper inside compose_closed_ui. Surely- // there's a more readable way to write this code.- // Similar code is present in Inbox.- let message;+ let reply_recipient_information: compose_closed_ui.ReplyRecipientInformation;if (type === "private") {- message = {+ reply_recipient_information = {display_reply_to: $topic_row.find(".recent_topic_name a").text(),};} else {const stream_name = $topic_row.find(".recent_topic_stream a").text();const stream = stream_data.get_sub_by_name(stream_name);- message = {+ reply_recipient_information = {stream_id: stream?.stream_id,topic: $topic_row.find(".recent_topic_name a").text(),};}- compose_closed_ui.update_recipient_text_for_reply_button(message);+ compose_closed_ui.update_recipient_text_for_reply_button(reply_recipient_information);return true;}