From db02b24e05652fca464f81e7618dc0f436828aea Mon Sep 17 00:00:00 2001 From: captain Date: Sat, 7 Mar 2026 13:35:08 +0800 Subject: [PATCH] feat(android): Simplify file sharing UI by delegating status management to Rust backend - Remove manual UI status tracking for file uploads from JavaScript - Eliminate chat message DOM manipulation for upload progress display - Delegate file status management to Rust backend for automatic database record creation - Add chat history reload after file sharing to display latest message state - Simplify handleShareToUser function by removing redundant UI update logic - Improve reliability by using backend as single source of truth for file message state --- src/js/app.js | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/src/js/app.js b/src/js/app.js index 1ae0044..2fa9380 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -184,35 +184,11 @@ async function handleShareToUser(userId, userName, userAddr, sharedFiles) { try { console.log("[JS-App] 发送文件:", fileInfo.fileName); - // 在聊天界面显示上传中状态 - const chatBox = document.getElementById('chat-box'); - if (chatBox) { - const msgDiv = document.createElement('div'); - msgDiv.className = 'message sent'; - msgDiv.innerHTML = ` -
- ${fileInfo.fileName} - ${formatFileSize(fileInfo.fileSize)} - 上传中... -
- `; - chatBox.appendChild(msgDiv); - chatBox.scrollTop = chatBox.scrollHeight; - } - - // 发送文件 + // 发送文件(Rust 会自动创建数据库记录) await apiSendFileFromAndroidUri(userId, userAddr, fileInfo); console.log("[JS-App] 文件发送成功:", fileInfo.fileName); - // 更新状态为已发送 - const statusSpans = document.querySelectorAll('.file-uploading'); - statusSpans.forEach(span => { - if (span.previousElementSibling?.textContent === formatFileSize(fileInfo.fileSize)) { - span.textContent = '已发送'; - span.classList.remove('file-uploading'); - } - }); } catch (e) { console.error("[JS-App] 文件发送失败:", fileInfo.fileName, e); alert(`发送文件失败: ${fileInfo.fileName}\n${e.message}`); @@ -221,6 +197,10 @@ async function handleShareToUser(userId, userName, userAddr, sharedFiles) { // 清除待处理的分享文件 apiClearAndroidSharedFiles(); + + // 重新加载聊天历史以显示最新状态 + console.log("[JS-App] 重新加载聊天历史"); + await loadChatHistory(userId); } // 格式化文件大小