From bc47c1ff64de42ad7269a991aed447726941fef6 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 24 Aug 2026 17:41:58 +0000 Subject: [PATCH] =?UTF-8?q?Fix:=20formatTime=20undefined=20=E2=86=92=20app?= =?UTF-8?q?endMessage=20=D0=BF=D0=B0=D0=B4=D0=B0=D0=BB=20=E2=86=92=20?= =?UTF-8?q?=D1=87=D0=B0=D1=82=20=D0=BF=D1=83=D1=81=D1=82=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Grok не зря говорил — bubbles не появлялись из-за неопределённой функции formatTime в appendMessage template. ReferenceError ловился в try/catch, но bubbles не рендерились. Добавлен formatTime(s) в app.js + try/catch в appendMessage с отправкой AppendMsgError на /api/v1/debug/log --- public/index.html | 20 ++++++++++---------- public/js/app.js | 16 ++++++++++++++++ public/js/views/chat.js | 7 +++++++ 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/public/index.html b/public/index.html index d787e8c..d7e129e 100644 --- a/public/index.html +++ b/public/index.html @@ -34,15 +34,15 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/public/js/app.js b/public/js/app.js index de4ea41..c810412 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -556,6 +556,22 @@ function escapeHtml(s) { return String(s).replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c])); } +function formatTime(s) { + if (!s) return ''; + try { + const d = new Date(s); + if (isNaN(d.getTime())) return ''; + const now = new Date(); + const sameDay = d.toDateString() === now.toDateString(); + const hh = String(d.getHours()).padStart(2, '0'); + const mm = String(d.getMinutes()).padStart(2, '0'); + if (sameDay) return `${hh}:${mm}`; + const dd = String(d.getDate()).padStart(2, '0'); + const mo = String(d.getMonth() + 1).padStart(2, '0'); + return `${dd}.${mo} ${hh}:${mm}`; + } catch { return ''; } +} + // Debug-оверлей: показывает ошибки JS прямо на экране (для отладки в обычном браузере) window.addEventListener('error', (e) => { console.error('Global error:', e); diff --git a/public/js/views/chat.js b/public/js/views/chat.js index 5c6583d..4ddcb60 100644 --- a/public/js/views/chat.js +++ b/public/js/views/chat.js @@ -83,6 +83,7 @@ const ChatView = { 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)); + try { 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); @@ -110,6 +111,12 @@ const ChatView = { box.appendChild(div); console.log('[Chat] appended bubble, children:', box.children.length); box.scrollTop = box.scrollHeight; + } catch (e) { + console.error('[Chat] appendMessage EXCEPTION:', e, 'm:', JSON.stringify(m).slice(0, 200)); + try { + fetch('/api/v1/debug/log', { method: 'POST', credentials: 'include', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ kind: 'AppendMsgError', msg: String(e && e.message), stack: String(e && e.stack || '').slice(0, 400), m: String(JSON.stringify(m).slice(0, 200)) }) }); + } catch {} + } }, onMessageClick(m) {