fix(chat desktop): abrir/minimizar chat ao detectar unread via Convex
This commit is contained in:
parent
daba03d25d
commit
c7711dfda5
1 changed files with 33 additions and 0 deletions
|
|
@ -11,6 +11,7 @@ import { cn } from "./lib/utils"
|
|||
import { ChatApp } from "./chat"
|
||||
import { DeactivationScreen } from "./components/DeactivationScreen"
|
||||
import type { SessionStartedEvent, UnreadUpdateEvent, NewMessageEvent, SessionEndedEvent } from "./chat/types"
|
||||
import { subscribeMachineUpdates } from "./chat/convexMachineClient"
|
||||
|
||||
type MachineOs = {
|
||||
name: string
|
||||
|
|
@ -1083,6 +1084,38 @@ const resolvedAppUrl = useMemo(() => {
|
|||
}
|
||||
}, [token])
|
||||
|
||||
// Assinatura direta no Convex para abrir/minimizar chat quando houver novas mensagens
|
||||
useEffect(() => {
|
||||
if (!token) return
|
||||
|
||||
let prevUnread = 0
|
||||
let unsub: (() => void) | null = null
|
||||
subscribeMachineUpdates(
|
||||
(payload) => {
|
||||
if (!payload) return
|
||||
const totalUnread = payload.totalUnread ?? 0
|
||||
const hasSessions = (payload.sessions ?? []).length > 0
|
||||
|
||||
// Abre/minimiza chat quando aparecem novas não lidas
|
||||
if (hasSessions && totalUnread > prevUnread) {
|
||||
const ticketId = payload.sessions[0].ticketId
|
||||
invoke("open_chat_window", { ticketId }).catch(console.error)
|
||||
// Minimiza para não ser intrusivo
|
||||
invoke("set_chat_minimized", { ticketId, minimized: true }).catch(console.error)
|
||||
}
|
||||
|
||||
prevUnread = totalUnread
|
||||
},
|
||||
(err) => console.error("chat updates (Convex) erro:", err)
|
||||
).then((u) => {
|
||||
unsub = u
|
||||
})
|
||||
|
||||
return () => {
|
||||
unsub?.()
|
||||
}
|
||||
}, [token])
|
||||
|
||||
async function register() {
|
||||
if (!profile) return
|
||||
const trimmedCode = provisioningCode.trim().toLowerCase()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue