diff --git a/js/app.js b/js/app.js index d6fdbc6e..12539648 100644 --- a/js/app.js +++ b/js/app.js @@ -839,6 +839,7 @@ class Application { videoRootId: video.videoRootId, dTag: dTagValue, fallbackEventId: video.id, + relay: video.relay, }); } @@ -7625,16 +7626,20 @@ class Application { const decoded = window.NostrTools.nip19.decode(maybeNevent); if (decoded.type === "nevent" && decoded.data.id) { const eventId = decoded.data.id; + const relay = + Array.isArray(decoded.data.relays) && decoded.data.relays.length + ? decoded.data.relays[0] + : null; // 1) check local map let localMatch = this.videosMap.get(eventId); if (localMatch) { - this.playVideoByEventId(eventId); + this.playVideoByEventId(eventId, { relay }); } else { // 2) fallback => getOldEventById this.getOldEventById(eventId) .then((video) => { if (video) { - this.playVideoByEventId(eventId); + this.playVideoByEventId(eventId, { relay }); } else { this.showError("No matching video found for that link."); } @@ -8468,6 +8473,7 @@ class Application { videoRootId: video.videoRootId, dTag: dTagValue, fallbackEventId: video.id || eventId, + relay: hint.relay || video.relay, }); this.currentVideoPointer = pointerInfo?.pointer || null; diff --git a/js/utils/videoPointer.js b/js/utils/videoPointer.js index 10358362..948f481f 100644 --- a/js/utils/videoPointer.js +++ b/js/utils/videoPointer.js @@ -16,28 +16,33 @@ export function resolveVideoPointer({ videoRootId, dTag, fallbackEventId, + relay, } = {}) { const normalizedPubkey = normalizeString(pubkey).toLowerCase(); const normalizedKind = typeof kind === "number" && Number.isFinite(kind) ? kind : DEFAULT_VIDEO_KIND; const pointerCandidates = []; + const normalizedRelay = normalizeString(relay); const rootId = normalizeString(videoRootId); if (rootId && normalizedPubkey) { - pointerCandidates.push(["a", `${normalizedKind}:${normalizedPubkey}:${rootId}`]); + const ptr = ["a", `${normalizedKind}:${normalizedPubkey}:${rootId}`]; + if (normalizedRelay) ptr.push(normalizedRelay); + pointerCandidates.push(ptr); } const normalizedDTag = normalizeString(dTag); if (normalizedDTag && normalizedPubkey) { - pointerCandidates.push([ - "a", - `${normalizedKind}:${normalizedPubkey}:${normalizedDTag}`, - ]); + const ptr = ["a", `${normalizedKind}:${normalizedPubkey}:${normalizedDTag}`]; + if (normalizedRelay) ptr.push(normalizedRelay); + pointerCandidates.push(ptr); } const fallbackId = normalizeString(fallbackEventId); if (fallbackId) { - pointerCandidates.push(["e", fallbackId]); + const ptr = ["e", fallbackId]; + if (normalizedRelay) ptr.push(normalizedRelay); + pointerCandidates.push(ptr); } for (const pointer of pointerCandidates) {