Skip to content

Node.js based forum software built for the modern web

fix: re-allow kicking of the other party in a 1-to-1 chat

Julian Lam6294beea0b5e
diff --git a/public/language/en-GB/error.json b/public/language/en-GB/error.json
index bb5a5e5fe5..eccd5d43d1 100644
--- a/public/language/en-GB/error.json
+++ b/public/language/en-GB/error.json
@@ -171,7 +171,6 @@
"invalid-chat-message": "Invalid chat message",
"chat-message-too-long": "Chat messages can not be longer than %1 characters.",
"cant-edit-chat-message": "You are not allowed to edit this message",
- "cant-remove-last-user": "You can't remove the last user",
"cant-delete-chat-message": "You are not allowed to delete this message",
"chat-edit-duration-expired": "You are only allowed to edit chat messages for %1 second(s) after posting",
"chat-delete-duration-expired": "You are only allowed to delete chat messages for %1 second(s) after posting",
diff --git a/src/messaging/rooms.js b/src/messaging/rooms.js
index d268bc511e..948fd88027 100644
--- a/src/messaging/rooms.js
+++ b/src/messaging/rooms.js
@@ -109,9 +109,6 @@ module.exports = function (Messaging) {
if (!payload.isOwner) {
throw new Error('[[error:cant-remove-users-from-chat-room]]');
}
- if (payload.userCount === 2) {
- throw new Error('[[error:cant-remove-last-user]]');
- }
await Messaging.leaveRoom(payload.uids, payload.roomId);
};
diff --git a/test/messaging.js b/test/messaging.js
index cbafacb5a9..6158a8a2e2 100644
--- a/test/messaging.js
+++ b/test/messaging.js
@@ -298,44 +298,33 @@ describe('Messaging Library', () => {
assert.equal(data.owner, receiver);
});
- it('should fail to remove user from room', (done) => {
- socketModules.chats.removeUserFromRoom({ uid: mocks.users.foo.uid }, null, (err) => {
- assert.equal(err.message, '[[error:invalid-data]]');
- socketModules.chats.removeUserFromRoom({ uid: mocks.users.foo.uid }, {}, (err) => {
- assert.equal(err.message, '[[error:invalid-data]]');
- done();
- });
- });
+ it('should fail to remove user from room', async () => {
+ let { statusCode, body } = await callv3API('delete', `/chats/${roomId}/users`, {}, 'foo');
+ assert.strictEqual(statusCode, 400);
+ assert.strictEqual(body.status.message, await translator.translate('[[error:required-parameters-missing, uids]]'));
+
+ ({ statusCode, body } = await callv3API('delete', `/chats/${roomId}/users`, { uids: [null] }, 'foo'));
+ assert.strictEqual(statusCode, 400);
+ assert.strictEqual(body.status.message, await translator.translate('[[error:no-user]]'));
});
- it('should fail to remove user from room if user does not exist', (done) => {
- socketModules.chats.removeUserFromRoom({ uid: mocks.users.foo.uid }, { roomId: roomId, uid: 99 }, (err) => {
- assert.equal('[[error:no-user]]', err.message);
- done();
- });
+ it('should fail to remove user from room if user does not exist', async () => {
+ const { statusCode, body } = await callv3API('delete', `/chats/${roomId}/users`, { uids: [99] }, 'foo');
+ assert.strictEqual(statusCode, 400);
+ assert.strictEqual(body.status.message, await translator.translate('[[error:no-user]]'));
});
it('should remove user from room', async () => {
- const { body } = await callv3API('post', `/chats`, {
+ const { statusCode, body } = await callv3API('post', `/chats`, {
uids: [mocks.users.herp.uid],
}, 'foo');
const { roomId } = body.response;
+ assert.strictEqual(statusCode, 200);
let isInRoom = await Messaging.isUserInRoom(mocks.users.herp.uid, roomId);
assert(isInRoom);
- try {
- await util.promisify(
- socketModules.chats.removeUserFromRoom
- )({ uid: mocks.users.foo.uid }, { roomId: roomId, uid: mocks.users.herp.uid });
- } catch (err) {
- assert.equal(err.message, '[[error:cant-remove-last-user]]');
- }
-
- await callv3API('post', `/chats/${roomId}/users`, { uids: [mocks.users.baz.uid] }, 'foo');
- await util.promisify(
- socketModules.chats.removeUserFromRoom
- )({ uid: mocks.users.foo.uid }, { roomId: roomId, uid: mocks.users.herp.uid });
+ await callv3API('delete', `/chats/${roomId}/users`, { uids: [mocks.users.herp.uid] }, 'foo');
isInRoom = await Messaging.isUserInRoom(mocks.users.herp.uid, roomId);
assert(!isInRoom);
});