mirror of
https://github.com/wekan/wekan.git
synced 2026-01-05 17:18:49 +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
server/notifications/notifications.js
Normal file
48
server/notifications/notifications.js
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
// a map of notification service, like email, web, IM, qq, etc.
|
||||
|
||||
// serviceName -> callback(user, title, description, params)
|
||||
// expected arguments to callback:
|
||||
// - user: Meteor user object
|
||||
// - title: String, TAPi18n key
|
||||
// - description, String, TAPi18n key
|
||||
// - params: Object, values extracted from context, to used for above two TAPi18n keys
|
||||
// see example call to Notifications.notify() in models/activities.js
|
||||
const notifyServices = {};
|
||||
|
||||
Notifications = {
|
||||
subscribe: (serviceName, callback) => {
|
||||
notifyServices[serviceName] = callback;
|
||||
},
|
||||
|
||||
unsubscribe: (serviceName) => {
|
||||
if (typeof notifyServices[serviceName] === 'function')
|
||||
delete notifyServices[serviceName];
|
||||
},
|
||||
|
||||
// filter recipients according to user settings for notification
|
||||
getUsers: (participants, watchers) => {
|
||||
const userMap = {};
|
||||
participants.forEach((userId) => {
|
||||
if (userMap[userId]) return;
|
||||
const user = Users.findOne(userId);
|
||||
if (user && user.hasTag('notify-participate')) {
|
||||
userMap[userId] = user;
|
||||
}
|
||||
});
|
||||
watchers.forEach((userId) => {
|
||||
if (userMap[userId]) return;
|
||||
const user = Users.findOne(userId);
|
||||
if (user && user.hasTag('notify-watch')) {
|
||||
userMap[userId] = user;
|
||||
}
|
||||
});
|
||||
return _.map(userMap, (v) => v);
|
||||
},
|
||||
|
||||
notify: (user, title, description, params) => {
|
||||
for(const k in notifyServices) {
|
||||
const notifyImpl = notifyServices[k];
|
||||
if (notifyImpl && typeof notifyImpl === 'function') notifyImpl(user, title, description, params);
|
||||
}
|
||||
},
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue