From bfaa3af1affd96ea0de7eac7101d3ae7eac5a4e4 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 21 Aug 2026 12:38:01 +0000 Subject: [PATCH] =?UTF-8?q?Debug:=20loadMessages/appendMessage=20=D0=BB?= =?UTF-8?q?=D0=BE=D0=B3=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Grok рекомендовал: console.log чтобы понять: 1. r.messages это массив 2. appendMessage не падает с exception 3. #messages элемент существует --- public/index.html | 20 ++++++++++---------- public/js/views/chat.js | 18 ++++++++++++++++-- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/public/index.html b/public/index.html index 7a40884..d787e8c 100644 --- a/public/index.html +++ b/public/index.html @@ -34,15 +34,15 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/public/js/views/chat.js b/public/js/views/chat.js index 4fbaef0..5c6583d 100644 --- a/public/js/views/chat.js +++ b/public/js/views/chat.js @@ -59,19 +59,32 @@ const ChatView = { }, async loadMessages() { + console.log('[Chat] loadMessages start, chatId:', this.chatId); try { const r = await API.ChatApi.listMessages(this.chatId); + console.log('[Chat] listMessages response:', JSON.stringify(r).slice(0, 500), 'messages isArray:', Array.isArray(r.messages)); const box = document.getElementById('messages'); + console.log('[Chat] messages box:', box, 'tag:', box?.tagName); + if (!box) { console.error('[Chat] no #messages element'); return; } box.innerHTML = ''; - r.messages.forEach((m) => this.appendMessage(m)); + const msgs = Array.isArray(r.messages) ? r.messages : (Array.isArray(r) ? r : []); + console.log('[Chat] will append', msgs.length, 'messages'); + msgs.forEach((m) => { + try { this.appendMessage(m); } catch (e) { console.error('[Chat] appendMessage failed for', m, e); } + }); box.scrollTop = box.scrollHeight; } catch (e) { - console.warn(e); + console.error('[Chat] loadMessages error:', e); + try { + fetch('/api/v1/debug/log', { method: 'POST', credentials: 'include', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ kind: 'ChatLoadError', msg: String(e && e.message), stack: String(e && e.stack || '').slice(0, 400) }) }); + } catch {} } }, appendMessage(m) { + console.log('[Chat] appendMessage called, m:', JSON.stringify(m).slice(0, 200), 'me check:', API.Store.user && m.sender_id === (API.Store.user.id || API.Store.user.user_id)); const box = document.getElementById('messages'); + if (!box) { console.error('[Chat] appendMessage: no box'); return; } const me = API.Store.user && m.sender_id === (API.Store.user.id || API.Store.user.user_id); const div = document.createElement('div'); div.className = 'bubble-b ' + (me ? 'out' : 'in'); @@ -95,6 +108,7 @@ const ChatView = { } } box.appendChild(div); + console.log('[Chat] appended bubble, children:', box.children.length); box.scrollTop = box.scrollHeight; },