From 07e11a223ceee1b62aaa2de18e8cf438893e9e82 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Thu, 23 Aug 2018 11:09:35 +0200 Subject: [PATCH] FIX: prefills username for new message on first post (#6305) --- .../components/composer-actions.js.es6 | 9 +++++++++ .../acceptance/composer-actions-test.js.es6 | 20 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/app/assets/javascripts/select-kit/components/composer-actions.js.es6 b/app/assets/javascripts/select-kit/components/composer-actions.js.es6 index 866a9750edc..9beff4acab9 100644 --- a/app/assets/javascripts/select-kit/components/composer-actions.js.es6 +++ b/app/assets/javascripts/select-kit/components/composer-actions.js.es6 @@ -275,6 +275,15 @@ export default DropdownSelectBoxComponent.extend({ if (postUsername) { usernames = postUsername; } + } else if (this.get("composerModel.topic")) { + const stream = this.get("composerModel.topic.postStream"); + + if (stream.get("firstPostPresent")) { + const post = stream.get("posts.firstObject"); + if (post && !post.get("yours") && post.get("username")) { + usernames = post.get("username"); + } + } } options.action = PRIVATE_MESSAGE; diff --git a/test/javascripts/acceptance/composer-actions-test.js.es6 b/test/javascripts/acceptance/composer-actions-test.js.es6 index f94897e99cf..6c84b8778d8 100644 --- a/test/javascripts/acceptance/composer-actions-test.js.es6 +++ b/test/javascripts/acceptance/composer-actions-test.js.es6 @@ -304,3 +304,23 @@ QUnit.test("replying to post as regular user", async assert => { ); }); }); + +QUnit.test( + "replying to first post - reply_as_private_message", + async assert => { + const composerActions = selectKit(".composer-actions"); + + await visit("/t/internationalization-localization/280"); + await click("article#post_1 button.reply"); + + await composerActions.expand(); + await composerActions.selectRowByValue("reply_as_private_message"); + + assert.equal(find(".users-input .item:eq(0)").text(), "uwe_keim"); + assert.ok( + find(".d-editor-input") + .val() + .indexOf("Continuing the discussion") >= 0 + ); + } +);