From c636fcf4fc92a5d403d3c5000031e12b94e7aa32 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Thu, 4 May 2023 06:18:05 +0800 Subject: [PATCH] FIX: Blank user messages inbox dropdown on subfolder setup. (#21356) This commit fixes a bug on subfolder setups where the user messages inbox dropdown will always be blank. This is because we were comparing URLs using values from `router.currentURL` and `router.urlFor` where `router.currentURL` does not include `router.rootURL` while `router.urlFor` does. --- .../app/controllers/user-private-messages.js | 4 +++- .../acceptance/user-private-messages-test.js | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/app/controllers/user-private-messages.js b/app/assets/javascripts/discourse/app/controllers/user-private-messages.js index 8aae040a378..09c75fab652 100644 --- a/app/assets/javascripts/discourse/app/controllers/user-private-messages.js +++ b/app/assets/javascripts/discourse/app/controllers/user-private-messages.js @@ -41,10 +41,12 @@ export default class extends Controller { get messagesDropdownValue() { let value; + const currentURL = this.router.currentURL.toLowerCase(); + for (let i = this.messagesDropdownContent.length - 1; i >= 0; i--) { const row = this.messagesDropdownContent[i]; - if (this.router.currentURL.toLowerCase().includes(row.id)) { + if (currentURL.includes(row.id.replace(this.router.rootURL, "/"))) { value = row.id; break; } diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-private-messages-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-private-messages-test.js index 043d913a19f..9079245cbc5 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/user-private-messages-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/user-private-messages-test.js @@ -45,6 +45,27 @@ acceptance( ); }); + test("viewing group messages on subfolder setup", async function (assert) { + const router = this.container.lookup("router:main"); + const originalRootURL = router.rootURL; + + try { + router.set("rootURL", "/forum/"); + + await visit("/forum/u/eviltrout/messages"); + + const messagesDropdown = selectKit(".user-nav-messages-dropdown"); + + assert.strictEqual( + messagesDropdown.header().name(), + I18n.t("user.messages.inbox"), + "User personal inbox is selected in dropdown" + ); + } finally { + router.set("rootURL", originalRootURL); + } + }); + test("viewing messages of another user", async function (assert) { updateCurrentUser({ id: 5, username: "charlie" });