Ajusta auto-minimização do chat web e unifica realtime no desktop

This commit is contained in:
rever-tecnologia 2025-12-11 17:46:33 -03:00
parent c65e37e232
commit 3d45fe3b04
10 changed files with 279 additions and 635 deletions

View file

@ -83,6 +83,8 @@ pub struct ChatSessionSummary {
pub struct ChatMessagesResponse {
pub messages: Vec<ChatMessage>,
pub has_session: bool,
#[serde(default)]
pub unread_count: Option<u32>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@ -259,6 +261,36 @@ pub async fn send_message(
.map_err(|e| format!("Falha ao parsear resposta de send: {e}"))
}
pub async fn mark_messages_read(
base_url: &str,
token: &str,
ticket_id: &str,
message_ids: &[String],
) -> Result<(), String> {
let url = format!("{}/api/machines/chat/read", base_url);
let payload = serde_json::json!({
"machineToken": token,
"ticketId": ticket_id,
"messageIds": message_ids,
});
let response = CHAT_CLIENT
.post(&url)
.json(&payload)
.send()
.await
.map_err(|e| format!("Falha na requisicao de mark read: {e}"))?;
if !response.status().is_success() {
let status = response.status();
let body = response.text().await.unwrap_or_default();
return Err(format!("Mark read falhou: status={}, body={}", status, body));
}
Ok(())
}
// ============================================================================
// UPLOAD DE ARQUIVOS
// ============================================================================
@ -835,4 +867,3 @@ pub fn set_chat_minimized(app: &tauri::AppHandle, ticket_id: &str, minimized: bo
crate::log_info!("Chat {} -> minimized={}", ticket_id, minimized);
Ok(())
}

View file

@ -284,6 +284,19 @@ async fn send_chat_message(
chat::send_message(&base_url, &token, &ticket_id, &body, attachments).await
}
#[tauri::command]
async fn mark_chat_messages_read(
base_url: String,
token: String,
ticket_id: String,
message_ids: Vec<String>,
) -> Result<(), String> {
if message_ids.is_empty() {
return Ok(());
}
chat::mark_messages_read(&base_url, &token, &ticket_id, &message_ids).await
}
#[tauri::command]
async fn upload_chat_file(
base_url: String,
@ -501,6 +514,7 @@ pub fn run() {
fetch_chat_sessions,
fetch_chat_messages,
send_chat_message,
mark_chat_messages_read,
upload_chat_file,
open_chat_window,
close_chat_window,