mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-06 15:42:52 +01:00
closes #3983
This commit is contained in:
@@ -103,6 +103,7 @@
|
||||
"invalid-chat-message": "Invalid chat message",
|
||||
"chat-message-too-long": "Chat message is too long",
|
||||
"cant-edit-chat-message": "You are not allowed to edit this message",
|
||||
"cant-remove-last-user": "You can't remove the last user",
|
||||
|
||||
"reputation-system-disabled": "Reputation system is disabled.",
|
||||
"downvoting-disabled": "Downvoting is disabled",
|
||||
|
||||
@@ -231,11 +231,22 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll',
|
||||
});
|
||||
|
||||
tagEl.on('beforeItemRemove', function(event) {
|
||||
event.cancel = !data.isOwner;
|
||||
event.cancel = !data.isOwner || data.users.length < 2;
|
||||
if (!data.owner) {
|
||||
return app.alertError('[[error:not-allowed]]');
|
||||
}
|
||||
|
||||
if (data.users.length < 2) {
|
||||
return app.alertError('[[error:cant-remove-last-user]]');
|
||||
}
|
||||
});
|
||||
|
||||
tagEl.on('itemRemoved', function(event) {
|
||||
socket.emit('modules.chats.removeUserFromRoom', {roomId: data.roomId, username: event.item});
|
||||
socket.emit('modules.chats.removeUserFromRoom', {roomId: data.roomId, username: event.item}, function(err) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var input = $('.users-tag-container').find('.bootstrap-tagsinput input');
|
||||
|
||||
@@ -58,7 +58,7 @@ chatsController.get = function(req, res, callback) {
|
||||
|
||||
room.isOwner = parseInt(room.owner, 10) === parseInt(req.uid, 10);
|
||||
room.users = data.users.filter(function(user) {
|
||||
return user && parseInt(user.uid, 10) !== req.uid;
|
||||
return user && parseInt(user.uid, 10) && parseInt(user.uid, 10) !== req.uid;
|
||||
});
|
||||
|
||||
room.usernames = data.users.map(function(user) {
|
||||
|
||||
@@ -56,6 +56,10 @@ module.exports = function(Messaging) {
|
||||
db.exists('chat:room:' + roomId + ':uids', callback);
|
||||
};
|
||||
|
||||
Messaging.getUserCountInRoom = function(roomId, callback) {
|
||||
db.sortedSetCard('chat:room:' + roomId + ':uids', callback);
|
||||
};
|
||||
|
||||
Messaging.isRoomOwner = function(uid, roomId, callback) {
|
||||
db.getObjectField('chat:room:' + roomId, 'owner', function(err, owner) {
|
||||
if (err) {
|
||||
@@ -87,12 +91,19 @@ module.exports = function(Messaging) {
|
||||
Messaging.removeUsersFromRoom = function(uid, uids, roomId, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
Messaging.isRoomOwner(uid, roomId, next);
|
||||
async.parallel({
|
||||
isOwner: async.apply(Messaging.isRoomOwner, uid, roomId),
|
||||
userCount: async.apply(Messaging.getUserCountInRoom, roomId)
|
||||
}, next);
|
||||
},
|
||||
function (isOwner, next) {
|
||||
if (!isOwner) {
|
||||
function (results, next) {
|
||||
if (!results.isOwner) {
|
||||
return next(new Error('[[error:cant-add-users-to-chat-room]]'));
|
||||
}
|
||||
if (results.userCount === 2) {
|
||||
return next(new Error('[[error:cant-remove-last-user]]'));
|
||||
}
|
||||
|
||||
db.sortedSetRemove('chat:room:' + roomId + ':uids', uids, next);
|
||||
},
|
||||
function (next) {
|
||||
|
||||
Reference in New Issue
Block a user