Remembering note order breaks adding notes at the top, instead sort by max created_at in thread

This commit is contained in:
Jonathan Staab 2022-12-27 15:40:31 -08:00
parent 207f8093a3
commit fb3426e80e

View File

@ -1,8 +1,8 @@
<script>
import {sortBy, reject, pluck} from 'ramda'
import {sortBy, pluck, reject} from 'ramda'
import {onMount} from 'svelte'
import {slide} from 'svelte/transition'
import {quantify, createMap} from 'hurdak/lib/hurdak'
import {quantify} from 'hurdak/lib/hurdak'
import {createScroller, now} from 'src/util/misc'
import {findReply} from 'src/util/nostr'
import Spinner from 'src/partials/Spinner.svelte'
@ -12,28 +12,14 @@
export let loadNotes
export let queryNotes
let prevNotes = []
const notes = relay.lq(async () => {
const notes = await queryNotes()
const annotated = await relay.annotateChunk(notes)
const annotatedById = createMap('id', annotated)
// Keep sort order intact, more recent replies can cause parent notes
// to show up at the top of a feed, but then an early parent date pushes
// it to the bottom if we just filter by created_at
const sorted = prevNotes
.map(id => annotatedById[id])
.concat(
sortBy(
e => -e.created_at,
annotated.filter(e => !prevNotes.includes(e.id))
)
)
prevNotes = pluck('id', sorted)
return sorted
return sortBy(
e => -pluck('created_at', e.replies).concat(e.created_at).reduce((a, b) => Math.max(a, b)),
annotated
)
})
let until = now()