Retorna status da maquina mesmo sem sessao de chat ativa
A query getTicketSession agora sempre retorna machineOnline, permitindo que o botao de chat seja habilitado corretamente quando a maquina esta online mas nao ha sessao ativa. 🤖 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
0bd9e993d5
commit
60e98dd47c
2 changed files with 20 additions and 11 deletions
|
|
@ -500,7 +500,7 @@ export const checkMachineUpdates = query({
|
|||
// QUERIES (Agente)
|
||||
// ============================================
|
||||
|
||||
// Listar sessao ativa de um ticket
|
||||
// Listar sessao ativa de um ticket e status da maquina
|
||||
export const getTicketSession = query({
|
||||
args: {
|
||||
ticketId: v.id("tickets"),
|
||||
|
|
@ -517,20 +517,29 @@ export const getTicketSession = query({
|
|||
return null
|
||||
}
|
||||
|
||||
// Verificar se maquina esta online (sempre, mesmo sem sessao)
|
||||
const machine = ticket.machineId ? await ctx.db.get(ticket.machineId) : null
|
||||
const fiveMinutesAgo = Date.now() - 5 * 60 * 1000
|
||||
const machineOnline = machine?.lastHeartbeatAt && machine.lastHeartbeatAt > fiveMinutesAgo
|
||||
|
||||
const session = await ctx.db
|
||||
.query("liveChatSessions")
|
||||
.withIndex("by_ticket", (q) => q.eq("ticketId", ticketId))
|
||||
.filter((q) => q.eq(q.field("status"), "ACTIVE"))
|
||||
.first()
|
||||
|
||||
// Sempre retorna status da maquina, mesmo sem sessao ativa
|
||||
if (!session) {
|
||||
return null
|
||||
return {
|
||||
sessionId: null,
|
||||
agentId: null,
|
||||
agentName: null,
|
||||
startedAt: null,
|
||||
lastActivityAt: null,
|
||||
unreadByAgent: 0,
|
||||
machineOnline: Boolean(machineOnline),
|
||||
}
|
||||
}
|
||||
|
||||
// Verificar se maquina esta online
|
||||
const machine = ticket.machineId ? await ctx.db.get(ticket.machineId) : null
|
||||
const fiveMinutesAgo = Date.now() - 5 * 60 * 1000
|
||||
const machineOnline = machine?.lastHeartbeatAt && machine.lastHeartbeatAt > fiveMinutesAgo
|
||||
|
||||
return {
|
||||
sessionId: session._id,
|
||||
|
|
|
|||
|
|
@ -322,11 +322,11 @@ export function TicketSummaryHeader({ ticket }: TicketHeaderProps) {
|
|||
? { ticketId: ticket.id as Id<"tickets">, viewerId: convexUserId as Id<"users"> }
|
||||
: "skip"
|
||||
) as {
|
||||
sessionId: Id<"liveChatSessions">
|
||||
agentId: Id<"users">
|
||||
sessionId: Id<"liveChatSessions"> | null
|
||||
agentId: Id<"users"> | null
|
||||
agentName: string | null
|
||||
startedAt: number
|
||||
lastActivityAt: number
|
||||
startedAt: number | null
|
||||
lastActivityAt: number | null
|
||||
unreadByAgent: number
|
||||
machineOnline: boolean
|
||||
} | null | undefined
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue