mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 02:25:55 +01:00
closes #5070
This commit is contained in:
@@ -74,6 +74,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.groupChat = room.hasOwnProperty('groupChat') ? room.groupChat : room.users.length > 2;
|
||||||
room.rooms = recentChats.rooms;
|
room.rooms = recentChats.rooms;
|
||||||
room.uid = uid;
|
room.uid = uid;
|
||||||
room.userslug = req.params.userslug;
|
room.userslug = req.params.userslug;
|
||||||
|
|||||||
@@ -265,7 +265,7 @@ var async = require('async'),
|
|||||||
},
|
},
|
||||||
users: function(next) {
|
users: function(next) {
|
||||||
async.map(roomIds, function(roomId, next) {
|
async.map(roomIds, function(roomId, next) {
|
||||||
db.getSortedSetRevRange('chat:room:' + roomId + ':uids', 0, 3, function(err, uids) {
|
db.getSortedSetRevRange('chat:room:' + roomId + ':uids', 0, 9, function(err, uids) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,7 @@ module.exports = function(Messaging) {
|
|||||||
if (err || !data) {
|
if (err || !data) {
|
||||||
return callback(err || new Error('[[error:no-chat-room]]'));
|
return callback(err || new Error('[[error:no-chat-room]]'));
|
||||||
}
|
}
|
||||||
data.roomName = data.roomName || '[[modules:chat.roomname, ' + roomId + ']]';
|
modifyRoomData([data]);
|
||||||
if (data.roomName) {
|
|
||||||
data.roomName = validator.escape(String(data.roomName));
|
|
||||||
}
|
|
||||||
callback(null, data);
|
callback(null, data);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -29,16 +26,23 @@ module.exports = function(Messaging) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
roomData.forEach(function(data) {
|
modifyRoomData(roomData);
|
||||||
if (data) {
|
|
||||||
data.roomName = data.roomName || '[[modules:chat.roomname, ' + data.roomId + ']]';
|
|
||||||
data.roomName = validator.escape(String(data.roomName));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
callback(null, roomData);
|
callback(null, roomData);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function modifyRoomData(rooms) {
|
||||||
|
rooms.forEach(function(data) {
|
||||||
|
if (data) {
|
||||||
|
data.roomName = data.roomName || '[[modules:chat.roomname, ' + data.roomId + ']]';
|
||||||
|
data.roomName = validator.escape(String(data.roomName));
|
||||||
|
if (data.hasOwnProperty('groupChat')) {
|
||||||
|
data.groupChat = parseInt(data.groupChat, 10) === 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Messaging.newRoom = function(uid, toUids, callback) {
|
Messaging.newRoom = function(uid, toUids, callback) {
|
||||||
var roomId;
|
var roomId;
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
@@ -105,6 +109,18 @@ module.exports = function(Messaging) {
|
|||||||
return now;
|
return now;
|
||||||
});
|
});
|
||||||
db.sortedSetAdd('chat:room:' + roomId + ':uids', timestamps, uids, next);
|
db.sortedSetAdd('chat:room:' + roomId + ':uids', timestamps, uids, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
async.parallel({
|
||||||
|
userCount: async.apply(db.sortedSetCard, 'chat:room:' + roomId + ':uids'),
|
||||||
|
roomData: async.apply(db.getObject, 'chat:room:' + roomId)
|
||||||
|
}, next);
|
||||||
|
},
|
||||||
|
function(results, next) {
|
||||||
|
if (!results.roomData.hasOwnProperty('groupChat') && results.userCount > 2) {
|
||||||
|
return db.setObjectField('chat:room:' + roomId, 'groupChat', 1, next);
|
||||||
|
}
|
||||||
|
next();
|
||||||
}
|
}
|
||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -133,6 +133,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.groupChat = results.roomData.hasOwnProperty('groupChat') ? results.roomData.groupChat : results.users.length > 2;
|
||||||
results.roomData.isOwner = parseInt(results.roomData.owner, 10) === socket.uid;
|
results.roomData.isOwner = parseInt(results.roomData.owner, 10) === socket.uid;
|
||||||
results.roomData.maximumUsersInChatRoom = parseInt(meta.config.maximumUsersInChatRoom, 10) || 0;
|
results.roomData.maximumUsersInChatRoom = parseInt(meta.config.maximumUsersInChatRoom, 10) || 0;
|
||||||
results.roomData.showUserInput = !results.roomData.maximumUsersInChatRoom || results.roomData.maximumUsersInChatRoom > 2;
|
results.roomData.showUserInput = !results.roomData.maximumUsersInChatRoom || results.roomData.maximumUsersInChatRoom > 2;
|
||||||
|
|||||||
Reference in New Issue
Block a user