From 2c4fd7f7c7f9f22e968e752b3b6e3474f3526759 Mon Sep 17 00:00:00 2001 From: Andrei Prigorshnev Date: Tue, 27 Apr 2021 19:36:17 +0400 Subject: [PATCH] FIX: No JIT when quoting a mention (#12835) --- .../app/components/composer-editor.js | 28 +++++++++++++++++++ .../tests/acceptance/composer-test.js | 23 +++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/app/assets/javascripts/discourse/app/components/composer-editor.js b/app/assets/javascripts/discourse/app/components/composer-editor.js index 31372910944..a50aee09671 100644 --- a/app/assets/javascripts/discourse/app/components/composer-editor.js +++ b/app/assets/javascripts/discourse/app/components/composer-editor.js @@ -540,6 +540,10 @@ export default Component.extend({ schedule("afterRender", () => { let found = this.warnedGroupMentions || []; $preview.find(".mention-group.notify").each((idx, e) => { + if (this._isInQuote(e)) { + return; + } + const $e = $(e); let name = $e.data("name"); if (found.indexOf(name) === -1) { @@ -860,6 +864,30 @@ export default Component.extend({ this.send("togglePreview"); }, + _isInQuote(element) { + let parent = element.parentElement; + while (parent && !this._isPreviewRoot(parent)) { + if (this._isQuote(parent)) { + return true; + } + + parent = parent.parentElement; + } + + return false; + }, + + _isPreviewRoot(element) { + return ( + element.tagName === "DIV" && + element.classList.contains("d-editor-preview") + ); + }, + + _isQuote(element) { + return element.tagName === "ASIDE" && element.classList.contains("quote"); + }, + actions: { importQuote(toolbarEvent) { this.importQuote(toolbarEvent); diff --git a/app/assets/javascripts/discourse/tests/acceptance/composer-test.js b/app/assets/javascripts/discourse/tests/acceptance/composer-test.js index 5def6eea2dc..99236da5eb9 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/composer-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/composer-test.js @@ -29,6 +29,15 @@ acceptance("Composer", function (needs) { server.get("/posts/419", () => { return helper.response({ id: 419 }); }); + server.get("/u/is_local_username", () => { + return helper.response({ + valid: [], + valid_groups: ["staff"], + mentionable_groups: [{ name: "staff", user_count: 30 }], + cannot_see: [], + max_users_notified_per_group_mention: 100, + }); + }); }); skip("Tests the Composer controls", async function (assert) { @@ -1007,4 +1016,18 @@ acceptance("Composer", function (needs) { await fillIn(".d-editor-input", "[](https://github.com)"); assert.equal(find(".composer-popup").length, 1); }); + + test("Shows the 'group_mentioned' notice", async function (assert) { + await visit("/t/internationalization-localization/280"); + await click("#topic-footer-buttons .create"); + + await fillIn(".d-editor-input", "[quote]\n@staff\n[/quote]"); + assert.notOk( + exists(".composer-popup"), + "Doesn't show the 'group_mentioned' notice in a quote" + ); + + await fillIn(".d-editor-input", "@staff"); + assert.ok(exists(".composer-popup"), "Shows the 'group_mentioned' notice"); + }); });