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

feat: Add notification when user is added to card

This commit is contained in:
Maksim Eltyshev 2025-05-17 01:50:40 +02:00
parent f43785c3d0
commit f6568ce41b
14 changed files with 169 additions and 39 deletions

View file

@ -143,55 +143,76 @@ module.exports = {
});
if (action.type !== Action.Types.CREATE_CARD) {
const cardSubscriptionUserIds = await sails.helpers.cards.getSubscriptionUserIds(
action.cardId,
action.userId,
);
const boardSubscriptionUserIds = await sails.helpers.boards.getSubscriptionUserIds(
inputs.board.id,
action.userId,
);
const notifiableUserIds = _.union(cardSubscriptionUserIds, boardSubscriptionUserIds);
await Promise.all(
notifiableUserIds.map((userId) =>
sails.helpers.notifications.createOne.with({
if (action.type === Action.Types.ADD_MEMBER_TO_CARD) {
if (values.user !== action.data.user.id) {
await sails.helpers.notifications.createOne.with({
values: {
userId,
action,
type: action.type,
data: {
...action.data,
card: _.pick(values.card, ['name']),
},
userId: action.data.user.id,
creatorUser: values.user,
card: values.card,
},
project: inputs.project,
board: inputs.board,
list: inputs.list,
}),
),
);
}
});
}
} else {
const cardSubscriptionUserIds = await sails.helpers.cards.getSubscriptionUserIds(
action.cardId,
action.userId,
);
const notificationServices = await NotificationService.qm.getByBoardId(inputs.board.id);
const boardSubscriptionUserIds = await sails.helpers.boards.getSubscriptionUserIds(
inputs.board.id,
action.userId,
);
if (notificationServices.length > 0) {
const services = notificationServices.map((notificationService) =>
_.pick(notificationService, ['url', 'format']),
);
const notifiableUserIds = _.union(cardSubscriptionUserIds, boardSubscriptionUserIds);
buildAndSendNotifications(
services,
inputs.board,
values.card,
action,
values.user,
sails.helpers.utils.makeTranslator(),
);
await Promise.all(
notifiableUserIds.map((userId) =>
sails.helpers.notifications.createOne.with({
values: {
userId,
action,
type: action.type,
data: {
...action.data,
card: _.pick(values.card, ['name']),
},
creatorUser: values.user,
card: values.card,
},
project: inputs.project,
board: inputs.board,
list: inputs.list,
}),
),
);
const notificationServices = await NotificationService.qm.getByBoardId(inputs.board.id);
if (notificationServices.length > 0) {
const services = notificationServices.map((notificationService) =>
_.pick(notificationService, ['url', 'format']),
);
buildAndSendNotifications(
services,
inputs.board,
values.card,
action,
values.user,
sails.helpers.utils.makeTranslator(),
);
}
}
}
return action;