mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: re-allow kicking of the other party in a 1-to-1 chat
This commit is contained in:
@@ -171,7 +171,6 @@
|
|||||||
"invalid-chat-message": "Invalid chat message",
|
"invalid-chat-message": "Invalid chat message",
|
||||||
"chat-message-too-long": "Chat messages can not be longer than %1 characters.",
|
"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-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",
|
"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-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",
|
"chat-delete-duration-expired": "You are only allowed to delete chat messages for %1 second(s) after posting",
|
||||||
|
|||||||
@@ -109,9 +109,6 @@ module.exports = function (Messaging) {
|
|||||||
if (!payload.isOwner) {
|
if (!payload.isOwner) {
|
||||||
throw new Error('[[error:cant-remove-users-from-chat-room]]');
|
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);
|
await Messaging.leaveRoom(payload.uids, payload.roomId);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -298,44 +298,33 @@ describe('Messaging Library', () => {
|
|||||||
assert.equal(data.owner, receiver);
|
assert.equal(data.owner, receiver);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to remove user from room', (done) => {
|
it('should fail to remove user from room', async () => {
|
||||||
socketModules.chats.removeUserFromRoom({ uid: mocks.users.foo.uid }, null, (err) => {
|
let { statusCode, body } = await callv3API('delete', `/chats/${roomId}/users`, {}, 'foo');
|
||||||
assert.equal(err.message, '[[error:invalid-data]]');
|
assert.strictEqual(statusCode, 400);
|
||||||
socketModules.chats.removeUserFromRoom({ uid: mocks.users.foo.uid }, {}, (err) => {
|
assert.strictEqual(body.status.message, await translator.translate('[[error:required-parameters-missing, uids]]'));
|
||||||
assert.equal(err.message, '[[error:invalid-data]]');
|
|
||||||
done();
|
({ 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) => {
|
it('should fail to remove user from room if user does not exist', async () => {
|
||||||
socketModules.chats.removeUserFromRoom({ uid: mocks.users.foo.uid }, { roomId: roomId, uid: 99 }, (err) => {
|
const { statusCode, body } = await callv3API('delete', `/chats/${roomId}/users`, { uids: [99] }, 'foo');
|
||||||
assert.equal('[[error:no-user]]', err.message);
|
assert.strictEqual(statusCode, 400);
|
||||||
done();
|
assert.strictEqual(body.status.message, await translator.translate('[[error:no-user]]'));
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should remove user from room', async () => {
|
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],
|
uids: [mocks.users.herp.uid],
|
||||||
}, 'foo');
|
}, 'foo');
|
||||||
const { roomId } = body.response;
|
const { roomId } = body.response;
|
||||||
|
assert.strictEqual(statusCode, 200);
|
||||||
|
|
||||||
let isInRoom = await Messaging.isUserInRoom(mocks.users.herp.uid, roomId);
|
let isInRoom = await Messaging.isUserInRoom(mocks.users.herp.uid, roomId);
|
||||||
assert(isInRoom);
|
assert(isInRoom);
|
||||||
|
|
||||||
try {
|
await callv3API('delete', `/chats/${roomId}/users`, { uids: [mocks.users.herp.uid] }, 'foo');
|
||||||
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 });
|
|
||||||
isInRoom = await Messaging.isUserInRoom(mocks.users.herp.uid, roomId);
|
isInRoom = await Messaging.isUserInRoom(mocks.users.herp.uid, roomId);
|
||||||
assert(!isInRoom);
|
assert(!isInRoom);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user