From c96fbc526eaad26067a6da4dde0413e333a6374d Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Thu, 31 Mar 2022 10:23:22 +0100 Subject: [PATCH] Merge pull request #7317 from overleaf/jpa-return-chat-edit-status [misc] return non-success status from editing chat messages back to web GitOrigin-RevId: a3d5f59ac1d92662ac9e9c94b1516441d66e831a --- .../chat/app/js/Features/Messages/MessageHttpController.js | 5 ++++- services/chat/app/js/Features/Messages/MessageManager.js | 3 ++- services/chat/test/acceptance/js/EditingAMessageTests.js | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/services/chat/app/js/Features/Messages/MessageHttpController.js b/services/chat/app/js/Features/Messages/MessageHttpController.js index c84c30c8ba..9c9815ed5e 100644 --- a/services/chat/app/js/Features/Messages/MessageHttpController.js +++ b/services/chat/app/js/Features/Messages/MessageHttpController.js @@ -58,13 +58,16 @@ async function editMessage(req, res) { const { projectId, threadId, messageId } = req.params logger.log({ projectId, threadId, messageId, content }, 'editing message') const room = await ThreadManager.findOrCreateThread(projectId, threadId) - await MessageManager.updateMessage( + const found = await MessageManager.updateMessage( room._id, messageId, userId, content, Date.now() ) + if (!found) { + return res.sendStatus(404) + } res.sendStatus(204) } diff --git a/services/chat/app/js/Features/Messages/MessageManager.js b/services/chat/app/js/Features/Messages/MessageManager.js index 76eed9a974..30a5627e84 100644 --- a/services/chat/app/js/Features/Messages/MessageManager.js +++ b/services/chat/app/js/Features/Messages/MessageManager.js @@ -53,12 +53,13 @@ async function updateMessage(roomId, messageId, userId, content, timestamp) { if (userId) { query.user_id = ObjectId(userId) } - await db.messages.updateOne(query, { + const res = await db.messages.updateOne(query, { $set: { content, edited_at: timestamp, }, }) + return res.modifiedCount === 1 } async function deleteMessage(roomId, messageId) { diff --git a/services/chat/test/acceptance/js/EditingAMessageTests.js b/services/chat/test/acceptance/js/EditingAMessageTests.js index 668fbe7969..f39a919c51 100644 --- a/services/chat/test/acceptance/js/EditingAMessageTests.js +++ b/services/chat/test/acceptance/js/EditingAMessageTests.js @@ -83,7 +83,7 @@ describe('Editing a message', async function () { ObjectId(), newContent ) - expect(response.statusCode).to.equal(204) + expect(response.statusCode).to.equal(404) }) it('should then list the old message in the threads', async function () {