mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-23 17:00:24 +01:00
add canReply to messages
This commit is contained in:
@@ -62,7 +62,7 @@
|
|||||||
"nodebb-plugin-spam-be-gone": "0.4.10",
|
"nodebb-plugin-spam-be-gone": "0.4.10",
|
||||||
"nodebb-rewards-essentials": "0.0.9",
|
"nodebb-rewards-essentials": "0.0.9",
|
||||||
"nodebb-theme-lavender": "3.0.15",
|
"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-theme-vanilla": "5.1.56",
|
||||||
"nodebb-widget-essentials": "2.0.13",
|
"nodebb-widget-essentials": "2.0.13",
|
||||||
"nodemailer": "2.6.4",
|
"nodemailer": "2.6.4",
|
||||||
|
|||||||
@@ -56,13 +56,14 @@ chatsController.get = function (req, res, callback) {
|
|||||||
}
|
}
|
||||||
async.parallel({
|
async.parallel({
|
||||||
users: async.apply(messaging.getUsersInRoom, req.params.roomid, 0, -1),
|
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, {
|
messages: async.apply(messaging.getMessages, {
|
||||||
callerUid: req.uid,
|
callerUid: req.uid,
|
||||||
uid: uid,
|
uid: uid,
|
||||||
roomId: req.params.roomid,
|
roomId: req.params.roomid,
|
||||||
isNew: false
|
isNew: false
|
||||||
}),
|
})
|
||||||
room: async.apply(messaging.getRoomData, req.params.roomid)
|
|
||||||
}, next);
|
}, next);
|
||||||
}
|
}
|
||||||
], function (err, data) {
|
], 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;
|
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.groupChat = room.hasOwnProperty('groupChat') ? room.groupChat : room.users.length > 2;
|
||||||
room.rooms = recentChats.rooms;
|
room.rooms = recentChats.rooms;
|
||||||
room.uid = uid;
|
room.uid = uid;
|
||||||
|
|||||||
@@ -209,4 +209,18 @@ module.exports = function (Messaging) {
|
|||||||
], callback);
|
], 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({
|
async.parallel({
|
||||||
roomData: async.apply(Messaging.getRoomData, data.roomId),
|
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),
|
users: async.apply(Messaging.getUsersInRoom, data.roomId, 0, -1),
|
||||||
messages: async.apply(Messaging.getMessages, {
|
messages: async.apply(Messaging.getMessages, {
|
||||||
callerUid: socket.uid,
|
callerUid: socket.uid,
|
||||||
@@ -125,6 +126,7 @@ SocketModules.chats.loadRoom = function (socket, data, callback) {
|
|||||||
},
|
},
|
||||||
function (results, next) {
|
function (results, next) {
|
||||||
results.roomData.users = results.users;
|
results.roomData.users = results.users;
|
||||||
|
results.roomData.canReply = results.canReply;
|
||||||
results.roomData.usernames = Messaging.generateUsernames(results.users, socket.uid);
|
results.roomData.usernames = Messaging.generateUsernames(results.users, socket.uid);
|
||||||
results.roomData.messages = results.messages;
|
results.roomData.messages = results.messages;
|
||||||
results.roomData.groupChat = results.roomData.hasOwnProperty('groupChat') ? results.roomData.groupChat : results.users.length > 2;
|
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);
|
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) {
|
User.getUsernameByEmail = function (email, callback) {
|
||||||
db.sortedSetScore('email:uid', email.toLowerCase(), function (err, uid) {
|
db.sortedSetScore('email:uid', email.toLowerCase(), function (err, uid) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user