From 1ac1ce19fafd754515b4e5f39b389e641b0270f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90?= Date: Wed, 4 Jan 2023 15:14:37 +0800 Subject: [PATCH] revert: "feat: reorder consecutive posts that have others in between" This reverts commit 364acd998e325aab9bcd115804f1015929e54fa7. --- composables/masto.ts | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/composables/masto.ts b/composables/masto.ts index a3b15a2d..0d0946d2 100644 --- a/composables/masto.ts +++ b/composables/masto.ts @@ -160,35 +160,17 @@ async function fetchRelationships() { } const maxDistance = 10 - -// Checks if (b) is a reply to (a) -function areStatusesConsecutive(a: Status, b: Status) { - const inReplyToId = b.inReplyToId ?? b.reblog?.inReplyToId - return !!inReplyToId && (inReplyToId === a.reblog?.id || inReplyToId === a.id) -} - export function timelineWithReorderedReplies(items: Status[]) { const newItems = [...items] // TODO: Basic reordering, we should get something more efficient and robust for (let i = items.length - 1; i > 0; i--) { for (let k = 1; k <= maxDistance && i - k >= 0; k++) { - // Check if the [i-k] item is a reply to the [i] item - // This means that they are in the wrong order - if (areStatusesConsecutive(newItems[i], newItems[i - k])) { + const inReplyToId = newItems[i - k].inReplyToId ?? newItems[i - k].reblog?.inReplyToId + if (inReplyToId && (inReplyToId === newItems[i].reblog?.id || inReplyToId === newItems[i].id)) { const item = newItems.splice(i, 1)[0] - newItems.splice(i - k, 0, item) // insert older item before the newer one + newItems.splice(i - k, 0, item) k = 1 } - else if (k > 1) { - // Check if the [i] item is a reply to the [i-k] item - // This means that they are in the correct order but there are posts between them - if (areStatusesConsecutive(newItems[i - k], newItems[i])) { - const item = newItems.splice(i, 1)[0] - // insert older item after the newer one - newItems.splice(i - k + 1, 0, item) - k = 1 - } - } } } return newItems