Skip to content

Node.js based forum software built for the modern web

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

Barış Soner Uşaklı308252f566db
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', () => {