fix: ensure watch history is sorted by most recent first

- Enforce descending month order in `js/nostr/watchHistory.js` by explicitly sorting keys before flattening buckets.
- Update `js/feedEngine/watchHistoryFeed.js` and `js/historyView.js` to use `video.created_at` as a fallback sort key when `watchedAt` is missing or equal.
- Verified logic with `tests/verify_sort.mjs`.
This commit is contained in:
google-labs-jules[bot] committed 2026-01-07 00:28:39 +00:00
1 parent ad961cd401
commit f2f55830e8
3 files changed
+55 -8

No files matched your search

+26 -4
View File
@@ -195,8 +195,19 @@ function createWatchHistorySource({ service = watchHistoryService } = {}) {
}
results.sort((a, b) => {
if (a.watchedAt !== b.watchedAt) {
return b.watchedAt - a.watchedAt;
const watchedA = a?.watchedAt || 0;
const watchedB = b?.watchedAt || 0;
if (watchedA !== watchedB) {
return watchedB - watchedA;
}
const createdA = Number.isFinite(a?.video?.created_at)
? a.video.created_at
: 0;
const createdB = Number.isFinite(b?.video?.created_at)
? b.video.created_at
: 0;
if (createdA !== createdB) {
return createdB - createdA;
}
return a.pointerKey.localeCompare(b.pointerKey);
});
@@ -488,8 +499,19 @@ function createWatchHistorySorter() {
}
const copy = [...items];
copy.sort((a, b) => {
if (a?.watchedAt !== b?.watchedAt) {
return (b?.watchedAt || 0) - (a?.watchedAt || 0);
const watchedA = a?.watchedAt || 0;
const watchedB = b?.watchedAt || 0;
if (watchedA !== watchedB) {
return watchedB - watchedA;
}
const createdA = Number.isFinite(a?.video?.created_at)
? a.video.created_at
: 0;
const createdB = Number.isFinite(b?.video?.created_at)
? b.video.created_at
: 0;
if (createdA !== createdB) {
return createdB - createdA;
}
const aKey = typeof a?.pointerKey === "string" ? a.pointerKey : "";
const bKey = typeof b?.pointerKey === "string" ? b.pointerKey : "";