diff --git a/js/app.js b/js/app.js index 825a3bde..ebd95aa0 100644 --- a/js/app.js +++ b/js/app.js @@ -3940,16 +3940,10 @@ class Application { ? normalizedProfile.npub.trim() : ""; - const fallbackNpub = (() => { - if (explicitNpub) { - return explicitNpub; - } - const encoded = this.safeEncodeNpub(normalizedPubkey); - return typeof encoded === "string" ? encoded : ""; - })(); - - const shortNpubLabel = fallbackNpub - ? formatShortNpub(fallbackNpub) || fallbackNpub + const encodedPubkeyNpub = this.safeEncodeNpub(normalizedPubkey); + const resolvedNpub = explicitNpub || encodedPubkeyNpub || ""; + const shortNpubLabel = resolvedNpub + ? formatShortNpub(resolvedNpub) || resolvedNpub : ""; // For any .author-pic[data-pubkey=...] @@ -3963,7 +3957,8 @@ class Application { el.src = pictureUrl; }); - const nameLabel = resolvedName || shortNpubLabel || fallbackNpub || ""; + const nameLabel = + resolvedName || shortNpubLabel || resolvedNpub || ""; // For any .author-name[data-pubkey=...] const nameEls = document.querySelectorAll( @@ -3976,26 +3971,55 @@ class Application { el.textContent = nameLabel; }); - const npubEls = document.querySelectorAll( - `.author-npub[data-pubkey="${normalizedPubkey}"]` - ); + const npubSelectors = new Set(); + if (resolvedNpub) { + npubSelectors.add(`.author-npub[data-npub="${resolvedNpub}"]`); + } + npubSelectors.add(`.author-npub[data-pubkey="${normalizedPubkey}"]`); + + const npubElements = new Set(); + npubSelectors.forEach((selector) => { + document.querySelectorAll(selector).forEach((el) => { + if (el) { + npubElements.add(el); + } + }); + }); + + const npubEls = Array.from(npubElements); + npubEls.forEach((el) => { if (!el) { return; } - if (shortNpubLabel) { - el.textContent = shortNpubLabel; + const displayNpub = resolvedNpub + ? shortNpubLabel || resolvedNpub + : ""; + const hasDisplayNpub = Boolean(displayNpub); + + if (hasDisplayNpub) { + el.textContent = displayNpub; el.setAttribute("aria-hidden", "false"); } else { el.textContent = ""; el.setAttribute("aria-hidden", "true"); } - if (fallbackNpub) { - el.setAttribute("title", fallbackNpub); + if (resolvedNpub) { + el.setAttribute("title", resolvedNpub); + if (el.dataset) { + el.dataset.npub = resolvedNpub; + } } else { el.removeAttribute("title"); + if (el.dataset && "npub" in el.dataset) { + delete el.dataset.npub; + } + } + + if (el.dataset && normalizedPubkey) { + el.dataset.pubkey = normalizedPubkey; } }); @@ -4024,7 +4048,7 @@ class Application { if (cardInstances.size) { const identityPayload = { name: resolvedName, - npub: fallbackNpub, + npub: resolvedNpub, shortNpub: shortNpubLabel, pubkey: normalizedPubkey, }; diff --git a/js/ui/components/SimilarContentCard.js b/js/ui/components/SimilarContentCard.js index 8babe809..904d761a 100644 --- a/js/ui/components/SimilarContentCard.js +++ b/js/ui/components/SimilarContentCard.js @@ -262,8 +262,18 @@ export class SimilarContentCard { this.authorNpubEl.removeAttribute("title"); } - if (this.identity.pubkey) { - this.authorNpubEl.dataset.pubkey = this.identity.pubkey; + if (this.identity.npub) { + this.authorNpubEl.dataset.npub = this.identity.npub; + } else if (this.authorNpubEl.dataset?.npub) { + delete this.authorNpubEl.dataset.npub; + } + + const resolvedPubkey = + this.identity.pubkey || + (typeof this.video?.pubkey === "string" ? this.video.pubkey.trim() : ""); + + if (resolvedPubkey) { + this.authorNpubEl.dataset.pubkey = resolvedPubkey; } else if (this.authorNpubEl.dataset?.pubkey) { delete this.authorNpubEl.dataset.pubkey; }