add canReply to messages

v1.18.x
barisusakli 8 years ago
parent 83c50f0648
commit dada858565

@ -62,7 +62,7 @@
"nodebb-plugin-spam-be-gone": "0.4.10",
"nodebb-rewards-essentials": "0.0.9",
"nodebb-theme-lavender": "3.0.15",
"nodebb-theme-persona": "4.1.86",
"nodebb-theme-persona": "4.1.87",
"nodebb-theme-vanilla": "5.1.56",
"nodebb-widget-essentials": "2.0.13",
"nodemailer": "2.6.4",

@ -56,13 +56,14 @@ chatsController.get = function (req, res, callback) {
}
async.parallel({
users: async.apply(messaging.getUsersInRoom, req.params.roomid, 0, -1),
canReply: async.apply(messaging.canReply, req.params.roomid, req.uid),
room: async.apply(messaging.getRoomData, req.params.roomid),
messages: async.apply(messaging.getMessages, {
callerUid: req.uid,
uid: uid,
roomId: req.params.roomid,
isNew: false
}),
room: async.apply(messaging.getRoomData, req.params.roomid)
})
}, next);
}
], function (err, data) {
@ -77,6 +78,7 @@ chatsController.get = function (req, res, callback) {
return user && parseInt(user.uid, 10) && parseInt(user.uid, 10) !== req.uid;
});
room.canReply = data.canReply;
room.groupChat = room.hasOwnProperty('groupChat') ? room.groupChat : room.users.length > 2;
room.rooms = recentChats.rooms;
room.uid = uid;

@ -209,4 +209,18 @@ module.exports = function (Messaging) {
], callback);
};
Messaging.canReply = function (roomId, uid, callback) {
async.waterfall([
function (next) {
db.isSortedSetMember('chat:room:' + roomId + ':uids', uid, next);
},
function (inRoom, next) {
plugins.fireHook('filter:messaging.canReply', {uid: uid, roomId: roomId, inRoom: inRoom, canReply: inRoom}, next);
},
function (data, next) {
next(null, data.canReply);
}
], callback);
};
};

@ -114,6 +114,7 @@ SocketModules.chats.loadRoom = function (socket, data, callback) {
async.parallel({
roomData: async.apply(Messaging.getRoomData, data.roomId),
canReply: async.apply(Messaging.canReply, data.roomId, socket.uid),
users: async.apply(Messaging.getUsersInRoom, data.roomId, 0, -1),
messages: async.apply(Messaging.getMessages, {
callerUid: socket.uid,
@ -125,6 +126,7 @@ SocketModules.chats.loadRoom = function (socket, data, callback) {
},
function (results, next) {
results.roomData.users = results.users;
results.roomData.canReply = results.canReply;
results.roomData.usernames = Messaging.generateUsernames(results.users, socket.uid);
results.roomData.messages = results.messages;
results.roomData.groupChat = results.roomData.hasOwnProperty('groupChat') ? results.roomData.groupChat : results.users.length > 2;

@ -222,6 +222,13 @@ var meta = require('./meta');
db.sortedSetScore('email:uid', email.toLowerCase(), callback);
};
User.getUidsByEmails = function (emails, callback) {
emails = emails.map(function(email) {
return email && email.toLowerCase();
});
db.sortedSetScores('email:uid', emails, callback);
};
User.getUsernameByEmail = function (email, callback) {
db.sortedSetScore('email:uid', email.toLowerCase(), function (err, uid) {
if (err) {

Loading…
Cancel
Save