1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 13:19:44 +02:00

hook with backend

This commit is contained in:
Roman Zavarnitsyn 2025-05-30 00:50:30 +02:00
parent 3f67d9e8bb
commit 946dfea5dd
No known key found for this signature in database
GPG key ID: C00677B27F355C04
8 changed files with 104 additions and 15 deletions

View file

@ -6,6 +6,12 @@
const escapeMarkdown = require('escape-markdown');
const escapeHtml = require('escape-html');
const extractMentionedUserIds = (text) => {
const mentionRegex = /@\[.*?\]\((.*?)\)/g;
const matches = [...text.matchAll(mentionRegex)];
return matches.map((match) => match[1]);
};
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>`;
@ -101,7 +107,14 @@ module.exports = {
comment.userId,
);
const notifiableUserIds = _.union(cardSubscriptionUserIds, boardSubscriptionUserIds);
const mentionedUserIds = extractMentionedUserIds(values.text);
// Combine all user IDs, removing duplicates and the comment author
const notifiableUserIds = [
...cardSubscriptionUserIds,
...boardSubscriptionUserIds,
...mentionedUserIds,
].filter((id) => id !== comment.userId);
await Promise.all(
notifiableUserIds.map((userId) =>
@ -109,10 +122,13 @@ module.exports = {
values: {
userId,
comment,
type: Notification.Types.COMMENT_CARD,
type: mentionedUserIds.includes(userId)
? Notification.Types.COMMENT_MENTION
: Notification.Types.COMMENT_CARD,
data: {
card: _.pick(values.card, ['name']),
text: comment.text,
wasMentioned: mentionedUserIds.includes(userId),
},
creatorUser: values.user,
card: values.card,