Add more messaging hooks

v1.18.x
Peter Jaszkowiak 8 years ago
parent 3350a89791
commit 42e21d5aa9

@ -172,6 +172,14 @@ Messaging.getRecentChats = function (callerUid, uid, start, stop, callback) {
next(null, { rooms: results.roomData, nextStart: stop + 1 }); 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); ], callback);
}; };
@ -252,11 +260,16 @@ Messaging.canMessageUser = function (uid, toUid, callback) {
}, next); }, next);
}, },
function (results, next) { function (results, next) {
if (!results.settings.restrictChat || results.isAdmin || results.isFollowing) { if (results.settings.restrictChat && !results.isAdmin && !results.isFollowing) {
return next(); return next(new Error('[[error:chat-restricted]]'));
} }
next(new Error('[[error:chat-restricted]]')); plugins.fireHook('filter:messaging.canMessageUser', {
uid: uid,
toUid: toUid,
}, function (err) {
next(err);
});
}, },
], callback); ], callback);
}; };

@ -6,6 +6,7 @@ var S = require('string');
var db = require('../database'); var db = require('../database');
var user = require('../user'); var user = require('../user');
var utils = require('../utils'); var utils = require('../utils');
var plugins = require('../plugins');
module.exports = function (Messaging) { module.exports = function (Messaging) {
Messaging.getMessageField = function (mid, field, callback) { Messaging.getMessageField = function (mid, field, callback) {
@ -128,6 +129,17 @@ module.exports = function (Messaging) {
next(null, []); next(null, []);
} }
}, },
function (messages, next) {
plugins.fireHook('filter:messaging.getMessagesData', {
messages: messages,
uid: uid,
roomId: roomId,
isNew: isNew,
mids: mids,
}, function (err, data) {
next(err, data && data.messages);
});
},
], callback); ], callback);
}; };
}; };

@ -9,6 +9,7 @@ var emailer = require('../emailer');
var notifications = require('../notifications'); var notifications = require('../notifications');
var meta = require('../meta'); var meta = require('../meta');
var sockets = require('../socket.io'); var sockets = require('../socket.io');
var plugins = require('../plugins');
module.exports = function (Messaging) { module.exports = function (Messaging) {
Messaging.notifyQueue = {}; // Only used to notify a user of a new chat message, see Messaging.notifyUser Messaging.notifyQueue = {}; // Only used to notify a user of a new chat message, see Messaging.notifyUser
@ -27,6 +28,15 @@ module.exports = function (Messaging) {
message: messageObj, message: messageObj,
}; };
plugins.fireHook('filter:messaging.notifyUsersInRoom', data, next);
},
function (data, next) {
if (!data || !data.uids || !data.uids.length) {
return next();
}
var uids = data.uids;
uids.forEach(function (uid) { uids.forEach(function (uid) {
data.self = parseInt(uid, 10) === parseInt(fromUid, 10) ? 1 : 0; data.self = parseInt(uid, 10) === parseInt(fromUid, 10) ? 1 : 0;
Messaging.pushUnreadCount(uid); Messaging.pushUnreadCount(uid);

Loading…
Cancel
Save