feat(bookmarks): sort by added_at (recently added first), fallback to event time\n\n- Track synthetic added_at on processed items\n- Keep order aligned with append semantics from Kind 10003 guidance (newest at end)\n- Cite: https://nostrbook.dev/kinds/10003

This commit is contained in:
Gigi
2025-10-03 01:41:11 +02:00
parent 86de9c9f1f
commit 0964156bcc
3 changed files with 9 additions and 4 deletions

View File

@@ -66,7 +66,8 @@ export const processApplesauceBookmarks = (
tags: bookmark.tags || [],
parsedContent: bookmark.content ? (getParsedContent(bookmark.content) as ParsedContent) : undefined,
type: 'event' as const,
isPrivate
isPrivate,
added_at: Math.floor(Date.now() / 1000)
}))
}
@@ -80,7 +81,8 @@ export const processApplesauceBookmarks = (
tags: bookmark.tags || [],
parsedContent: bookmark.content ? (getParsedContent(bookmark.content) as ParsedContent) : undefined,
type: 'event' as const,
isPrivate
isPrivate,
added_at: Math.floor(Date.now() / 1000)
}))
}

View File

@@ -113,7 +113,8 @@ export const fetchBookmarks = async (
...hydrateItems(privateItemsAll, idToEvent)
])
// Sort individual bookmarks by timestamp (newest first)
// Sort individual bookmarks by "added" timestamp first (most recently added first),
// falling back to event created_at when unknown.
const enriched = allBookmarks.map(b => ({
...b,
tags: b.tags || [],
@@ -121,7 +122,7 @@ export const fetchBookmarks = async (
}))
const sortedBookmarks = enriched
.map(b => ({ ...b, urlReferences: extractUrlsFromContent(b.content) }))
.sort((a, b) => (b.created_at || 0) - (a.created_at || 0))
.sort((a, b) => ((b.added_at || 0) - (a.added_at || 0)) || ((b.created_at || 0) - (a.created_at || 0)))
const bookmark: Bookmark = {
id: `${activeAccount.pubkey}-bookmarks`,

View File

@@ -40,6 +40,8 @@ export interface IndividualBookmark {
type: 'event' | 'article'
isPrivate?: boolean
encryptedContent?: string
// When the item was added to the bookmark list (synthetic, for sorting)
added_at?: number
}
export interface ActiveAccount {