mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
kick support for chats, #6479
This commit is contained in:
@@ -32,6 +32,7 @@
|
|||||||
"chat.leave-prompt": "Are you sure you wish to leave this chat?",
|
"chat.leave-prompt": "Are you sure you wish to leave this chat?",
|
||||||
"chat.leave-help": "Leaving this chat will remove you from future correspondence in this chat. If you are re-added in the future, you will not see any chat history from prior to your re-joining.",
|
"chat.leave-help": "Leaving this chat will remove you from future correspondence in this chat. If you are re-added in the future, you will not see any chat history from prior to your re-joining.",
|
||||||
"chat.in-room": "In this room",
|
"chat.in-room": "In this room",
|
||||||
|
"chat.kick": "Kick",
|
||||||
|
|
||||||
"composer.compose": "Compose",
|
"composer.compose": "Compose",
|
||||||
"composer.show_preview": "Show Preview",
|
"composer.show_preview": "Show Preview",
|
||||||
|
|||||||
@@ -189,6 +189,7 @@ define('forum/chats', [
|
|||||||
modal.attr('component', 'chat/manage-modal');
|
modal.attr('component', 'chat/manage-modal');
|
||||||
|
|
||||||
Chats.refreshParticipantsList(roomId, modal);
|
Chats.refreshParticipantsList(roomId, modal);
|
||||||
|
Chats.addKickHandler(roomId, modal);
|
||||||
|
|
||||||
var searchInput = modal.find('input');
|
var searchInput = modal.find('input');
|
||||||
var errorEl = modal.find('.text-danger');
|
var errorEl = modal.find('.text-danger');
|
||||||
@@ -215,6 +216,23 @@ define('forum/chats', [
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Chats.addKickHandler = function (roomId, modal) {
|
||||||
|
modal.on('click', '[data-action="kick"]', function () {
|
||||||
|
var uid = parseInt(this.getAttribute('data-uid'), 10);
|
||||||
|
|
||||||
|
socket.emit('modules.chats.removeUserFromRoom', {
|
||||||
|
roomId: roomId,
|
||||||
|
uid: uid,
|
||||||
|
}, function (err) {
|
||||||
|
if (err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
Chats.refreshParticipantsList(roomId, modal);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
Chats.addLeaveHandler = function (roomId, buttonEl) {
|
Chats.addLeaveHandler = function (roomId, buttonEl) {
|
||||||
buttonEl.on('click', function () {
|
buttonEl.on('click', function () {
|
||||||
bootbox.confirm({
|
bootbox.confirm({
|
||||||
@@ -254,7 +272,7 @@ define('forum/chats', [
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Benchpress.parse('partials/modals/manage_room_users', {
|
app.parseAndTranslate('partials/modals/manage_room_users', {
|
||||||
users: users,
|
users: users,
|
||||||
}, function (html) {
|
}, function (html) {
|
||||||
listEl.html(html);
|
listEl.html(html);
|
||||||
|
|||||||
@@ -193,7 +193,21 @@ SocketModules.chats.getUsersInRoom = function (socket, data, callback) {
|
|||||||
return callback(new Error('[[error:invalid-data]]'));
|
return callback(new Error('[[error:invalid-data]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
Messaging.getUsersInRoom(data.roomId, 0, -1, callback);
|
async.parallel({
|
||||||
|
users: async.apply(Messaging.getUsersInRoom, data.roomId, 0, -1),
|
||||||
|
isOwner: async.apply(Messaging.isRoomOwner, socket.uid, data.roomId),
|
||||||
|
}, function (err, payload) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
payload.users = payload.users.map((user) => {
|
||||||
|
user.canKick = payload.isOwner;
|
||||||
|
return user;
|
||||||
|
});
|
||||||
|
|
||||||
|
callback(null, payload.users);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketModules.chats.addUserToRoom = function (socket, data, callback) {
|
SocketModules.chats.addUserToRoom = function (socket, data, callback) {
|
||||||
@@ -250,16 +264,17 @@ SocketModules.chats.removeUserFromRoom = function (socket, data, callback) {
|
|||||||
if (!data || !data.roomId) {
|
if (!data || !data.roomId) {
|
||||||
return callback(new Error('[[error:invalid-data]]'));
|
return callback(new Error('[[error:invalid-data]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
user.getUidByUsername(data.username, next);
|
user.exists(data.uid, next);
|
||||||
},
|
},
|
||||||
function (uid, next) {
|
function (exists, next) {
|
||||||
if (!uid) {
|
if (!exists) {
|
||||||
return next(new Error('[[error:no-user]]'));
|
return next(new Error('[[error:no-user]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
Messaging.removeUsersFromRoom(socket.uid, [uid], data.roomId, next);
|
Messaging.removeUsersFromRoom(socket.uid, [data.uid], data.roomId, next);
|
||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -234,8 +234,8 @@ describe('Messaging Library', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to remove user from room if user does not exist', function (done) {
|
it('should fail to remove user from room if user does not exist', function (done) {
|
||||||
socketModules.chats.removeUserFromRoom({ uid: fooUid }, { roomId: roomId, username: 'doesnotexist' }, function (err) {
|
socketModules.chats.removeUserFromRoom({ uid: fooUid }, { roomId: roomId, uid: 99 }, function (err) {
|
||||||
assert.equal(err.message, '[[error:no-user]]');
|
assert.equal('[[error:no-user]]', err.message);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -246,11 +246,11 @@ describe('Messaging Library', function () {
|
|||||||
Messaging.isUserInRoom(herpUid, roomId, function (err, isInRoom) {
|
Messaging.isUserInRoom(herpUid, roomId, function (err, isInRoom) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert(isInRoom);
|
assert(isInRoom);
|
||||||
socketModules.chats.removeUserFromRoom({ uid: fooUid }, { roomId: roomId, username: 'herp' }, function (err) {
|
socketModules.chats.removeUserFromRoom({ uid: fooUid }, { roomId: roomId, uid: herpUid }, function (err) {
|
||||||
assert.equal(err.message, '[[error:cant-remove-last-user]]');
|
assert.equal(err.message, '[[error:cant-remove-last-user]]');
|
||||||
socketModules.chats.addUserToRoom({ uid: fooUid }, { roomId: roomId, username: 'baz' }, function (err) {
|
socketModules.chats.addUserToRoom({ uid: fooUid }, { roomId: roomId, username: 'baz' }, function (err) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
socketModules.chats.removeUserFromRoom({ uid: fooUid }, { roomId: roomId, username: 'herp' }, function (err) {
|
socketModules.chats.removeUserFromRoom({ uid: fooUid }, { roomId: roomId, uid: herpUid }, function (err) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
Messaging.isUserInRoom(herpUid, roomId, function (err, isInRoom) {
|
Messaging.isUserInRoom(herpUid, roomId, function (err, isInRoom) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
|||||||
Reference in New Issue
Block a user