mirror of
https://github.com/plankanban/planka.git
synced 2025-12-24 09:15:01 +03:00
fix: Improve mentions behavior
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user