From 4e6ace408c6c4fb0a64addc9155716e7a4746a90 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Thu, 22 Jan 2026 19:23:57 -0500 Subject: [PATCH] Preserve explore feed ordering --- js/app.js | 24 +++++++++++++++--------- js/ui/views/VideoListView.js | 14 ++++++++++---- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/js/app.js b/js/app.js index 07c936f4..8e946067 100644 --- a/js/app.js +++ b/js/app.js @@ -5952,12 +5952,20 @@ class Application { const runtime = this.buildExploreFeedRuntime(); const normalizedReason = typeof reason === "string" ? reason : undefined; const fallback = Array.isArray(fallbackVideos) ? fallbackVideos : []; + const applyExploreOrderingMetadata = (source) => { + const next = source && typeof source === "object" ? { ...source } : {}; + if (!next.sortOrder) { + next.sortOrder = "explore"; + } + next.preserveOrder = true; + return next; + }; if (!this.feedEngine || typeof this.feedEngine.run !== "function") { - const metadata = { + const metadata = applyExploreOrderingMetadata({ reason: normalizedReason, engine: "unavailable", - }; + }); this.latestFeedMetadata = metadata; this.videosMap = this.nostrService.getVideosMap(); if (this.videoListView) { @@ -5971,12 +5979,10 @@ class Application { .run("explore", { runtime }) .then((result) => { const videos = Array.isArray(result?.videos) ? result.videos : []; - const metadata = { + const metadata = applyExploreOrderingMetadata({ ...(result?.metadata || {}), - }; - if (normalizedReason) { - metadata.reason = normalizedReason; - } + ...(normalizedReason ? { reason: normalizedReason } : {}), + }); this.latestFeedMetadata = metadata; this.videosMap = this.nostrService.getVideosMap(); @@ -5990,10 +5996,10 @@ class Application { }) .catch((error) => { devLogger.error("[Application] Failed to run explore feed:", error); - const metadata = { + const metadata = applyExploreOrderingMetadata({ reason: normalizedReason || "error:explore-feed", error: true, - }; + }); this.latestFeedMetadata = metadata; this.videosMap = this.nostrService.getVideosMap(); if (this.videoListView) { diff --git a/js/ui/views/VideoListView.js b/js/ui/views/VideoListView.js index 9be143f6..4bd5c7ad 100644 --- a/js/ui/views/VideoListView.js +++ b/js/ui/views/VideoListView.js @@ -599,10 +599,16 @@ export class VideoListView { return displayVideos; } - displayVideos.sort( - (a, b) => - this.getVideoPostedAtForSort(b) - this.getVideoPostedAtForSort(a), - ); + const preserveOrder = + normalizedMetadata?.sortOrder === "explore" || + normalizedMetadata?.preserveOrder === true; + + if (!preserveOrder) { + displayVideos.sort( + (a, b) => + this.getVideoPostedAtForSort(b) - this.getVideoPostedAtForSort(a), + ); + } this.currentVideos = displayVideos.slice(); const signaturePayload = displayVideos.map((video) => ({