Fix unread badge - increment unreadByMachine when agent sends message
The unreadByMachine counter was never being incremented when agents sent chat messages, causing the badge to always show 0. Now when an agent (ADMIN/MANAGER/AGENT) posts a message to a ticket with an active chat session, the counter is incremented properly. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
88a3b37f2f
commit
4f81f62429
1 changed files with 17 additions and 0 deletions
|
|
@ -3257,6 +3257,23 @@ export const postChatMessage = mutation({
|
|||
|
||||
await ctx.db.patch(ticketId, { updatedAt: now })
|
||||
|
||||
// Se o autor for um agente (ADMIN, MANAGER, AGENT), incrementar unreadByMachine na sessao de chat ativa
|
||||
const actorRole = participant.role?.toUpperCase() ?? ""
|
||||
if (["ADMIN", "MANAGER", "AGENT"].includes(actorRole)) {
|
||||
const activeSession = await ctx.db
|
||||
.query("liveChatSessions")
|
||||
.withIndex("by_ticket", (q) => q.eq("ticketId", ticketId))
|
||||
.filter((q) => q.eq(q.field("status"), "ACTIVE"))
|
||||
.first()
|
||||
|
||||
if (activeSession) {
|
||||
await ctx.db.patch(activeSession._id, {
|
||||
unreadByMachine: (activeSession.unreadByMachine ?? 0) + 1,
|
||||
lastActivityAt: now,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return { ok: true, messageId }
|
||||
},
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue