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: Do not consider code-blocks when parsing mentions #23280
FIX: Do not consider code-blocks when parsing mentions #23280
Conversation
9e92875
to
9f07381
Compare
@@ -2125,15 +2125,15 @@ class PluginApi { | |||
* Support for setting a Sidebar panel. | |||
*/ | |||
setSidebarPanel(name) { | |||
this._lookupContainer("service:sidebar-state").setPanel(name); | |||
this._lookupContainer("service:sidebar-state")?.setPanel(name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and following methods get called during the route's deactivation and at that moment service is null. That lead to errors in tests, so I've added safe navigation here.
currentMessage.cook().then(() => { | ||
const mentions = parseMentionedUsernames(currentMessage.cooked); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are only two changes in this method:
- Now we call
currentMessage.cook()
before parsing mentions - We call
parseMentionedUsernames(currentMessage.cooked)
instead ofthis._extractMentions(currentMessage.message)
9f07381
to
2df6952
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requesting changes while you address concerns of Sam
63ddfa4
to
4c9875a
Compare
@jjaffeux I've pushed commits that address those concerns. With this commit, instead of parsing mentions from HTML we use the Markdown parser:
|
if (this.mentionsCount > 0) { | ||
this.tooManyMentions = | ||
this.mentionsCount > this.siteSettings.max_mentions_per_chat_message; | ||
currentMessage.parseMentions().then((mentions) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After the last commits, this line is the only significant change to this function, we called this._extractMentions
before, now we call currentMessage.parseMentions()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good 👍
@AndrewPrigorshnev is that expected that this will not consider the first (valid) test("doesn't consider code-blocks when counting mentions", async function (assert) {
this.siteSettings.max_mentions_per_chat_message = 2;
await visit(`/chat/c/-/${channelId}`);
// since @bar is inside a code-block it shouldn't be considered a mention
const message = `Hey @user1 @user2 @bar
\`\`\`
def foo
@bar = true
end
\`\`\`
`;
await fillIn(".chat-composer__input", message);
assert.dom(".chat-mention-warnings").doesNotExist();
}); |
That should consider it. I've just tried it locally, added In case you tested that not in tests, but in an actual chat channel, you may not see a warning because the default value for
|
Yes I think it's fine indeed, I think I misunderstood the test at first, all good 👍 |
656e045
to
e48a9a4
Compare
e48a9a4
to
80c105d
Compare
We have the
max_mentions_per_chat_message
site settings; when a user tries to mention more users than allowed, no one gets mentioned.Chat messages may contain code-blocks with strings that look like mentions:
The problem is that the parsing code considers these as real mentions and counts them when checking the limit. This PR fixes the problem.
I also made these simple refactorings along the way: