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 const { projectId, threadId, messageId } = req.params
logger.log({ projectId, threadId, messageId, content }, 'editing message') logger.log({ projectId, threadId, messageId, content }, 'editing message')
const room = await ThreadManager.findOrCreateThread(projectId, threadId) const room = await ThreadManager.findOrCreateThread(projectId, threadId)
await MessageManager.updateMessage( const found = await MessageManager.updateMessage(
room._id, room._id,
messageId, messageId,
userId, userId,
content, content,
Date.now() Date.now()
) )
if (!found) {
return res.sendStatus(404)
}
res.sendStatus(204) res.sendStatus(204)
} }

View file

@ -53,12 +53,13 @@ async function updateMessage(roomId, messageId, userId, content, timestamp) {
if (userId) { if (userId) {
query.user_id = ObjectId(userId) query.user_id = ObjectId(userId)
} }
await db.messages.updateOne(query, { const res = await db.messages.updateOne(query, {
$set: { $set: {
content, content,
edited_at: timestamp, edited_at: timestamp,
}, },
}) })
return res.modifiedCount === 1
} }
async function deleteMessage(roomId, messageId) { async function deleteMessage(roomId, messageId) {

View file

@ -83,7 +83,7 @@ describe('Editing a message', async function () {
ObjectId(), ObjectId(),
newContent 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 () { it('should then list the old message in the threads', async function () {