From 5df68c3917f1e825baadda5ed83f552cdfb7445b Mon Sep 17 00:00:00 2001 From: esdrasrenan Date: Fri, 12 Dec 2025 23:41:52 -0300 Subject: [PATCH] desktop: fechar chat ao encerrar sessao --- apps/desktop/src/chat/ChatWidget.tsx | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/apps/desktop/src/chat/ChatWidget.tsx b/apps/desktop/src/chat/ChatWidget.tsx index acacacd..334da67 100644 --- a/apps/desktop/src/chat/ChatWidget.tsx +++ b/apps/desktop/src/chat/ChatWidget.tsx @@ -242,7 +242,7 @@ export function ChatWidget({ ticketId, ticketRef }: ChatWidgetProps) { const messagesEndRef = useRef(null) const messagesContainerRef = useRef(null) const messageElementsRef = useRef>(new Map()) - const hadSessionRef = useRef(false) + const prevHasSessionRef = useRef(false) const [isAtBottom, setIsAtBottom] = useState(true) const isAtBottomRef = useRef(true) @@ -279,16 +279,15 @@ export function ChatWidget({ ticketId, ticketRef }: ChatWidgetProps) { return true }, [updateIsAtBottom]) - // Auto-minimizar quando a sessão termina (hasSession muda de true para false) + // Quando a sessão termina (hasSession muda de true -> false), fechar a janela para não ficar "Offline" preso useEffect(() => { - if (hadSessionRef.current && !hasSession) { - setIsMinimized(true) - // Redimensionar janela para modo minimizado - invoke("set_chat_minimized", { ticketId, minimized: true }).catch(err => { - console.error("Erro ao minimizar janela automaticamente:", err) + const prevHasSession = prevHasSessionRef.current + if (prevHasSession && !hasSession) { + invoke("close_chat_window", { ticketId }).catch((err) => { + console.error("Erro ao fechar janela ao encerrar sessão:", err) }) } - hadSessionRef.current = hasSession + prevHasSessionRef.current = hasSession }, [hasSession, ticketId]) // Ref para acessar isMinimized dentro do callback sem causar resubscription @@ -347,7 +346,6 @@ export function ChatWidget({ ticketId, ticketRef }: ChatWidgetProps) { }) setHasSession(result.hasSession) - hadSessionRef.current = hadSessionRef.current || result.hasSession setUnreadCount(result.unreadCount ?? 0) setMessages(result.messages.slice(-MAX_MESSAGES_IN_MEMORY)) @@ -718,6 +716,13 @@ export function ChatWidget({ ticketId, ticketRef }: ChatWidgetProps) { Offline + )