|
|
|
@ -159,7 +159,7 @@ class ClientService { |
|
|
|
onReplies, |
|
|
|
onReplies, |
|
|
|
onNew |
|
|
|
onNew |
|
|
|
}: { |
|
|
|
}: { |
|
|
|
onReplies: (events: NEvent[], until?: number) => void |
|
|
|
onReplies: (events: NEvent[], isCache: boolean, until?: number) => void |
|
|
|
onNew: (evt: NEvent) => void |
|
|
|
onNew: (evt: NEvent) => void |
|
|
|
} |
|
|
|
} |
|
|
|
) { |
|
|
|
) { |
|
|
|
@ -170,7 +170,7 @@ class ClientService { |
|
|
|
replies = (await Promise.all(cache.refs.map(([id]) => this.eventCache.get(id)))).filter( |
|
|
|
replies = (await Promise.all(cache.refs.map(([id]) => this.eventCache.get(id)))).filter( |
|
|
|
Boolean |
|
|
|
Boolean |
|
|
|
) as NEvent[] |
|
|
|
) as NEvent[] |
|
|
|
onReplies(replies, cache.until) |
|
|
|
onReplies(replies, true, cache.until) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
cache = { refs } |
|
|
|
cache = { refs } |
|
|
|
this.repliesCache.set(parentEventId, cache) |
|
|
|
this.repliesCache.set(parentEventId, cache) |
|
|
|
@ -206,12 +206,21 @@ class ClientService { |
|
|
|
hasEosed = true |
|
|
|
hasEosed = true |
|
|
|
const newReplies = events.sort((a, b) => a.created_at - b.created_at) |
|
|
|
const newReplies = events.sort((a, b) => a.created_at - b.created_at) |
|
|
|
replies = replies.concat(newReplies) |
|
|
|
replies = replies.concat(newReplies) |
|
|
|
refs.push(...newReplies.map((evt) => [evt.id, evt.created_at] as [string, number])) |
|
|
|
|
|
|
|
// first fetch
|
|
|
|
// first fetch
|
|
|
|
if (!since) { |
|
|
|
if (!since) { |
|
|
|
cache.until = events.length >= limit ? events[0].created_at - 1 : undefined |
|
|
|
cache.until = events.length >= limit ? events[0].created_at - 1 : undefined |
|
|
|
} |
|
|
|
} |
|
|
|
onReplies(replies, cache.until) |
|
|
|
onReplies(replies, false, cache.until) |
|
|
|
|
|
|
|
const lastRefCreatedAt = refs.length ? refs[refs.length - 1][1] : undefined |
|
|
|
|
|
|
|
if (lastRefCreatedAt) { |
|
|
|
|
|
|
|
refs.push( |
|
|
|
|
|
|
|
...newReplies |
|
|
|
|
|
|
|
.filter((reply) => reply.created_at > lastRefCreatedAt) |
|
|
|
|
|
|
|
.map((evt) => [evt.id, evt.created_at] as [string, number]) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
refs.push(...newReplies.map((evt) => [evt.id, evt.created_at] as [string, number])) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
) |
|
|
|
) |
|
|
|
|