Update communications.js

This commit is contained in:
Troplo 2022-07-31 20:16:44 +10:00
parent a4e71cb412
commit c6b18cb768

View file

@ -679,6 +679,7 @@ router.put("/:id/read", auth, async (req, res, next) => {
] ]
}) })
if (chat) { if (chat) {
if (req.user.storedStatus !== "invisible") {
await chat.update({ await chat.update({
lastRead: chat.chat.lastMessages[0]?.id || null lastRead: chat.chat.lastMessages[0]?.id || null
}) })
@ -701,6 +702,13 @@ router.put("/:id/read", auth, async (req, res, next) => {
previousMessageId: chat.lastRead previousMessageId: chat.lastRead
}) })
} }
} else {
io.to(req.user.id).emit("readChat", {
id: chat.id,
lastRead: chat.chat.lastMessages[0]?.id || null
})
res.sendStatus(204)
}
} else { } else {
throw Errors.invalidParameter("chat association id") throw Errors.invalidParameter("chat association id")
} }