1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-18 12:49:43 +02:00

ref: Little refactoring

This commit is contained in:
Maksim Eltyshev 2025-06-06 12:34:09 +02:00
parent 585464eef3
commit 63de346b0e
8 changed files with 42 additions and 28 deletions

View file

@ -13,7 +13,7 @@ import { Button } from 'semantic-ui-react';
import selectors from '../../../selectors';
import entryActions from '../../../entry-actions';
import { formatTextWithMentions } from '../../../utils/formatters';
import { formatTextWithMentions } from '../../../utils/mentions';
import Paths from '../../../constants/Paths';
import { StaticUserIds } from '../../../constants/StaticUsers';
import { NotificationTypes } from '../../../constants/Enums';

View file

@ -3,7 +3,7 @@
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
const MENTION_REGEX = /@\[(.*?)\]\((.*?)\)/g;
import { MENTION_REGEX } from '../../utils/mentions';
export default (md) => {
md.core.ruler.push('mention', ({ tokens }) => {

View file

@ -1,4 +0,0 @@
const MENTIONS_REGEX = /@\[(.*?)\]\(.*?\)/g;
// eslint-disable-next-line import/prefer-default-export
export const formatTextWithMentions = (text) => text.replace(MENTIONS_REGEX, '@$1');

View file

@ -0,0 +1,9 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
export const MENTION_REGEX = /@\[(.*?)\]\((.*?)\)/g;
export const MENTION_NAME_REGEX = /@\[(.*?)\]\(.*?\)/g;
export const formatTextWithMentions = (text) => text.replace(MENTION_NAME_REGEX, '@$1');

View file

@ -6,13 +6,7 @@
const escapeMarkdown = require('escape-markdown');
const escapeHtml = require('escape-html');
const { formatTextWithMentions } = require('../../../utils/formatters');
const extractMentionedUserIds = (text) => {
const mentionRegex = /@\[.*?\]\((.*?)\)/g;
const matches = [...text.matchAll(mentionRegex)];
return matches.map((match) => match[1]);
};
const { extractMentionIds, formatTextWithMentions } = require('../../../utils/mentions');
const buildAndSendNotifications = async (services, board, card, comment, actorUser, t) => {
const markdownCardLink = `[${escapeMarkdown(card.name)}](${sails.config.custom.baseUrl}/cards/${card.id})`;
@ -99,18 +93,18 @@ module.exports = {
user: values.user,
});
let mentionedUserIds = extractMentionedUserIds(values.text);
let mentionUserIds = extractMentionIds(comment.text);
if (mentionedUserIds.length > 0) {
if (mentionUserIds.length > 0) {
const boardMemberUserIds = await sails.helpers.boards.getMemberUserIds(inputs.board.id);
mentionedUserIds = _.difference(
_.intersection(mentionedUserIds, boardMemberUserIds),
mentionUserIds = _.difference(
_.intersection(mentionUserIds, boardMemberUserIds),
comment.userId,
);
}
const mentionedUserIdsSet = new Set(mentionedUserIds);
const mentionUserIdsSet = new Set(mentionUserIds);
const cardSubscriptionUserIds = await sails.helpers.cards.getSubscriptionUserIds(
comment.cardId,
@ -123,7 +117,7 @@ module.exports = {
);
const notifiableUserIds = _.union(
mentionedUserIds,
mentionUserIds,
cardSubscriptionUserIds,
boardSubscriptionUserIds,
);
@ -134,7 +128,7 @@ module.exports = {
values: {
userId,
comment,
type: mentionedUserIdsSet.has(userId)
type: mentionUserIdsSet.has(userId)
? Notification.Types.MENTION_IN_COMMENT
: Notification.Types.COMMENT_CARD,
data: {

View file

@ -6,7 +6,7 @@
const escapeMarkdown = require('escape-markdown');
const escapeHtml = require('escape-html');
const { formatTextWithMentions } = require('../../../utils/formatters');
const { formatTextWithMentions } = require('../../../utils/mentions');
const buildTitle = (notification, t) => {
switch (notification.type) {

View file

@ -1,7 +0,0 @@
const MENTIONS_REGEX = /@\[(.*?)\]\(.*?\)/g;
const formatTextWithMentions = (text) => text.replace(MENTIONS_REGEX, '@$1');
module.exports = {
formatTextWithMentions,
};

22
server/utils/mentions.js Normal file
View file

@ -0,0 +1,22 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
const MENTION_ID_REGEX = /@\[.*?\]\((.*?)\)/g;
const MENTION_NAME_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');
module.exports = {
MENTION_ID_REGEX,
MENTION_NAME_REGEX,
extractMentionIds,
formatTextWithMentions,
};