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)
|
// QUERIES (Agente)
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
// Listar sessao ativa de um ticket
|
// Listar sessao ativa de um ticket e status da maquina
|
||||||
export const getTicketSession = query({
|
export const getTicketSession = query({
|
||||||
args: {
|
args: {
|
||||||
ticketId: v.id("tickets"),
|
ticketId: v.id("tickets"),
|
||||||
|
|
@ -517,20 +517,29 @@ export const getTicketSession = query({
|
||||||
return null
|
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
|
const session = await ctx.db
|
||||||
.query("liveChatSessions")
|
.query("liveChatSessions")
|
||||||
.withIndex("by_ticket", (q) => q.eq("ticketId", ticketId))
|
.withIndex("by_ticket", (q) => q.eq("ticketId", ticketId))
|
||||||
.filter((q) => q.eq(q.field("status"), "ACTIVE"))
|
.filter((q) => q.eq(q.field("status"), "ACTIVE"))
|
||||||
.first()
|
.first()
|
||||||
|
|
||||||
|
// Sempre retorna status da maquina, mesmo sem sessao ativa
|
||||||
if (!session) {
|
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 {
|
return {
|
||||||
sessionId: session._id,
|
sessionId: session._id,
|
||||||
|
|
|
||||||
|
|
@ -322,11 +322,11 @@ export function TicketSummaryHeader({ ticket }: TicketHeaderProps) {
|
||||||
? { ticketId: ticket.id as Id<"tickets">, viewerId: convexUserId as Id<"users"> }
|
? { ticketId: ticket.id as Id<"tickets">, viewerId: convexUserId as Id<"users"> }
|
||||||
: "skip"
|
: "skip"
|
||||||
) as {
|
) as {
|
||||||
sessionId: Id<"liveChatSessions">
|
sessionId: Id<"liveChatSessions"> | null
|
||||||
agentId: Id<"users">
|
agentId: Id<"users"> | null
|
||||||
agentName: string | null
|
agentName: string | null
|
||||||
startedAt: number
|
startedAt: number | null
|
||||||
lastActivityAt: number
|
lastActivityAt: number | null
|
||||||
unreadByAgent: number
|
unreadByAgent: number
|
||||||
machineOnline: boolean
|
machineOnline: boolean
|
||||||
} | null | undefined
|
} | null | undefined
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue