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.

inbox: Set compose recipient according to focused row on `reply`.

Aman Agrawal2561e7f2d8eb
diff --git a/web/src/compose_reply.js b/web/src/compose_reply.js
index f85456f9a4f..b86f885e943 100644
--- a/web/src/compose_reply.js
+++ b/web/src/compose_reply.js
@@ -8,6 +8,8 @@ import * as compose_state from "./compose_state";
import * as compose_ui from "./compose_ui";
import * as hash_util from "./hash_util";
import {$t} from "./i18n";
+import * as inbox_ui from "./inbox_ui";
+import * as inbox_util from "./inbox_util";
import * as message_lists from "./message_lists";
import * as narrow_state from "./narrow_state";
import * as people from "./people";
@@ -27,6 +29,14 @@ export function respond_to_message(opts) {
compose_actions.start("stream", {trigger: "recent_view_nofocus"});
return;
}
+ } else if (inbox_util.is_visible()) {
+ message = inbox_ui.get_focused_row_message();
+ if (message === undefined) {
+ // Open empty compose with nothing pre-filled since
+ // user is not focused on any table row.
+ compose_actions.start("stream", {trigger: "inbox_nofocus"});
+ return;
+ }
} else {
message = message_lists.current.selected_message();
diff --git a/web/src/inbox_ui.js b/web/src/inbox_ui.js
index acd1fcde55a..d5491b02360 100644
--- a/web/src/inbox_ui.js
+++ b/web/src/inbox_ui.js
@@ -691,6 +691,30 @@ function update_closed_compose_text($row, is_header_row) {
compose_closed_ui.update_reply_recipient_label(message);
}
+export function get_focused_row_message() {
+ if (!is_list_focused()) {
+ return undefined;
+ }
+
+ const $all_rows = get_all_rows();
+ const $focused_row = $($all_rows.get(row_focus));
+ if (is_row_a_header($focused_row)) {
+ return undefined;
+ }
+
+ const is_dm = $focused_row.parent("#inbox-direct-messages-container").length > 0;
+ const conversation_key = $focused_row.attr("id").slice(CONVERSATION_ID_PREFIX.length);
+ let latest_msg_id;
+ if (is_dm) {
+ latest_msg_id = dms_dict.get(conversation_key).latest_msg_id;
+ } else {
+ const $stream = $focused_row.parent(".inbox-topic-container").parent();
+ const stream_key = $stream.attr("id");
+ latest_msg_id = topics_dict.get(stream_key).get(conversation_key).latest_msg_id;
+ }
+ return message_store.get(latest_msg_id);
+}
+
function is_row_a_header($row) {
return $row.hasClass("inbox-header");
}