fix: Improve mentions behavior

This commit is contained in:
Maksim Eltyshev
2025-08-11 13:52:17 +02:00
parent cbb00d1d59
commit 6515877eb6
9 changed files with 89 additions and 30 deletions

View File

@@ -6,12 +6,12 @@
const escapeMarkdown = require('escape-markdown');
const escapeHtml = require('escape-html');
const { extractMentionIds, formatTextWithMentions } = require('../../../utils/mentions');
const { extractMentionIds, mentionMarkupToText } = require('../../../utils/mentions');
const buildAndSendNotifications = async (services, board, card, comment, actorUser, t) => {
const markdownCardLink = `[${escapeMarkdown(card.name)}](${sails.config.custom.baseUrl}/cards/${card.id})`;
const htmlCardLink = `<a href="${sails.config.custom.baseUrl}/cards/${card.id}}">${escapeHtml(card.name)}</a>`;
const commentText = _.truncate(formatTextWithMentions(comment.text));
const commentText = _.truncate(mentionMarkupToText(comment.text));
await sails.helpers.utils.sendNotifications(services, t('New Comment'), {
text: `${t(
@@ -101,10 +101,9 @@ module.exports = {
if (mentionUserIds.length > 0) {
const boardMemberUserIds = await sails.helpers.boards.getMemberUserIds(inputs.board.id);
mentionUserIds = _.difference(
_.intersection(mentionUserIds, boardMemberUserIds),
mentionUserIds = _.difference(_.intersection(mentionUserIds, boardMemberUserIds), [
comment.userId,
);
]);
}
const mentionUserIdsSet = new Set(mentionUserIds);

View File

@@ -6,7 +6,7 @@
const escapeMarkdown = require('escape-markdown');
const escapeHtml = require('escape-html');
const { formatTextWithMentions } = require('../../../utils/mentions');
const { mentionMarkupToText } = require('../../../utils/mentions');
const buildTitle = (notification, t) => {
switch (notification.type) {
@@ -60,7 +60,7 @@ const buildBodyByFormat = (board, card, notification, actorUser, t) => {
};
}
case Notification.Types.COMMENT_CARD: {
const commentText = _.truncate(formatTextWithMentions(notification.data.text));
const commentText = _.truncate(mentionMarkupToText(notification.data.text));
return {
text: `${t(
@@ -100,7 +100,7 @@ const buildBodyByFormat = (board, card, notification, actorUser, t) => {
),
};
case Notification.Types.MENTION_IN_COMMENT: {
const commentText = _.truncate(formatTextWithMentions(notification.data.text));
const commentText = _.truncate(mentionMarkupToText(notification.data.text));
return {
text: `${t(

View File

@@ -4,19 +4,17 @@
*/
const MENTION_ID_REGEX = /@\[.*?\]\((.*?)\)/g;
const MENTION_NAME_REGEX = /@\[(.*?)\]\(.*?\)/g;
const MENTION_USERNAME_REGEX = /@\[(.*?)\]\(.*?\)/g;
const extractMentionIds = (text) => {
const matches = [...text.matchAll(MENTION_ID_REGEX)];
return matches.map((match) => match[1]);
};
const formatTextWithMentions = (text) => text.replace(MENTION_NAME_REGEX, '@$1');
const mentionMarkupToText = (markup) =>
markup.replace(MENTION_USERNAME_REGEX, (_, username) => `@${username}`);
module.exports = {
MENTION_ID_REGEX,
MENTION_NAME_REGEX,
extractMentionIds,
formatTextWithMentions,
mentionMarkupToText,
};