diff --git a/docs/qa.md b/docs/qa.md index 2b785423..79447636 100644 --- a/docs/qa.md +++ b/docs/qa.md @@ -17,5 +17,8 @@ Run this checklist before publishing releases or merging changes that touch uplo 5. **Cross-Browser Verification** - Spot-check Chromium and Firefox (desktop) for console warnings about CORS, Range requests, or tracker connectivity. - Optionally validate on mobile Safari/Chrome if the change targets mobile UX. +6. **Saved Profile Metadata Refresh** + - In the browser devtools console/storage panel, delete `bitvid:profileCache:v1` but keep `bitvid:savedProfiles:v1` populated with Nostr pubkeys that lack stored names/avatars. + - Reload the page and open the profile switcher; confirm avatars and display names populate automatically without manual refresh. Document findings (pass/fail notes plus relevant screenshots or logs) so they can be attached to release or PR notes. diff --git a/js/app.js b/js/app.js index 5bce857c..f55d8776 100644 --- a/js/app.js +++ b/js/app.js @@ -1082,18 +1082,19 @@ class bitvidApp { } getProfileCacheEntry(pubkey) { - if (!pubkey) { + const normalized = this.normalizeHexPubkey(pubkey); + if (!normalized) { return null; } - const entry = this.profileCache.get(pubkey); + const entry = this.profileCache.get(normalized); if (!entry) { return null; } const timestamp = typeof entry.timestamp === "number" ? entry.timestamp : 0; if (!timestamp || Date.now() - timestamp > PROFILE_CACHE_TTL_MS) { - this.profileCache.delete(pubkey); + this.profileCache.delete(normalized); this.persistProfileCacheToStorage(); return null; } @@ -1102,7 +1103,8 @@ class bitvidApp { } setProfileCacheEntry(pubkey, profile) { - if (!pubkey || !profile) { + const normalizedPubkey = this.normalizeHexPubkey(pubkey); + if (!normalizedPubkey || !profile) { return; } @@ -1116,9 +1118,9 @@ class bitvidApp { timestamp: Date.now(), }; - this.profileCache.set(pubkey, entry); + this.profileCache.set(normalizedPubkey, entry); this.persistProfileCacheToStorage(); - const didUpdateSavedProfile = this.syncSavedProfileFromCache(pubkey, { + const didUpdateSavedProfile = this.syncSavedProfileFromCache(normalizedPubkey, { persist: true, }); if (!didUpdateSavedProfile) { @@ -3556,6 +3558,7 @@ class bitvidApp { const normalizedActive = this.normalizeHexPubkey( this.activeProfilePubkey ); + const entriesNeedingFetch = new Set(); const resolveMeta = (entry) => { if (!entry || typeof entry !== "object") { @@ -3566,9 +3569,26 @@ class bitvidApp { }; } - const cacheEntry = this.profileCache.get(entry.pubkey); + const normalizedPubkey = this.normalizeHexPubkey(entry.pubkey); + let cacheEntry = null; + if (normalizedPubkey) { + cacheEntry = this.getProfileCacheEntry(normalizedPubkey); + } const cachedProfile = cacheEntry?.profile || {}; + const hasStoredName = + typeof entry.name === "string" && entry.name.trim().length > 0; + const hasStoredPicture = + typeof entry.picture === "string" && entry.picture.trim().length > 0; + + if ( + !cacheEntry && + normalizedPubkey && + (!hasStoredName || !hasStoredPicture) + ) { + entriesNeedingFetch.add(normalizedPubkey); + } + let resolvedNpub = typeof entry.npub === "string" && entry.npub.trim() ? entry.npub.trim() @@ -3794,6 +3814,10 @@ class bitvidApp { } else { this.updateProfileModalFocusables(); } + + if (entriesNeedingFetch.size) { + this.batchFetchProfiles(entriesNeedingFetch); + } } /**