FIX: Loading draft also replaces the recipients (#7122)

FIX: Loading draft also replaces the recipients (#7122)

diff --git a/app/assets/javascripts/discourse/controllers/composer.js.es6 b/app/assets/javascripts/discourse/controllers/composer.js.es6
index 8156df8..52deb54 100644
--- a/app/assets/javascripts/discourse/controllers/composer.js.es6
+++ b/app/assets/javascripts/discourse/controllers/composer.js.es6
@@ -902,7 +902,7 @@ export default Ember.Controller.extend({
     composerModel.set("composeState", Composer.OPEN);
     composerModel.set("isWarning", false);
 
-    if (opts.usernames) {
+    if (opts.usernames && !this.get("model.targetUsernames")) {
       this.set("model.targetUsernames", opts.usernames);
     }
 
diff --git a/test/javascripts/acceptance/composer-test.js.es6 b/test/javascripts/acceptance/composer-test.js.es6
index 9ad9d44..fcbff94 100644
--- a/test/javascripts/acceptance/composer-test.js.es6
+++ b/test/javascripts/acceptance/composer-test.js.es6
@@ -600,6 +600,24 @@ QUnit.test("Checks for existing draft", async assert => {
   toggleCheckDraftPopup(false);
 });
 
+QUnit.test("Loading draft also replaces the recipients", async assert => {
+  toggleCheckDraftPopup(true);
+
+  // prettier-ignore
+  server.get("/draft.json", () => { // eslint-disable-line no-undef
+    return [ 200, { "Content-Type": "application/json" }, {
+       "draft":"{\"reply\":\"hello\",\"action\":\"privateMessage\",\"title\":\"hello\",\"categoryId\":null,\"archetypeId\":\"private_message\",\"metaData\":null,\"usernames\":\"codinghorror\",\"composerTime\":9159,\"typingTime\":2500}",
+       "draft_sequence":0
+    } ];
+  });
+
+  await visit("/u/charlie");
+  await click("button.compose-pm");
+  await click(".modal .btn-default");
+
+  assert.equal(find(".users-input .item:eq(0)").text(), "codinghorror");
+});
+
 const assertImageResized = (assert, uploads) => {
   assert.equal(
     find(".d-editor-input").val(),
diff --git a/test/javascripts/fixtures/user_fixtures.js.es6 b/test/javascripts/fixtures/user_fixtures.js.es6
index 51df041..203f3a7 100644
--- a/test/javascripts/fixtures/user_fixtures.js.es6
+++ b/test/javascripts/fixtures/user_fixtures.js.es6
@@ -2276,5 +2276,334 @@ export default {
         }
       ]
     }
+  },
+  "/u/charlie.json": {
+    user_badges: [
+      {
+        id: 17,
+        granted_at: "2019-03-06T19:08:28.230Z",
+        count: 1,
+        badge_id: 3,
+        user_id: 5,
+        granted_by_id: -1
+      }
+    ],
+    badges: [
+      {
+        id: 3,
+        name: "Regular",
+        description:
+          '\u003ca href="https://blog.discourse.org/2018/06/understanding-discourse-trust-levels/"\u003eGranted\u003c/a\u003e recategorize, rename, followed links, wiki, more likes',
+        grant_count: 3,
+        allow_title: true,
+        multiple_grant: false,
+        icon: "fa-user",
+        image: null,
+        listable: true,
+        enabled: true,
+        badge_grouping_id: 4,
+        system: true,
+        slug: "regular",
+        manually_grantable: false,
+        badge_type_id: 2
+      }
+    ],
+    badge_types: [{ id: 2, name: "Silver", sort_order: 8 }],
+    users: [
+      {
+        id: 5,
+        username: "charlie",
+        name: null,
+        avatar_template: "/letter_avatar_proxy/v3/letter/c/d6d6ee/{size}.png",
+        moderator: false,
+        admin: false
+      },
+      {
+        id: -1,
+        username: "system",
+        name: "system",
+        avatar_template: "/user_avatar/localhost/system/{size}/2_2.png",
+        moderator: true,
+        admin: true
+      }
+    ],
+    user: {
+      id: 5,
+      username: "charlie",
+      name: null,
+      avatar_template: "/letter_avatar_proxy/v3/letter/c/d6d6ee/{size}.png",
+      last_posted_at: null,
+      last_seen_at: null,
+      created_at: "2019-03-06T19:06:20.340Z",
+      can_edit: true,
+      can_edit_username: true,
+      can_edit_email: true,
+      can_edit_name: true,
+      ignored: false,
+      can_ignore_user: false,
+      can_send_private_messages: true,
+      can_send_private_message_to_user: true,
+      trust_level: 3,
+      moderator: false,
+      admin: false,
+      title: null,
+      uploaded_avatar_id: null,
+      badge_count: 3,
+      has_title_badges: true,
+      custom_fields: {},
+      pending_count: 0,
+      profile_view_count: 1,
+      time_read: 0,
+      recent_time_read: 0,
+      primary_group_name: null,
+      primary_group_flair_url: null,
+      primary_group_flair_bg_color: null,
+      primary_group_flair_color: null,
+      staged: false,
+      second_factor_enabled: false,
+      post_count: 0,
+      can_be_deleted: true,
+      can_delete_all_posts: true,
+      locale: null,
+      muted_category_ids: [],
+      watched_tags: [],
+      watching_first_post_tags: [],
+      tracked_tags: [],
+      muted_tags: [],
+      tracked_category_ids: [],
+      watched_category_ids: [],
+      watched_first_post_category_ids: [],
+      system_avatar_upload_id: null,
+      system_avatar_template:
+        "/letter_avatar_proxy/v3/letter/c/d6d6ee/{size}.png",
+      muted_usernames: [],
+      ignored_usernames: [],
+      mailing_list_posts_per_day: 0,
+      can_change_bio: true,
+      user_api_keys: null,
+      user_auth_tokens: [],
+      user_auth_token_logs: [],
+      invited_by: null,
+      groups: [
+        {
+          id: 10,
+          automatic: true,
+          name: "trust_level_0",
+          display_name: "trust_level_0",
+          user_count: 14,
+          mentionable_level: 0,
+          messageable_level: 0,
+          visibility_level: 0,
+          automatic_membership_email_domains: null,
+          automatic_membership_retroactive: false,
+          primary_group: false,
+          title: null,
+          grant_trust_level: null,
+          incoming_email: null,
+          has_messages: false,
+          flair_url: null,
+          flair_bg_color: null,
+          flair_color: null,
+          bio_raw: null,
+          bio_cooked: null,
+          public_admission: false,
+          public_exit: false,
+          allow_membership_requests: false,
+          full_name: null,
+          default_notification_level: 3,
+          membership_request_template: null
+        },
+        {
+          id: 11,
+          automatic: true,
+          name: "trust_level_1",
+          display_name: "trust_level_1",
+          user_count: 9,
+          mentionable_level: 0,
+          messageable_level: 0,
+          visibility_level: 0,
+          automatic_membership_email_domains: null,
+          automatic_membership_retroactive: false,
+          primary_group: false,
+          title: null,
+          grant_trust_level: null,
+          incoming_email: null,
+          has_messages: false,
+          flair_url: null,
+          flair_bg_color: null,
+          flair_color: null,
+          bio_raw: null,
+          bio_cooked: null,
+          public_admission: false,
+          public_exit: false,
+          allow_membership_requests: false,
+          full_name: null,
+          default_notification_level: 3,
+          membership_request_template: null
+        },
+        {
+          id: 12,
+          automatic: true,
+          name: "trust_level_2",
+          display_name: "trust_level_2",
+          user_count: 6,
+          mentionable_level: 0,
+          messageable_level: 0,
+          visibility_level: 0,
+          automatic_membership_email_domains: null,
+          automatic_membership_retroactive: false,
+          primary_group: false,
+          title: null,
+          grant_trust_level: null,
+          incoming_email: null,
+          has_messages: false,
+          flair_url: null,
+          flair_bg_color: null,
+          flair_color: null,
+          bio_raw: null,
+          bio_cooked: null,
+          public_admission: false,
+          public_exit: false,
+          allow_membership_requests: false,
+          full_name: null,
+          default_notification_level: 3,
+          membership_request_template: null
+        },
+        {
+          id: 13,
+          automatic: true,

[... diff too long, it was truncated ...]

GitHub sha: 733deba5