From 308252f566db1212f9d03ef89621b12d4dd7e0e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Fri, 23 Apr 2021 14:46:54 -0400 Subject: [PATCH] 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 --- src/messaging/unread.js | 2 +- test/user.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/messaging/unread.js b/src/messaging/unread.js index 4a1ab60cfb..169374045f 100644 --- a/src/messaging/unread.js +++ b/src/messaging/unread.js @@ -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); diff --git a/test/user.js b/test/user.js index 3306ebee0b..e3482d5139 100644 --- a/test/user.js +++ b/test/user.js @@ -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', () => {