This commit is contained in:
Julian Lam
2014-10-30 17:50:07 -04:00
parent 28f87cc776
commit adfb89a2ad
8 changed files with 95 additions and 34 deletions

View File

@@ -292,6 +292,34 @@ var db = require('./database'),
}, 1000*60); // wait 60s before sending
};
Messaging.canMessage = function(fromUid, toUid, callback) {
async.waterfall([
function(next) {
// Check if the sending user is an admin
user.isAdministrator(fromUid, function(err, isAdmin) {
next(err || isAdmin);
});
},
function(next) {
// Retrieve the recipient's user setting
user.getSettings(toUid, function(err, settings) {
next(err || !settings.restrictChat);
});
},
function(next) {
// Does toUid follow fromUid?
user.isFollowing(toUid, fromUid, next);
}
], function(err, allowed) {
// Handle premature returns
if (err === true) {
return callback(undefined, true);
}
callback.apply(this, arguments);
});
}
function sendNotifications(fromuid, touid, messageObj, callback) {
// todo #1798 -- this should check if the user is in room `chat_{uidA}_{uidB}` instead, see `Sockets.uidInRoom(uid, room);`
if (!websockets.isUserOnline(touid)) {