mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-05 12:01:17 +01:00
Merge pull request #5630 from NodeBB/notif-abort
Add more hooks for messaging, allow notification hook to abort the push
This commit is contained in:
@@ -172,6 +172,14 @@ Messaging.getRecentChats = function (callerUid, uid, start, stop, callback) {
|
||||
|
||||
next(null, { rooms: results.roomData, nextStart: stop + 1 });
|
||||
},
|
||||
function (ref, next) {
|
||||
plugins.fireHook('filter:messaging.getRecentChats', {
|
||||
rooms: ref.rooms,
|
||||
nextStart: ref.nextStart,
|
||||
uid: uid,
|
||||
callerUid: callerUid,
|
||||
}, next);
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -252,11 +260,16 @@ Messaging.canMessageUser = function (uid, toUid, callback) {
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
if (!results.settings.restrictChat || results.isAdmin || results.isFollowing) {
|
||||
return next();
|
||||
if (results.settings.restrictChat && !results.isAdmin && !results.isFollowing) {
|
||||
return next(new Error('[[error:chat-restricted]]'));
|
||||
}
|
||||
|
||||
next(new Error('[[error:chat-restricted]]'));
|
||||
plugins.fireHook('static:messaging.canMessageUser', {
|
||||
uid: uid,
|
||||
toUid: toUid,
|
||||
}, function (err) {
|
||||
next(err);
|
||||
});
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
@@ -293,7 +306,12 @@ Messaging.canMessageRoom = function (uid, roomId, callback) {
|
||||
return next(new Error('[[error:email-not-confirmed-chat]]'));
|
||||
}
|
||||
|
||||
next();
|
||||
plugins.fireHook('static:messaging.canMessageRoom', {
|
||||
uid: uid,
|
||||
roomId: roomId,
|
||||
}, function (err) {
|
||||
next(err);
|
||||
});
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@ var S = require('string');
|
||||
var db = require('../database');
|
||||
var user = require('../user');
|
||||
var utils = require('../utils');
|
||||
var plugins = require('../plugins');
|
||||
|
||||
module.exports = function (Messaging) {
|
||||
Messaging.newMessageCutoff = 1000 * 60 * 3;
|
||||
@@ -130,6 +131,17 @@ module.exports = function (Messaging) {
|
||||
next(null, []);
|
||||
}
|
||||
},
|
||||
function (messages, next) {
|
||||
plugins.fireHook('filter:messaging.getMessages', {
|
||||
messages: messages,
|
||||
uid: uid,
|
||||
roomId: roomId,
|
||||
isNew: isNew,
|
||||
mids: mids,
|
||||
}, function (err, data) {
|
||||
next(err, data && data.messages);
|
||||
});
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -9,6 +9,7 @@ var emailer = require('../emailer');
|
||||
var notifications = require('../notifications');
|
||||
var meta = require('../meta');
|
||||
var sockets = require('../socket.io');
|
||||
var plugins = require('../plugins');
|
||||
|
||||
module.exports = function (Messaging) {
|
||||
Messaging.notifyQueue = {}; // Only used to notify a user of a new chat message, see Messaging.notifyUser
|
||||
@@ -25,8 +26,18 @@ module.exports = function (Messaging) {
|
||||
roomId: roomId,
|
||||
fromUid: fromUid,
|
||||
message: messageObj,
|
||||
uids: uids,
|
||||
};
|
||||
|
||||
plugins.fireHook('filter:messaging.notify', data, next);
|
||||
},
|
||||
function (data, next) {
|
||||
if (!data || !data.uids || !data.uids.length) {
|
||||
return next();
|
||||
}
|
||||
|
||||
var uids = data.uids;
|
||||
|
||||
uids.forEach(function (uid) {
|
||||
data.self = parseInt(uid, 10) === parseInt(fromUid, 10) ? 1 : 0;
|
||||
Messaging.pushUnreadCount(uid);
|
||||
|
||||
@@ -194,6 +194,10 @@ function pushToUids(uids, notification, callback) {
|
||||
plugins.fireHook('filter:notification.push', { notification: notification, uids: uids }, next);
|
||||
},
|
||||
function (data, next) {
|
||||
if (!data || !data.notification || !data.uids || !data.uids.length) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
uids = data.uids;
|
||||
notification = data.notification;
|
||||
|
||||
@@ -246,7 +250,6 @@ Notifications.pushGroups = function (notification, groupNames, callback) {
|
||||
}
|
||||
|
||||
var members = _.unique(_.flatten(groupMembers));
|
||||
|
||||
Notifications.push(notification, members, callback);
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user