Add debug logs for chat and red border to end chat button
- Add detailed debug logs in Rust (chat.rs) to trace polling flow - Add console.log in frontend (main.tsx) to trace event reception - Add red border to "Encerrar" button in chat panels for better visibility 🤖 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
4f81f62429
commit
b10548157e
4 changed files with 45 additions and 4 deletions
|
|
@ -322,9 +322,30 @@ impl ChatRuntime {
|
||||||
Ok(result) => {
|
Ok(result) => {
|
||||||
last_checked_at = Some(chrono::Utc::now().timestamp_millis());
|
last_checked_at = Some(chrono::Utc::now().timestamp_millis());
|
||||||
|
|
||||||
|
// DEBUG: Log do resultado do polling
|
||||||
|
crate::log_info!(
|
||||||
|
"[CHAT DEBUG] poll_chat_updates: has_active={}, total_unread={}, sessions_count={}",
|
||||||
|
result.has_active_sessions,
|
||||||
|
result.total_unread,
|
||||||
|
result.sessions.len()
|
||||||
|
);
|
||||||
|
|
||||||
// Buscar sessoes completas para ter dados corretos
|
// Buscar sessoes completas para ter dados corretos
|
||||||
let current_sessions = if result.has_active_sessions {
|
let current_sessions = if result.has_active_sessions {
|
||||||
fetch_sessions(&base_clone, &token_clone).await.unwrap_or_default()
|
let sessions = fetch_sessions(&base_clone, &token_clone).await.unwrap_or_default();
|
||||||
|
crate::log_info!(
|
||||||
|
"[CHAT DEBUG] fetch_sessions: {} sessoes encontradas",
|
||||||
|
sessions.len()
|
||||||
|
);
|
||||||
|
for s in &sessions {
|
||||||
|
crate::log_info!(
|
||||||
|
"[CHAT DEBUG] Sessao: id={}, ticket={}, unread={}",
|
||||||
|
s.session_id,
|
||||||
|
s.ticket_id,
|
||||||
|
s.unread_count
|
||||||
|
);
|
||||||
|
}
|
||||||
|
sessions
|
||||||
} else {
|
} else {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
};
|
};
|
||||||
|
|
@ -400,7 +421,20 @@ impl ChatRuntime {
|
||||||
let new_messages = result.total_unread > prev_unread;
|
let new_messages = result.total_unread > prev_unread;
|
||||||
*last_unread_count.lock() = result.total_unread;
|
*last_unread_count.lock() = result.total_unread;
|
||||||
|
|
||||||
|
// DEBUG: Log de unread count
|
||||||
|
crate::log_info!(
|
||||||
|
"[CHAT DEBUG] Unread check: prev={}, current={}, new_messages={}",
|
||||||
|
prev_unread,
|
||||||
|
result.total_unread,
|
||||||
|
new_messages
|
||||||
|
);
|
||||||
|
|
||||||
// Sempre emitir unread-update com sessoes completas
|
// Sempre emitir unread-update com sessoes completas
|
||||||
|
crate::log_info!(
|
||||||
|
"[CHAT DEBUG] Emitindo unread-update: totalUnread={}, sessions={}",
|
||||||
|
result.total_unread,
|
||||||
|
current_sessions.len()
|
||||||
|
);
|
||||||
let _ = app.emit(
|
let _ = app.emit(
|
||||||
"raven://chat/unread-update",
|
"raven://chat/unread-update",
|
||||||
serde_json::json!({
|
serde_json::json!({
|
||||||
|
|
@ -411,6 +445,7 @@ impl ChatRuntime {
|
||||||
|
|
||||||
// Notificar novas mensagens (quando aumentou)
|
// Notificar novas mensagens (quando aumentou)
|
||||||
if new_messages && result.total_unread > 0 {
|
if new_messages && result.total_unread > 0 {
|
||||||
|
crate::log_info!("[CHAT DEBUG] NOVA MENSAGEM DETECTADA! Emitindo evento new-message");
|
||||||
let new_count = result.total_unread - prev_unread;
|
let new_count = result.total_unread - prev_unread;
|
||||||
|
|
||||||
crate::log_info!(
|
crate::log_info!(
|
||||||
|
|
|
||||||
|
|
@ -1076,13 +1076,16 @@ const resolvedAppUrl = useMemo(() => {
|
||||||
// Listener para atualizacao de mensagens nao lidas (sincroniza sessoes completas)
|
// Listener para atualizacao de mensagens nao lidas (sincroniza sessoes completas)
|
||||||
listen<UnreadUpdateEvent>("raven://chat/unread-update", (event) => {
|
listen<UnreadUpdateEvent>("raven://chat/unread-update", (event) => {
|
||||||
if (disposed) return
|
if (disposed) return
|
||||||
logDesktop("chat:unread-update", { totalUnread: event.payload.totalUnread, sessionsCount: event.payload.sessions.length })
|
console.log("[CHAT DEBUG] unread-update recebido:", JSON.stringify(event.payload, null, 2))
|
||||||
|
logDesktop("chat:unread-update", { totalUnread: event.payload.totalUnread, sessionsCount: event.payload.sessions?.length ?? 0 })
|
||||||
setChatUnreadCount(event.payload.totalUnread)
|
setChatUnreadCount(event.payload.totalUnread)
|
||||||
// Atualiza sessoes com dados completos do backend
|
// Atualiza sessoes com dados completos do backend
|
||||||
if (event.payload.sessions && event.payload.sessions.length > 0) {
|
if (event.payload.sessions && event.payload.sessions.length > 0) {
|
||||||
|
console.log("[CHAT DEBUG] Atualizando chatSessions com", event.payload.sessions.length, "sessoes")
|
||||||
setChatSessions(event.payload.sessions)
|
setChatSessions(event.payload.sessions)
|
||||||
} else if (event.payload.totalUnread === 0) {
|
} else if (event.payload.totalUnread === 0) {
|
||||||
// Sem sessoes ativas
|
// Sem sessoes ativas
|
||||||
|
console.log("[CHAT DEBUG] Sem sessoes ativas, limpando chatSessions")
|
||||||
setChatSessions([])
|
setChatSessions([])
|
||||||
}
|
}
|
||||||
}).then(unlisten => {
|
}).then(unlisten => {
|
||||||
|
|
@ -1093,14 +1096,17 @@ const resolvedAppUrl = useMemo(() => {
|
||||||
// Listener para nova mensagem (abre widget se fechado)
|
// Listener para nova mensagem (abre widget se fechado)
|
||||||
listen<NewMessageEvent>("raven://chat/new-message", (event) => {
|
listen<NewMessageEvent>("raven://chat/new-message", (event) => {
|
||||||
if (disposed) return
|
if (disposed) return
|
||||||
|
console.log("[CHAT DEBUG] new-message recebido:", JSON.stringify(event.payload, null, 2))
|
||||||
logDesktop("chat:new-message", { totalUnread: event.payload.totalUnread, newCount: event.payload.newCount })
|
logDesktop("chat:new-message", { totalUnread: event.payload.totalUnread, newCount: event.payload.newCount })
|
||||||
setChatUnreadCount(event.payload.totalUnread)
|
setChatUnreadCount(event.payload.totalUnread)
|
||||||
// Atualiza sessoes com dados completos do backend
|
// Atualiza sessoes com dados completos do backend
|
||||||
if (event.payload.sessions && event.payload.sessions.length > 0) {
|
if (event.payload.sessions && event.payload.sessions.length > 0) {
|
||||||
|
console.log("[CHAT DEBUG] Atualizando chatSessions com", event.payload.sessions.length, "sessoes")
|
||||||
setChatSessions(event.payload.sessions)
|
setChatSessions(event.payload.sessions)
|
||||||
}
|
}
|
||||||
// Abre o widget quando chega nova mensagem
|
// Abre o widget quando chega nova mensagem
|
||||||
if (event.payload.newCount > 0) {
|
if (event.payload.newCount > 0) {
|
||||||
|
console.log("[CHAT DEBUG] Nova mensagem! Abrindo widget...")
|
||||||
setIsChatOpen(true)
|
setIsChatOpen(true)
|
||||||
}
|
}
|
||||||
}).then(unlisten => {
|
}).then(unlisten => {
|
||||||
|
|
|
||||||
|
|
@ -516,7 +516,7 @@ export function ChatWidget() {
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={handleEndChat}
|
onClick={handleEndChat}
|
||||||
disabled={isEndingChat}
|
disabled={isEndingChat}
|
||||||
className="gap-1.5 text-red-600 hover:bg-red-50 hover:text-red-700"
|
className="gap-1.5 border border-red-300 text-red-600 hover:border-red-400 hover:bg-red-50 hover:text-red-700"
|
||||||
>
|
>
|
||||||
{isEndingChat ? (
|
{isEndingChat ? (
|
||||||
<Spinner className="size-3.5" />
|
<Spinner className="size-3.5" />
|
||||||
|
|
|
||||||
|
|
@ -241,7 +241,7 @@ export function TicketChatPanel({ ticketId }: TicketChatPanelProps) {
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={handleEndLiveChat}
|
onClick={handleEndLiveChat}
|
||||||
disabled={isEndingChat}
|
disabled={isEndingChat}
|
||||||
className="gap-1.5 text-red-600 hover:bg-red-50 hover:text-red-700"
|
className="gap-1.5 border border-red-300 text-red-600 hover:border-red-400 hover:bg-red-50 hover:text-red-700"
|
||||||
>
|
>
|
||||||
{isEndingChat ? <Spinner className="size-3" /> : <X className="size-3" />}
|
{isEndingChat ? <Spinner className="size-3" /> : <X className="size-3" />}
|
||||||
Encerrar
|
Encerrar
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue