group chat: profile photos missing on a cached re-open (only initials showed)
The instant-paint work renders a group thread from cache BEFORE /api/groups/members (convoMembers) loads, so senderAvatar had no avatar and drew initials only; the later network render diffs/skips the unchanged messages, so the photos never came back until a full reload. Platform-agnostic (desktop + iOS), group-only — matching the report. Fix: senderAvatar now falls back to the global CONTACTS avatar so the cache paint is already correct, and openConvo repaints the sender avatars (refreshSenderAvatars) once convoMembers loads. Web-only; live on next app launch. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -2197,7 +2197,11 @@ function convoShellHTML(it){
|
||||
+ '</div>';
|
||||
}
|
||||
// Small round avatar (photo if the member has one, else colored initials) for a group message sender.
|
||||
function senderAvatar(id, name){ const mem=convoMembers.find(x=>x.id===id); const av=mem&&mem.avatar; return '<span class="snd-av" style="background:'+avColor(name||'?')+'">'+(av?'<img src="'+pEsc(av)+'" alt="" onerror="this.remove()">':'')+pEsc(initials(name||'?'))+'</span>'; }
|
||||
function senderAvatar(id, name){ const mem=convoMembers.find(x=>x.id===id); let av=mem&&mem.avatar; if(!av){ try{ const c=(typeof CONTACTS!=='undefined'?CONTACTS:[]).find(x=>x&&x.id===id); av=c&&c.avatar; }catch(_){} } return '<span class="snd-av" style="background:'+avColor(name||'?')+'">'+(av?'<img src="'+pEsc(av)+'" alt="" onerror="this.remove()">':'')+pEsc(initials(name||'?'))+'</span>'; } // #DP: fall back to the global CONTACTS avatar so a cached-open paint (before convoMembers loads) still shows photos, not just initials
|
||||
// Repaint group message sender avatars once convoMembers is loaded — the instant cache-paint renders before the
|
||||
// member list arrives, and the network render diffs/skips unchanged messages, so without this the photos would
|
||||
// stay as initials on a re-opened group until a full reload.
|
||||
function refreshSenderAvatars(){ try{ document.querySelectorAll('#msgs .sender[data-uid]').forEach(sd=>{ const uid=sd.getAttribute('data-uid'); const old=sd.querySelector('.snd-av'); if(!uid||!old) return; const mem=convoMembers.find(x=>x.id===uid); const spans=sd.querySelectorAll('span'); const nm=(mem&&mem.name)||(spans.length?spans[spans.length-1].textContent:'')||''; old.outerHTML=senderAvatar(uid, nm); }); }catch(_){} }
|
||||
function bubbleHTML(m){
|
||||
if(m.evt==='call-start') return '<div class="sys-msg">📞 '+(m.from===ME.id?'You':pEsc(m.byName||'Someone'))+' started a call</div>';
|
||||
// Unanswered 1:1: the caller (message sender) sees "Call not answered"; the callee sees "Missed call".
|
||||
@@ -3633,6 +3637,7 @@ async function openConvo(kind,id){
|
||||
if(window.__freshOpen){ window.__freshOpen=false; armOpenSlide(); }
|
||||
if(kind==='group'){ try{ convoMembers=await fetch('/api/groups/members?group='+encodeURIComponent(id)).then(r=>r.json())||[]; }catch(_){ convoMembers=[]; } }
|
||||
if(!selected||selected.kind!==kind||selected.id!==id) return;
|
||||
if(kind==='group') refreshSenderAvatars(); // #DP: the cache paint rendered sender avatars before members loaded → repaint them with photos now
|
||||
wireMentions();
|
||||
const url=kind==='group'?('/api/messages/thread?group='+encodeURIComponent(id)):('/api/messages/thread?with='+encodeURIComponent(id));
|
||||
// msgs stays null on a failed/non-OK fetch (distinct from a genuinely empty [] thread), so a flaky
|
||||
|
||||
Reference in New Issue
Block a user