fix: preserve content created_at, add listUpdatedAt for sorting by when bookmarked

This commit is contained in:
Gigi
2025-10-22 12:26:01 +02:00
parent 8bb871913b
commit 4f78ee4794
5 changed files with 31 additions and 22 deletions

View File

@@ -352,17 +352,20 @@ class BookmarkController {
urlReferences: extractUrlsFromContent(b.content)
}))
.sort((a, b) => {
// Sort by created_at (timestamp of bookmark list event = when bookmarked)
// Sort by listUpdatedAt (timestamp of bookmark list event = proxy for when bookmarked)
// Newest first (descending)
return (b.created_at || 0) - (a.created_at || 0)
return (b.listUpdatedAt || 0) - (a.listUpdatedAt || 0)
})
// DEBUG: Log sorting details for top 10 bookmarks
console.log('🔍 Bookmark Sorting Debug:')
sortedBookmarks.slice(0, 10).forEach((b, i) => {
const bookmarkedDate = b.created_at ? new Date(b.created_at * 1000).toISOString() : 'none'
const listUpdated = b.listUpdatedAt ? new Date(b.listUpdatedAt * 1000).toISOString() : 'none'
const contentCreated = b.created_at ? new Date(b.created_at * 1000).toISOString() : 'none'
const contentPreview = (b.content || '').substring(0, 50)
console.log(` ${i + 1}. [${b.type}] bookmarked at: ${bookmarkedDate}`)
console.log(` ${i + 1}. [${b.type}]`)
console.log(` list updated: ${listUpdated}`)
console.log(` content created: ${contentCreated}`)
console.log(` content: "${contentPreview}"`)
})
console.log(`Total bookmarks: ${sortedBookmarks.length}\n`)

View File

@@ -81,14 +81,14 @@ export const processApplesauceBookmarks = (
allItems.push({
id: note.id,
content: '',
// Use parent event timestamp (when bookmarked), not note creation time
created_at: parentCreatedAt || 0,
created_at: note.created_at || 0,
pubkey: note.author || activeAccount.pubkey,
kind: 1, // Short note kind
tags: [],
parsedContent: undefined,
type: 'event' as const,
isPrivate
isPrivate,
listUpdatedAt: parentCreatedAt || 0
})
})
}
@@ -101,14 +101,14 @@ export const processApplesauceBookmarks = (
allItems.push({
id: coordinate,
content: '',
// Use parent event timestamp (when bookmarked), not article creation time
created_at: parentCreatedAt || 0,
created_at: article.created_at || 0,
pubkey: article.pubkey,
kind: article.kind, // Usually 30023 for long-form articles
tags: [],
parsedContent: undefined,
type: 'event' as const,
isPrivate
isPrivate,
listUpdatedAt: parentCreatedAt || 0
})
})
}
@@ -119,13 +119,14 @@ export const processApplesauceBookmarks = (
allItems.push({
id: `hashtag-${hashtag}`,
content: `#${hashtag}`,
created_at: parentCreatedAt || 0,
created_at: 0, // Hashtags don't have their own creation time
pubkey: activeAccount.pubkey,
kind: 1,
tags: [['t', hashtag]],
parsedContent: undefined,
type: 'event' as const,
isPrivate
isPrivate,
listUpdatedAt: parentCreatedAt || 0
})
})
}
@@ -136,13 +137,14 @@ export const processApplesauceBookmarks = (
allItems.push({
id: `url-${url}`,
content: url,
created_at: parentCreatedAt || 0,
created_at: 0, // URLs don't have their own creation time
pubkey: activeAccount.pubkey,
kind: 1,
tags: [['r', url]],
parsedContent: undefined,
type: 'event' as const,
isPrivate
isPrivate,
listUpdatedAt: parentCreatedAt || 0
})
})
}
@@ -157,21 +159,21 @@ export const processApplesauceBookmarks = (
const result = {
id: bookmark.id!,
content: bookmark.content || '',
// Use parent event timestamp (when bookmarked), not content creation time
created_at: parentCreatedAt || 0,
created_at: bookmark.created_at || 0,
pubkey: activeAccount.pubkey,
kind: bookmark.kind || 30001,
tags: bookmark.tags || [],
parsedContent: bookmark.content ? (getParsedContent(bookmark.content) as ParsedContent) : undefined,
type: 'event' as const,
isPrivate
isPrivate,
listUpdatedAt: parentCreatedAt || 0
}
// DEBUG: Log timestamp assignment
if (Math.random() < 0.05) { // Log ~5% of bookmarks to avoid spam
console.log('📌 Processing bookmark:')
console.log(` parentCreatedAt (list event): ${parentCreatedAt ? new Date(parentCreatedAt * 1000).toISOString() : 'none'}`)
console.log(` result.created_at (when bookmarked): ${result.created_at ? new Date(result.created_at * 1000).toISOString() : 'none'}`)
console.log(` content created_at: ${result.created_at ? new Date(result.created_at * 1000).toISOString() : 'none'}`)
console.log(` list updated at: ${result.listUpdatedAt ? new Date(result.listUpdatedAt * 1000).toISOString() : 'none'}`)
console.log(` content preview: "${(bookmark.content || '').substring(0, 40)}"`)
}

View File

@@ -150,7 +150,8 @@ export async function collectBookmarksFromEvents(
setName: dTag,
setTitle,
setDescription,
setImage
setImage,
listUpdatedAt: evt.created_at || Math.floor(Date.now() / 1000)
})
continue
}

View File

@@ -31,7 +31,7 @@ export interface Bookmark {
export interface IndividualBookmark {
id: string
content: string
// Timestamp from the bookmark list event (when this was bookmarked)
// Timestamp when the content was created (from the content event itself)
created_at: number
pubkey: string
kind: number
@@ -49,6 +49,9 @@ export interface IndividualBookmark {
setTitle?: string
setDescription?: string
setImage?: string
// Timestamp of the bookmark list event (best proxy for "when bookmarked")
// Note: This is imperfect - it's when the list was last updated, not necessarily when this item was added
listUpdatedAt?: number
}
export interface ActiveAccount {

View File

@@ -87,7 +87,7 @@ export const renderParsedContent = (parsedContent: ParsedContent) => {
export const sortIndividualBookmarks = (items: IndividualBookmark[]) => {
return items
.slice()
.sort((a, b) => (b.created_at || 0) - (a.created_at || 0))
.sort((a, b) => (b.listUpdatedAt || 0) - (a.listUpdatedAt || 0))
}
export function groupIndividualBookmarks(items: IndividualBookmark[]) {