mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
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
This commit is contained in:
@@ -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);
|
||||
|
||||
11
test/user.js
11
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', () => {
|
||||
|
||||
Reference in New Issue
Block a user