summaryrefslogtreecommitdiffstats
path: root/models/activities.js
diff options
context:
space:
mode:
authorLiming Xie <liming.xie@gmail.com>2016-01-05 23:26:02 +0800
committerLiming Xie <liming.xie@gmail.com>2016-01-05 23:26:02 +0800
commit9bbdacc79a89667e0d6f1ed30c415e5350ad468b (patch)
treefc6d9918dcd77699295ecb5bdbaf59f9d7c2f479 /models/activities.js
parent9ef8ebaf09e52d7133ebe08ab1354ef663ee948b (diff)
downloadwekan-9bbdacc79a89667e0d6f1ed30c415e5350ad468b.tar.gz
wekan-9bbdacc79a89667e0d6f1ed30c415e5350ad468b.tar.bz2
wekan-9bbdacc79a89667e0d6f1ed30c415e5350ad468b.zip
Add notification, allow watch boards / lists / cards
Diffstat (limited to 'models/activities.js')
-rw-r--r--models/activities.js73
1 files changed, 73 insertions, 0 deletions
diff --git a/models/activities.js b/models/activities.js
index 5de07ee5..0aa4fa54 100644
--- a/models/activities.js
+++ b/models/activities.js
@@ -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);
+ });
+ });
}