From 7c74e4882a59d4864bda78f4f05e3e2883895149 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Wed, 1 Mar 2023 11:32:12 +0100 Subject: [PATCH] FIX: Don't set `categoryId` on PM drafts (#20475) --- .../javascripts/discourse/app/models/composer.js | 4 +++- .../discourse/tests/unit/models/composer-test.js | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/app/models/composer.js b/app/assets/javascripts/discourse/app/models/composer.js index 267c2412d4f..8340083a0e7 100644 --- a/app/assets/javascripts/discourse/app/models/composer.js +++ b/app/assets/javascripts/discourse/app/models/composer.js @@ -142,7 +142,9 @@ const Composer = RestModel.extend({ set(categoryId) { const oldCategoryId = this._categoryId; - if (isEmpty(categoryId)) { + if (this.privateMessage) { + categoryId = null; + } else if (isEmpty(categoryId)) { // Check if there is a default composer category to set const defaultComposerCategoryId = parseInt( this.siteSettings.default_composer_category, diff --git a/app/assets/javascripts/discourse/tests/unit/models/composer-test.js b/app/assets/javascripts/discourse/tests/unit/models/composer-test.js index b671ce5dd4a..9306c8554ef 100644 --- a/app/assets/javascripts/discourse/tests/unit/models/composer-test.js +++ b/app/assets/javascripts/discourse/tests/unit/models/composer-test.js @@ -317,6 +317,20 @@ module("Unit | Model | composer", function (hooks) { ); }); + test("initial category when creating PM and there is a default composer category", function (assert) { + this.siteSettings.default_composer_category = 2; + const composer = openComposer.call(this, { + action: PRIVATE_MESSAGE, + draftKey: "abcd", + draftSequence: 1, + }); + assert.strictEqual( + composer.categoryId, + null, + "it doesn't save the category" + ); + }); + test("open with a quote", function (assert) { const quote = '[quote="neil, post:5, topic:413"]\nSimmer down you two.\n[/quote]';