From ac33ecdc8ca8db336e39b155d65f24fc5d849191 Mon Sep 17 00:00:00 2001 From: Renato Atilio Date: Wed, 6 Nov 2024 15:20:54 -0300 Subject: [PATCH] FIX: pass topic+category to @-mention user search (#29620) When replying to a topic, the @-mention userSearch needs the topicId and the categoryId so they can trigger immediately, with sane suggestions. This was broken when the mentions were moved from ComposerEditor to DEditor. --- .../discourse/app/components/d-editor.js | 4 ++-- .../composer-editor-mentions-test.js | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/d-editor.js b/app/assets/javascripts/discourse/app/components/d-editor.js index b8e6362d31e..0e1ed221c65 100644 --- a/app/assets/javascripts/discourse/app/components/d-editor.js +++ b/app/assets/javascripts/discourse/app/components/d-editor.js @@ -484,8 +484,8 @@ export default class DEditor extends Component { destroyUserStatuses(); return userSearch({ term, - topicId: this.topic?.id, - categoryId: this.topic?.category_id || this.composer?.categoryId, + topicId: this.topicId, + categoryId: this.categoryId, includeGroups: true, }).then((result) => { initUserStatusHtml(getOwner(this), result.users); diff --git a/app/assets/javascripts/discourse/tests/acceptance/composer-editor-mentions-test.js b/app/assets/javascripts/discourse/tests/acceptance/composer-editor-mentions-test.js index 08e8b860fb5..ac0c64f2bd1 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/composer-editor-mentions-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/composer-editor-mentions-test.js @@ -1,6 +1,7 @@ import { click, visit } from "@ember/test-helpers"; import { test } from "qunit"; import { setCaretPosition } from "discourse/lib/utilities"; +import topicFixtures from "discourse/tests/fixtures/topic"; import { acceptance, fakeTime, @@ -9,6 +10,7 @@ import { queryAll, simulateKeys, } from "discourse/tests/helpers/qunit-helpers"; +import { cloneJSON } from "discourse-common/lib/object"; acceptance("Composer - editor mentions", function (needs) { let clock = null; @@ -24,6 +26,11 @@ acceptance("Composer - editor mentions", function (needs) { needs.hooks.afterEach(() => clock?.restore()); needs.pretender((server, helper) => { + server.get("/t/11557.json", () => { + const topicFixture = cloneJSON(topicFixtures["/t/130.json"]); + topicFixture.id = 11557; + return helper.response(topicFixture); + }); server.get("/u/search/users", () => { return helper.response({ users: [ @@ -144,4 +151,19 @@ acceptance("Composer - editor mentions", function (needs) { ["foo", "user_group", "user", "user2"] ); }); + + test("shows users immediately when @ is typed in a reply", async function (assert) { + await visit("/"); + await click(".topic-list-item .title"); + await click(".btn-primary.create"); + + await simulateKeys(".d-editor-input", "abc @"); + + assert.deepEqual( + [...document.querySelectorAll(".ac-user .username")].map( + (e) => e.innerText + ), + ["user_group", "user", "user2", "foo"] + ); + }); });