const profiles=new Map(); // Public lookups retain the profile API's privacy and suspension checks. async function profileFor(db,username){ if(!profiles.has(username))profiles.set(username,db.rpc('community_profile',{p_username:username}).then(({data,error})=>error?null:data?.[0]||null).catch(()=>null)); return profiles.get(username); } export function memberAvatar(db,member,{className='member-avatar',own=false}={}){ const avatar=document.createElement('span');avatar.className=className;avatar.setAttribute('aria-hidden','true'); const fallback=document.createElement('span');fallback.textContent=(member.display_name||member.username||'?').trim().slice(0,1).toUpperCase();avatar.append(fallback); const paint=profile=>{const url=profile?.avatar_url;if(typeof url!=='string'||!url.startsWith('https://'))return; const image=document.createElement('img');image.alt='';image.loading='lazy';image.decoding='async';image.referrerPolicy='no-referrer';image.onload=()=>{fallback.hidden=true;};image.onerror=()=>{image.remove();fallback.hidden=false;};image.src=url;avatar.append(image); }; if(own)paint(member);else if(member.username)profileFor(db,member.username).then(paint); return avatar; }