diff --git a/server/public/home.html b/server/public/home.html index 5210cdd..28fc5bf 100644 --- a/server/public/home.html +++ b/server/public/home.html @@ -788,7 +788,7 @@
- @@ -1795,9 +1795,19 @@ async function openConvo(kind,id){ if(!selected||selected.kind!==kind||selected.id!==id) return; wireMentions(); const url=kind==='group'?('/api/messages/thread?group='+encodeURIComponent(id)):('/api/messages/thread?with='+encodeURIComponent(id)); - let msgs=[]; try{ msgs=await fetch(url).then(r=>r.json()); }catch(_){} + // msgs stays null on a failed/non-OK fetch (distinct from a genuinely empty [] thread), so a flaky + // desktop network can't be mistaken for "no messages". + let msgs=null; try{ const r=await fetch(url); if(r.ok) msgs=await r.json(); }catch(_){} if(!selected||selected.kind!==kind||selected.id!==id) return; // switched away while loading - THREAD=Array.isArray(msgs)?msgs:[]; + if(!Array.isArray(msgs)){ + // Fetch failed / errored — DO NOT blank the chat or overwrite the cache (that wiped messages that + // are still safely on the server → the "messages disappear after reopen" bug). Keep the cached + // render; only show empty if we truly have nothing cached to fall back to. + if(!THREAD_CACHE.has(ckey)){ THREAD=[]; renderThread(); } + const inp0=document.getElementById('msgInput'); if(inp0) inp0.focus(); + return; + } + THREAD=msgs; THREAD_CACHE.set(ckey, THREAD.slice()); renderThread(); // #3: if there were unread messages, drop a "New messages" divider, scroll to the first unread,