diff --git a/apps/desktop/src/chat/ChatWidget.tsx b/apps/desktop/src/chat/ChatWidget.tsx index 8441c0d..aaa5c9a 100644 --- a/apps/desktop/src/chat/ChatWidget.tsx +++ b/apps/desktop/src/chat/ChatWidget.tsx @@ -127,6 +127,28 @@ export function ChatWidget({ ticketId, ticketRef }: ChatWidgetProps) { } }, [ticketId, isMinimized]) + // Sincroniza estado de minimizado com o tamanho da janela (Tauri pode alterar por fora) + useEffect(() => { + const handler = () => { + const h = window.innerHeight + // thresholds alinhados com set_chat_minimized (52px minimizado, 520px expandido) + setIsMinimized(h < 100) + } + window.addEventListener("resize", handler) + handler() + return () => window.removeEventListener("resize", handler) + }, []) + + // Quando expandir, marcar mensagens como lidas e limpar badge + useEffect(() => { + if (isMinimized) return + const unreadIds = messages.filter(m => !m.isFromMachine).map(m => m.id as string) + if (unreadIds.length > 0) { + markMachineMessagesRead(ticketId, unreadIds).catch(err => console.error("mark read falhou", err)) + } + setUnreadCount(0) + }, [isMinimized, messages, ticketId]) + // Selecionar arquivo para anexar const handleAttach = async () => { if (isUploading || isSending) return @@ -231,10 +253,8 @@ export function ChatWidget({ ticketId, ticketRef }: ChatWidgetProps) { const unreadIds = messages.filter(m => !m.isFromMachine).map(m => m.id as string) if (unreadIds.length > 0) { markMachineMessagesRead(ticketId, unreadIds).catch(err => console.error("mark read falhou", err)) - setUnreadCount(0) - } else { - setUnreadCount(0) } + setUnreadCount(0) } const handleClose = () => {