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
This commit is contained in:
Jakob Ackermann 2022-03-31 10:23:22 +01:00 committed by Copybot
parent 64ffd66fa4
commit c96fbc526e
3 changed files with 7 additions and 3 deletions

View file

@ -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)
}

View file

@ -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) {

View file

@ -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 () {