From af192952a78ccd29a7518f387a487607d210245c Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Mon, 27 Oct 2025 19:30:51 -0400 Subject: [PATCH] Fix modal profile lightning cache updates --- js/app.js | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/js/app.js b/js/app.js index 04abbbc9..089d8e82 100644 --- a/js/app.js +++ b/js/app.js @@ -9189,8 +9189,12 @@ class Application { return; } + const parsedLud16 = + typeof parsed?.lud16 === "string" ? parsed.lud16.trim() : ""; + const parsedLud06 = + typeof parsed?.lud06 === "string" ? parsed.lud06.trim() : ""; const lightningAddressCandidate = (() => { - const fields = [parsed?.lud16, parsed?.lud06]; + const fields = [parsedLud16, parsedLud06]; for (const field of fields) { if (typeof field !== "string") { continue; @@ -9229,6 +9233,10 @@ class Application { } const nextLightning = lightningAddressCandidate || ""; + const previousLightning = + typeof this.currentVideo?.lightningAddress === "string" + ? this.currentVideo.lightningAddress + : ""; if (this.currentVideo) { this.currentVideo.lightningAddress = nextLightning ? nextLightning : null; @@ -9241,12 +9249,14 @@ class Application { name: resolvedProfile.name, picture: resolvedProfile.picture, pubkey: normalized, + lightningAddress: nextLightning ? nextLightning : null, }; } else { this.currentVideo.creator = { name: resolvedProfile.name, picture: resolvedProfile.picture, pubkey: normalized, + lightningAddress: nextLightning ? nextLightning : null, }; } } @@ -9272,14 +9282,38 @@ class Application { parsed?.username, ]); - if (fetchedNameCandidate || sanitizedFetchedPicture) { + const cachedLightning = + typeof cachedProfile?.lightningAddress === "string" + ? cachedProfile.lightningAddress.trim() + : ""; + const shouldUpdateCache = + Boolean(fetchedNameCandidate) || + Boolean(sanitizedFetchedPicture) || + cachedLightning !== nextLightning || + previousLightning !== nextLightning; + + if (shouldUpdateCache) { try { + const profileForCache = { + name: fetchedNameCandidate || resolvedProfile.name, + picture: sanitizedFetchedPicture || resolvedProfile.picture, + }; + + if (parsedLud16) { + profileForCache.lud16 = parsedLud16; + } + + if (parsedLud06) { + profileForCache.lud06 = parsedLud06; + } + + if (nextLightning) { + profileForCache.lightningAddress = nextLightning; + } + this.setProfileCacheEntry( normalized, - { - name: fetchedNameCandidate || resolvedProfile.name, - picture: sanitizedFetchedPicture || resolvedProfile.picture, - }, + profileForCache, { persist: false, reason: "modal-profile-fetch" }, ); } catch (error) {