mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 00:43:24 +08:00
9c8043a4d2
* FEATURE: Enforce mention limits for chat messages The first part of these changes adds a new setting called `max_mentions_per_chat_message`, which skips notifications when the message contains too many mentions. It also respects the `max_users_notified_per_group_mention` setting and skips notifications if expanding a group mention would exceed it. We also include a new component to display JIT warning for these limits to the user while composing a message. * Simplify ignoring/muting filter in chat_notifier * Post-send warnings for unsent warnings * Improve pluralization * Address review feedback * Fix test * Address second feedback round * Third round of feedback Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
37 lines
943 B
JavaScript
37 lines
943 B
JavaScript
import { mentionRegex } from "pretty-text/mentions";
|
|
|
|
function addMention(buffer, matches, state) {
|
|
let username = matches[1] || matches[2];
|
|
let tag = "span";
|
|
let className = "mention";
|
|
|
|
let token = new state.Token("mention_open", tag, 1);
|
|
token.attrs = [["class", className]];
|
|
|
|
buffer.push(token);
|
|
|
|
token = new state.Token("text", "", 0);
|
|
token.content = "@" + username;
|
|
|
|
buffer.push(token);
|
|
|
|
token = new state.Token("mention_close", tag, -1);
|
|
buffer.push(token);
|
|
}
|
|
|
|
export function setup(helper) {
|
|
helper.registerOptions((opts, siteSettings) => {
|
|
opts.features.mentions = !!siteSettings.enable_mentions;
|
|
opts.features.unicodeUsernames = !!siteSettings.unicode_usernames;
|
|
});
|
|
|
|
helper.registerPlugin((md) => {
|
|
const rule = {
|
|
matcher: mentionRegex(md.options.discourse.features.unicodeUsernames),
|
|
onMatch: addMention,
|
|
};
|
|
|
|
md.core.textPostProcess.ruler.push("mentions", rule);
|
|
});
|
|
}
|