mirror of
https://github.com/wekan/wekan.git
synced 2026-02-15 12:38:06 +01:00
Add notification, allow watch boards / lists / cards
This commit is contained in:
parent
9ef8ebaf09
commit
9bbdacc79a
24 changed files with 579 additions and 16 deletions
|
|
@ -48,4 +48,77 @@ if (Meteor.isServer) {
|
|||
createdAt: -1,
|
||||
});
|
||||
});
|
||||
|
||||
Activities.after.insert((userId, doc) => {
|
||||
const activity = Activities.findOne(doc._id);
|
||||
let participants = [];
|
||||
let watchers = [];
|
||||
let title = 'Wekan Notification';
|
||||
let board = null;
|
||||
const description = `act-${activity.activityType}`;
|
||||
const params = {
|
||||
activityId: activity._id,
|
||||
};
|
||||
if (activity.userId) {
|
||||
// No need send notification to user of activity
|
||||
// participants = _.union(participants, [activity.userId]);
|
||||
params.user = activity.user().getName();
|
||||
}
|
||||
if (activity.boardId) {
|
||||
board = activity.board();
|
||||
params.board = board.title;
|
||||
title = 'act-withBoardTitle';
|
||||
params.url = board.absoluteUrl();
|
||||
}
|
||||
if (activity.memberId) {
|
||||
participants = _.union(participants, [activity.memberId]);
|
||||
params.member = activity.member().getName();
|
||||
}
|
||||
if (activity.listId) {
|
||||
const list = activity.list();
|
||||
watchers = _.union(watchers, list.watchers || []);
|
||||
params.list = list.title;
|
||||
}
|
||||
if (activity.oldListId) {
|
||||
const oldList = activity.oldList();
|
||||
watchers = _.union(watchers, oldList.watchers || []);
|
||||
params.oldList = oldList.title;
|
||||
}
|
||||
if (activity.cardId) {
|
||||
const card = activity.card();
|
||||
participants = _.union(participants, [card.userId], card.members || []);
|
||||
watchers = _.union(watchers, card.watchers || []);
|
||||
params.card = card.title;
|
||||
title = 'act-withCardTitle';
|
||||
params.url = card.absoluteUrl();
|
||||
}
|
||||
if (activity.commentId) {
|
||||
const comment = activity.comment();
|
||||
params.comment = comment.text;
|
||||
}
|
||||
if (activity.attachmentId) {
|
||||
const attachment = activity.attachment();
|
||||
params.attachment = attachment._id;
|
||||
}
|
||||
if (board) {
|
||||
const boardWatching = _.pluck(_.where(board.watchers, {level: 'watching'}), 'userId');
|
||||
const boardTracking = _.pluck(_.where(board.watchers, {level: 'tracking'}), 'userId');
|
||||
const boardMuted = _.pluck(_.where(board.watchers, {level: 'muted'}), 'userId');
|
||||
switch(board.getWatchDefault()) {
|
||||
case 'muted':
|
||||
participants = _.intersection(participants, boardTracking);
|
||||
watchers = _.intersection(watchers, boardTracking);
|
||||
break;
|
||||
case 'tracking':
|
||||
participants = _.difference(participants, boardMuted);
|
||||
watchers = _.difference(watchers, boardMuted);
|
||||
break;
|
||||
}
|
||||
watchers = _.union(watchers, boardWatching || []);
|
||||
}
|
||||
|
||||
Notifications.getUsers(participants, watchers).forEach((user) => {
|
||||
Notifications.notify(user, title, description, params);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue