Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: No JIT when quoting a mention #12835

Merged
merged 2 commits into from Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions app/assets/javascripts/discourse/app/components/composer-editor.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
23 changes: 23 additions & 0 deletions app/assets/javascripts/discourse/tests/acceptance/composer-test.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
});
});