mirror of
https://github.com/dergigi/boris.git
synced 2026-01-17 13:54:24 +01:00
refactor: remove synthetic added_at field, use created_at from bookmark list event
This commit is contained in:
@@ -349,26 +349,20 @@ class BookmarkController {
|
||||
const sortedBookmarks = enriched
|
||||
.map(b => ({
|
||||
...b,
|
||||
urlReferences: extractUrlsFromContent(b.content),
|
||||
// Ensure we have valid timestamps for sorting
|
||||
added_at: b.added_at || b.created_at || 0,
|
||||
created_at: b.created_at || 0
|
||||
urlReferences: extractUrlsFromContent(b.content)
|
||||
}))
|
||||
.sort((a, b) => {
|
||||
// Sort by added_at (when item was added to bookmark list), then by created_at
|
||||
// Both should be newest first (descending)
|
||||
const addedDiff = (b.added_at || 0) - (a.added_at || 0)
|
||||
if (addedDiff !== 0) return addedDiff
|
||||
// Sort by created_at (timestamp of bookmark list event = when bookmarked)
|
||||
// Newest first (descending)
|
||||
return (b.created_at || 0) - (a.created_at || 0)
|
||||
})
|
||||
|
||||
// DEBUG: Log sorting details for top 10 bookmarks
|
||||
console.log('🔍 Bookmark Sorting Debug:')
|
||||
sortedBookmarks.slice(0, 10).forEach((b, i) => {
|
||||
const addedDate = b.added_at ? new Date(b.added_at * 1000).toISOString() : 'none'
|
||||
const createdDate = b.created_at ? new Date(b.created_at * 1000).toISOString() : 'none'
|
||||
const bookmarkedDate = b.created_at ? new Date(b.created_at * 1000).toISOString() : 'none'
|
||||
const contentPreview = (b.content || '').substring(0, 50)
|
||||
console.log(` ${i + 1}. [${b.type}] added_at: ${addedDate}, created_at: ${createdDate}`)
|
||||
console.log(` ${i + 1}. [${b.type}] bookmarked at: ${bookmarkedDate}`)
|
||||
console.log(` content: "${contentPreview}"`)
|
||||
})
|
||||
console.log(`Total bookmarks: ${sortedBookmarks.length}\n`)
|
||||
|
||||
@@ -81,14 +81,14 @@ export const processApplesauceBookmarks = (
|
||||
allItems.push({
|
||||
id: note.id,
|
||||
content: '',
|
||||
created_at: note.created_at || parentCreatedAt || 0,
|
||||
// Use parent event timestamp (when bookmarked), not note creation time
|
||||
created_at: parentCreatedAt || 0,
|
||||
pubkey: note.author || activeAccount.pubkey,
|
||||
kind: 1, // Short note kind
|
||||
tags: [],
|
||||
parsedContent: undefined,
|
||||
type: 'event' as const,
|
||||
isPrivate,
|
||||
added_at: note.added_at || parentCreatedAt || 0
|
||||
isPrivate
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -101,14 +101,14 @@ export const processApplesauceBookmarks = (
|
||||
allItems.push({
|
||||
id: coordinate,
|
||||
content: '',
|
||||
created_at: article.created_at || parentCreatedAt || 0,
|
||||
// Use parent event timestamp (when bookmarked), not article creation time
|
||||
created_at: parentCreatedAt || 0,
|
||||
pubkey: article.pubkey,
|
||||
kind: article.kind, // Usually 30023 for long-form articles
|
||||
tags: [],
|
||||
parsedContent: undefined,
|
||||
type: 'event' as const,
|
||||
isPrivate,
|
||||
added_at: article.added_at || parentCreatedAt || 0
|
||||
isPrivate
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -125,8 +125,7 @@ export const processApplesauceBookmarks = (
|
||||
tags: [['t', hashtag]],
|
||||
parsedContent: undefined,
|
||||
type: 'event' as const,
|
||||
isPrivate,
|
||||
added_at: parentCreatedAt || 0
|
||||
isPrivate
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -143,8 +142,7 @@ export const processApplesauceBookmarks = (
|
||||
tags: [['r', url]],
|
||||
parsedContent: undefined,
|
||||
type: 'event' as const,
|
||||
isPrivate,
|
||||
added_at: parentCreatedAt || 0
|
||||
isPrivate
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -159,24 +157,21 @@ export const processApplesauceBookmarks = (
|
||||
const result = {
|
||||
id: bookmark.id!,
|
||||
content: bookmark.content || '',
|
||||
created_at: bookmark.created_at || parentCreatedAt || 0,
|
||||
// Use parent event timestamp (when bookmarked), not content creation time
|
||||
created_at: parentCreatedAt || 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,
|
||||
// added_at should be when the bookmark was added (parentCreatedAt = bookmark list event timestamp)
|
||||
// NOT when the content itself was created
|
||||
added_at: parentCreatedAt || bookmark.created_at || 0
|
||||
isPrivate
|
||||
}
|
||||
|
||||
// DEBUG: Log timestamp assignment
|
||||
if (Math.random() < 0.05) { // Log ~5% of bookmarks to avoid spam
|
||||
console.log('📌 Processing bookmark:')
|
||||
console.log(` parentCreatedAt: ${parentCreatedAt ? new Date(parentCreatedAt * 1000).toISOString() : 'none'}`)
|
||||
console.log(` bookmark.created_at: ${bookmark.created_at ? new Date(bookmark.created_at * 1000).toISOString() : 'none'}`)
|
||||
console.log(` result.added_at: ${result.added_at ? new Date(result.added_at * 1000).toISOString() : 'none'}`)
|
||||
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 preview: "${(bookmark.content || '').substring(0, 40)}"`)
|
||||
}
|
||||
|
||||
|
||||
@@ -146,7 +146,6 @@ export async function collectBookmarksFromEvents(
|
||||
parsedContent: undefined,
|
||||
type: 'web' as const,
|
||||
isPrivate: false,
|
||||
added_at: evt.created_at || Math.floor(Date.now() / 1000),
|
||||
sourceKind: 39701,
|
||||
setName: dTag,
|
||||
setTitle,
|
||||
|
||||
@@ -76,7 +76,7 @@ export async function fetchAllReads(
|
||||
source: 'bookmark',
|
||||
type: 'article',
|
||||
readingProgress: 0,
|
||||
readingTimestamp: bookmark.added_at || bookmark.created_at
|
||||
readingTimestamp: bookmark.created_at
|
||||
}
|
||||
readsMap.set(coordinate, item)
|
||||
if (onItem) emitItem(item)
|
||||
|
||||
@@ -31,6 +31,7 @@ export interface Bookmark {
|
||||
export interface IndividualBookmark {
|
||||
id: string
|
||||
content: string
|
||||
// Timestamp from the bookmark list event (when this was bookmarked)
|
||||
created_at: number
|
||||
pubkey: string
|
||||
kind: number
|
||||
@@ -40,8 +41,6 @@ export interface IndividualBookmark {
|
||||
type: 'event' | 'article' | 'web'
|
||||
isPrivate?: boolean
|
||||
encryptedContent?: string
|
||||
// When the item was added to the bookmark list (synthetic, for sorting)
|
||||
added_at?: number
|
||||
// The kind of the source list/set that produced this bookmark (e.g., 10003, 30003, 30001, or 39701 for web)
|
||||
sourceKind?: number
|
||||
// The 'd' tag value from kind 30003 bookmark sets
|
||||
|
||||
@@ -87,7 +87,7 @@ export const renderParsedContent = (parsedContent: ParsedContent) => {
|
||||
export const sortIndividualBookmarks = (items: IndividualBookmark[]) => {
|
||||
return items
|
||||
.slice()
|
||||
.sort((a, b) => ((b.added_at || 0) - (a.added_at || 0)) || ((b.created_at || 0) - (a.created_at || 0)))
|
||||
.sort((a, b) => (b.created_at || 0) - (a.created_at || 0))
|
||||
}
|
||||
|
||||
export function groupIndividualBookmarks(items: IndividualBookmark[]) {
|
||||
|
||||
@@ -51,7 +51,7 @@ export function deriveLinksFromBookmarks(bookmarks: Bookmark[]): ReadItem[] {
|
||||
summary,
|
||||
image,
|
||||
readingProgress: 0,
|
||||
readingTimestamp: bookmark.added_at || bookmark.created_at
|
||||
readingTimestamp: bookmark.created_at
|
||||
}
|
||||
|
||||
linksMap.set(url, item)
|
||||
|
||||
@@ -49,7 +49,7 @@ export function deriveReadsFromBookmarks(bookmarks: Bookmark[]): ReadItem[] {
|
||||
source: 'bookmark',
|
||||
type: 'article',
|
||||
readingProgress: 0,
|
||||
readingTimestamp: bookmark.added_at || bookmark.created_at,
|
||||
readingTimestamp: bookmark.created_at,
|
||||
title,
|
||||
summary,
|
||||
image,
|
||||
|
||||
Reference in New Issue
Block a user