From dada8585658ea6ab038a1214676edf6c0b842767 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 18 Nov 2016 17:35:05 +0300 Subject: [PATCH] add canReply to messages --- package.json | 2 +- src/controllers/accounts/chats.js | 6 ++++-- src/messaging/rooms.js | 14 ++++++++++++++ src/socket.io/modules.js | 2 ++ src/user.js | 7 +++++++ 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 654c45bff8..44a2c1003b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/controllers/accounts/chats.js b/src/controllers/accounts/chats.js index f70b9b4db8..c951bafdbd 100644 --- a/src/controllers/accounts/chats.js +++ b/src/controllers/accounts/chats.js @@ -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; diff --git a/src/messaging/rooms.js b/src/messaging/rooms.js index 2687448c56..bea909946a 100644 --- a/src/messaging/rooms.js +++ b/src/messaging/rooms.js @@ -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); + }; + }; \ No newline at end of file diff --git a/src/socket.io/modules.js b/src/socket.io/modules.js index f74e077c5c..46f3804c03 100644 --- a/src/socket.io/modules.js +++ b/src/socket.io/modules.js @@ -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; diff --git a/src/user.js b/src/user.js index 31dda0d991..f6bdc07902 100644 --- a/src/user.js +++ b/src/user.js @@ -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) {