From 2754121f6790216a4371c98b4b1934c8c77589ec Mon Sep 17 00:00:00 2001 From: Mary <148872143+mary-ext@users.noreply.github.com> Date: Tue, 6 Feb 2024 06:44:14 +0700 Subject: [PATCH] Bump replies (#2604) * fix: bump replies * refactor: only bump if not at 0 --- src/lib/api/feed-manip.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/lib/api/feed-manip.ts b/src/lib/api/feed-manip.ts index c964693c..22706259 100644 --- a/src/lib/api/feed-manip.ts +++ b/src/lib/api/feed-manip.ts @@ -168,14 +168,25 @@ export class FeedTuner { const selfReplyUri = getSelfReplyUri(item) if (selfReplyUri) { - const parent = slices.find(item2 => - item2.isNextInThread(selfReplyUri), + const index = slices.findIndex(slice => + slice.isNextInThread(selfReplyUri), ) - if (parent) { + + if (index !== -1) { + const parent = slices[index] + parent.insert(item) + + // If our slice isn't currently on the top, reinsert it to the top. + if (index !== 0) { + slices.splice(index, 1) + slices.unshift(parent) + } + continue } } + slices.unshift(new FeedViewPostsSlice([item])) } }