From ac64ee355df9d6fcdbe322203988f80df4b11663 Mon Sep 17 00:00:00 2001 From: Joshua Pan Date: Fri, 21 Apr 2017 00:33:05 -0700 Subject: [PATCH] compose_actions.js: Allow compose to empty narrow. This allows r/enter hotkeys to compose to an empty narrow (no messages). Fixes #4500. --- frontend_tests/node_tests/hotkey.js | 2 +- static/js/compose_actions.js | 16 +++++++++++++++- static/js/hotkey.js | 19 +++++++------------ 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.js index adc20632c2..daab51a27e 100644 --- a/frontend_tests/node_tests/hotkey.js +++ b/frontend_tests/node_tests/hotkey.js @@ -215,7 +215,7 @@ function stubbing(func_name_to_stub, test_function) { assert_mapping('d', 'drafts.toggle'); // Next, test keys that only work on a selected message. - var message_view_only_keys = '@*+rRjJkKsSuvi:GM'; + var message_view_only_keys = '@*+RjJkKsSuvi:GM'; // Check that they do nothing without a selected message global.current_msg_list.empty = return_true; diff --git a/static/js/compose_actions.js b/static/js/compose_actions.js index 38bc7e39ea..df6485af3c 100644 --- a/static/js/compose_actions.js +++ b/static/js/compose_actions.js @@ -252,7 +252,21 @@ exports.respond_to_message = function (opts) { message = current_msg_list.selected_message(); - if (message === undefined) { + if (message === undefined) { // empty narrow implementation + if (!narrow_state.narrowed_by_pm_reply() && + !narrow_state.narrowed_by_stream_reply() && + !narrow_state.narrowed_by_topic_reply()) { + return; + } + + msg_type = 'stream'; // Set msg_type to stream by default + // in the case of an empty home view. + if (narrow_state.narrowed_by_pm_reply()) { + msg_type = 'private'; + } + + var new_opts = fill_in_opts_from_current_narrowed_view(msg_type, opts); + exports.start(new_opts.message_type, new_opts); return; } diff --git a/static/js/hotkey.js b/static/js/hotkey.js index 904d74c516..ad74ca93d2 100644 --- a/static/js/hotkey.js +++ b/static/js/hotkey.js @@ -321,14 +321,9 @@ exports.process_enter_key = function (e) { return true; } - if (current_msg_list.empty()) { - return false; - } - // If we got this far, then we're presumably in the message - // view and there is a "current" message, so in that case - // "enter" is the hotkey to respond to a message. Note that - // "r" has same effect, but that is handled in process_hotkey(). + // view, so in that case "enter" is the hotkey to respond to a message. + // Note that "r" has same effect, but that is handled in process_hotkey(). compose_actions.respond_to_message({trigger: 'hotkey enter'}); return true; }; @@ -589,6 +584,11 @@ exports.process_hotkey = function (e, hotkey) { case 'open_drafts': drafts.toggle(); return true; + case 'reply_message': // 'r': respond to message + // Note that you can "enter" to respond to messages as well, + // but that is handled in process_enter_key(). + compose_actions.respond_to_message({trigger: 'hotkey'}); + return true; } if (current_msg_list.empty()) { @@ -640,11 +640,6 @@ exports.process_hotkey = function (e, hotkey) { return do_narrow_action(narrow.by_recipient); case 'narrow_by_subject': return do_narrow_action(narrow.by_subject); - case 'reply_message': // 'r': respond to message - // Note that you can "enter" to respond to messages as well, - // but that is handled in process_enter_key(). - compose_actions.respond_to_message({trigger: 'hotkey'}); - return true; case 'respond_to_author': // 'R': respond to author compose_actions.respond_to_message({reply_type: "personal", trigger: 'hotkey pm'}); return true;