From 207d7a8ee60fa123ea3da348198f433bd373f5c0 Mon Sep 17 00:00:00 2001 From: Marco Burstein Date: Thu, 1 Nov 2018 15:43:29 -0700 Subject: [PATCH] compose: Use a placeholder when quoting and replying. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the placeholder `[Quoting…]` when quoting and replying before the quote has been added to the message. Also, add tests to the `compose_actions` Node tests for the new behavior. Fix #10705. --- frontend_tests/node_tests/compose_actions.js | 41 ++++++++++++++++++++ static/js/compose_actions.js | 8 ++-- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/frontend_tests/node_tests/compose_actions.js b/frontend_tests/node_tests/compose_actions.js index e831513c29..743bae049b 100644 --- a/frontend_tests/node_tests/compose_actions.js +++ b/frontend_tests/node_tests/compose_actions.js @@ -29,6 +29,7 @@ var cancel = compose_actions.cancel; var get_focus_area = compose_actions._get_focus_area; var respond_to_message = compose_actions.respond_to_message; var reply_with_mention = compose_actions.reply_with_mention; +var quote_and_reply = compose_actions.quote_and_reply; var compose_state = global.compose_state; @@ -84,6 +85,14 @@ function stub_selected_message(msg) { }); } +function stub_channel_get(success_value) { + set_global('channel', { + get: function (opts) { + opts.success(success_value); + }, + }); +} + function assert_visible(sel) { assert($(sel).visible()); } @@ -244,6 +253,38 @@ run_test('reply_with_mention', () => { assert(compose_state.has_message_content()); }); +run_test('quote_and_reply', () => { + var msg = { + type: 'stream', + stream: 'devel', + subject: 'python', + reply_to: 'bob', + sender_full_name: 'Bob Roberts', + sender_id: 40, + }; + stub_selected_message(msg); + stub_channel_get({ raw_content: 'Testing.' }); + + current_msg_list.selected_id = function () { + return 100; + }; + + compose_ui.insert_syntax_and_focus = function (syntax) { + assert.equal(syntax, '[Quoting…]\n'); + }; + + compose_ui.replace_syntax = function (syntax, replacement) { + assert.equal(syntax, '[Quoting…]'); + assert.equal(replacement, 'Testing.'); + }; + + var opts = { + reply_type: 'personal', + }; + + quote_and_reply(opts); +}); + run_test('get_focus_area', () => { assert.equal(get_focus_area('private', {}), 'private_message_recipient'); assert.equal(get_focus_area('private', { diff --git a/static/js/compose_actions.js b/static/js/compose_actions.js index 88314210b1..1f9cc8de88 100644 --- a/static/js/compose_actions.js +++ b/static/js/compose_actions.js @@ -390,15 +390,13 @@ exports.quote_and_reply = function (opts) { var message_id = current_msg_list.selected_id(); exports.respond_to_message(opts); + compose_ui.insert_syntax_and_focus("[Quoting…]\n", textarea); + channel.get({ url: '/json/messages/' + message_id, idempotent: true, success: function (data) { - if (textarea.val() === "") { - textarea.val("```quote\n" + data.raw_content + "\n```\n"); - } else { - textarea.val(textarea.val() + "\n```quote\n" + data.raw_content + "\n```\n"); - } + compose_ui.replace_syntax('[Quoting…]', '```quote\n' + data.raw_content + '\n```', textarea); $("#compose-textarea").trigger("autosize.resize"); }, });