Auto-fetch saved profile metadata

This commit is contained in:
thePR0M3TH3AN committed 2025-09-29 23:38:22 -04:00
1 parent 3f4b56ae90
commit b50996b907
2 files changed
+34 -7

No files matched your search

+3
View File
@@ -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.
+31 -7
View File
@@ -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);
}
}
/**