Node.js based forum software built for the modern web
fix: closes #15011, update messageCount on message purge
Barış Soner Uşaklı4e4051fa91f8
diff --git a/src/controllers/accounts/chats.js b/src/controllers/accounts/chats.jsindex bd0dc62a4f..c376f80aa9 100644--- a/src/controllers/accounts/chats.js+++ b/src/controllers/accounts/chats.js@@ -117,5 +117,5 @@ chatsController.redirectToMessage = async function (req, res, next) {return next();}- helpers.redirect(res, `/user/${userslug}/chats/${roomId}${index ? `/${index + 1}` : ''}`, true);+ helpers.redirect(res, `/user/${userslug}/chats/${roomId}/${index + 1}`, true);};diff --git a/src/messaging/delete.js b/src/messaging/delete.jsindex 9f5f9ca678..06d0f66d33 100644--- a/src/messaging/delete.js+++ b/src/messaging/delete.js@@ -17,6 +17,7 @@ module.exports = function (Messaging) {}await db.delete(`message:${mid}`);await db.sortedSetRemove(`chat:room:${msgData.roomId}:mids`, mid);+ await db.decrObjectField(`chat:room:${msgData.roomId}`, 'messageCount');plugins.hooks.fire('action:messaging.delete', { message: msgData });};diff --git a/test/messaging.js b/test/messaging.jsindex e7e1d2aeb1..e140909ed1 100644--- a/test/messaging.js+++ b/test/messaging.js@@ -942,6 +942,37 @@ describe('Messaging Library', () => {assert.strictEqual(body.status.message, 'This chat message has already been restored.');});+ it('should reduce messageCount property of chat room when a message is purged', async () => {+ const { body: roomBody } = await callv3API('post', '/chats', {+ uids: [mocks.users.baz.uid],+ }, 'foo');+ const purgeRoomId = roomBody.response.roomId;++ // Send 3 messages+ const { body: msg1 } = await callv3API('post', `/chats/${purgeRoomId}`, {+ roomId: purgeRoomId, message: 'message one',+ }, 'foo');+ const { body: msg2 } = await callv3API('post', `/chats/${purgeRoomId}`, {+ roomId: purgeRoomId, message: 'message two',+ }, 'foo');+ const { body: msg3 } = await callv3API('post', `/chats/${purgeRoomId}`, {+ roomId: purgeRoomId, message: 'message three',+ }, 'foo');++ const mids = [msg1.response.messageId, msg2.response.messageId, msg3.response.messageId];++ // Verify messageCount is 3+ let msgCount = await db.getObjectField(`chat:room:${purgeRoomId}`, 'messageCount');+ assert.strictEqual(parseInt(msgCount, 10), 3);++ // Purge one message+ await Messaging.purgeMessage(mids[1]);++ // Verify messageCount is now 2+ msgCount = await db.getObjectField(`chat:room:${purgeRoomId}`, 'messageCount');+ assert.strictEqual(parseInt(msgCount, 10), 2);+ });+describe('disabled via ACP', () => {before(async () => {meta.config.disableChatMessageEditing = true;