diff --git a/apps/desktop/src-tauri/src/chat.rs b/apps/desktop/src-tauri/src/chat.rs index ce5518a..12f8773 100644 --- a/apps/desktop/src-tauri/src/chat.rs +++ b/apps/desktop/src-tauri/src/chat.rs @@ -802,7 +802,7 @@ async fn process_chat_update( }), ); - // Notificar novas mensagens (sem abrir janela automaticamente - so na nova sessao) + // Notificar novas mensagens - mostrar chat minimizado com badge if new_messages && total_unread > 0 { let new_count = total_unread - prev_unread; @@ -817,7 +817,22 @@ async fn process_chat_update( }), ); - // Notificacao nativa (sem abrir janela - usuario pode clicar para abrir) + // Mostrar janela de chat minimizada (menos intrusivo que abrir completo) + if let Some(session) = current_sessions.first() { + // Abrir janela se nao existir + let label = format!("chat-{}", session.ticket_id); + if app.get_webview_window(&label).is_none() { + let _ = open_chat_window(app, &session.ticket_id); + // Minimizar imediatamente apos abrir + let _ = set_chat_minimized(app, &session.ticket_id, true); + } + // Se ja existe, apenas garantir que esta visivel (pode estar escondida) + else if let Some(window) = app.get_webview_window(&label) { + let _ = window.show(); + } + } + + // Notificacao nativa let notification_title = "Nova mensagem de suporte"; let notification_body = if new_count == 1 { "Voce recebeu 1 nova mensagem no chat".to_string() @@ -875,10 +890,11 @@ fn open_chat_window_internal(app: &tauri::AppHandle, ticket_id: &str) -> Result< ) .title("Chat de Suporte") .inner_size(380.0, 520.0) - .min_inner_size(168.0, 36.0) // Tamanho minimo para modo minimizado + .min_inner_size(200.0, 44.0) // Tamanho minimo para modo minimizado com badge .position(x, y) .decorations(false) // Sem decoracoes nativas - usa header customizado .transparent(true) // Permite fundo transparente + .shadow(false) // Desabilitar sombra para transparencia funcionar corretamente .always_on_top(true) .skip_taskbar(true) .focused(true) @@ -915,9 +931,9 @@ pub fn set_chat_minimized(app: &tauri::AppHandle, ticket_id: &str, minimized: bo let label = format!("chat-{}", ticket_id); let window = app.get_webview_window(&label).ok_or("Janela nao encontrada")?; - // Tamanhos - chip minimizado precisa ser exato para transparencia funcionar + // Tamanhos - chip minimizado com margem extra para badge e modo offline let (width, height) = if minimized { - (168.0, 36.0) // Tamanho exato do chip rounded-full + (200.0, 44.0) // Tamanho com folga para badge e texto "Offline" } else { (380.0, 520.0) // Tamanho expandido }; diff --git a/apps/desktop/src/chat/ChatWidget.tsx b/apps/desktop/src/chat/ChatWidget.tsx index bc8fcf3..c2591aa 100644 --- a/apps/desktop/src/chat/ChatWidget.tsx +++ b/apps/desktop/src/chat/ChatWidget.tsx @@ -49,6 +49,7 @@ export function ChatWidget({ ticketId }: ChatWidgetProps) { const [hasSession, setHasSession] = useState(false) const [pendingAttachments, setPendingAttachments] = useState([]) const [isMinimized, setIsMinimized] = useState(false) + const [unreadCount, setUnreadCount] = useState(0) const messagesEndRef = useRef(null) const lastFetchRef = useRef(0) @@ -186,7 +187,7 @@ export function ChatWidget({ ticketId }: ChatWidgetProps) { init() // Listener para eventos de nova mensagem do Tauri - const unlistenPromise = listen<{ ticketId: string; message: ChatMessage }>( + const unlistenNewMessage = listen<{ ticketId: string; message: ChatMessage }>( "raven://chat/new-message", (event) => { if (event.payload.ticketId === ticketId) { @@ -202,12 +203,25 @@ export function ChatWidget({ ticketId }: ChatWidgetProps) { } ) + // Listener para atualização de mensagens não lidas + const unlistenUnread = listen<{ totalUnread: number; sessions: Array<{ ticketId: string; unreadCount: number }> }>( + "raven://chat/unread-update", + (event) => { + // Encontrar o unread count para este ticket + const session = event.payload.sessions?.find(s => s.ticketId === ticketId) + if (session) { + setUnreadCount(session.unreadCount ?? 0) + } + } + ) + return () => { mounted = false if (pollIntervalRef.current) { clearInterval(pollIntervalRef.current) } - unlistenPromise.then(unlisten => unlisten()) + unlistenNewMessage.then(unlisten => unlisten()) + unlistenUnread.then(unlisten => unlisten()) } }, [ticketId, loadConfig, fetchMessages, fetchSessionInfo]) @@ -378,7 +392,7 @@ export function ChatWidget({ ticketId }: ChatWidgetProps) {
)