fix: #9503, dont error in markUnread if room doesnt exist

this prevents deleting the user if they are the only person in the chat room
v1.18.x
Barış Soner Uşaklı 4 years ago
parent 9e07efc126
commit 308252f566

@ -31,7 +31,7 @@ module.exports = function (Messaging) {
Messaging.markUnread = async (uids, roomId) => {
const exists = await Messaging.roomExists(roomId);
if (!exists) {
throw new Error('[[error:chat-room-does-not-exist]]');
return;
}
const keys = uids.map(uid => `uid:${uid}:chat:rooms:unread`);
return await db.sortedSetsAdd(keys, Date.now(), roomId);

@ -541,6 +541,17 @@ describe('User', () => {
await Posts.upvote(result.postData.pid, 1);
assert(!await db.isSortedSetMember('users:reputation', uid));
});
it('should delete user even if they started a chat', async () => {
const socketModules = require('../src/socket.io/modules');
const uid1 = await User.create({ username: 'chatuserdelete1' });
const uid2 = await User.create({ username: 'chatuserdelete2' });
const roomId = await socketModules.chats.newRoom({ uid: uid1 }, { touid: uid2 });
await socketModules.chats.send({ uid: uid1 }, { roomId: roomId, message: 'hello' });
await socketModules.chats.leave({ uid: uid2 }, roomId);
await User.delete(1, uid1);
assert.strictEqual(await User.exists(uid1), false);
});
});
describe('passwordReset', () => {

Loading…
Cancel
Save