mirror of
https://github.com/coracle-social/coracle.git
synced 2024-09-19 11:43:35 +00:00
Remembering note order breaks adding notes at the top, instead sort by max created_at in thread
This commit is contained in:
parent
207f8093a3
commit
fb3426e80e
@ -1,8 +1,8 @@
|
|||||||
<script>
|
<script>
|
||||||
import {sortBy, reject, pluck} from 'ramda'
|
import {sortBy, pluck, reject} from 'ramda'
|
||||||
import {onMount} from 'svelte'
|
import {onMount} from 'svelte'
|
||||||
import {slide} from 'svelte/transition'
|
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 {createScroller, now} from 'src/util/misc'
|
||||||
import {findReply} from 'src/util/nostr'
|
import {findReply} from 'src/util/nostr'
|
||||||
import Spinner from 'src/partials/Spinner.svelte'
|
import Spinner from 'src/partials/Spinner.svelte'
|
||||||
@ -12,28 +12,14 @@
|
|||||||
export let loadNotes
|
export let loadNotes
|
||||||
export let queryNotes
|
export let queryNotes
|
||||||
|
|
||||||
let prevNotes = []
|
|
||||||
|
|
||||||
const notes = relay.lq(async () => {
|
const notes = relay.lq(async () => {
|
||||||
const notes = await queryNotes()
|
const notes = await queryNotes()
|
||||||
const annotated = await relay.annotateChunk(notes)
|
const annotated = await relay.annotateChunk(notes)
|
||||||
const annotatedById = createMap('id', annotated)
|
|
||||||
|
|
||||||
// Keep sort order intact, more recent replies can cause parent notes
|
return sortBy(
|
||||||
// to show up at the top of a feed, but then an early parent date pushes
|
e => -pluck('created_at', e.replies).concat(e.created_at).reduce((a, b) => Math.max(a, b)),
|
||||||
// it to the bottom if we just filter by created_at
|
annotated
|
||||||
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
|
|
||||||
})
|
})
|
||||||
|
|
||||||
let until = now()
|
let until = now()
|
||||||
|
Loading…
Reference in New Issue
Block a user