From bc868da22647b6473649b28d469c1146be253923 Mon Sep 17 00:00:00 2001 From: patak Date: Thu, 29 Dec 2022 17:25:04 +0100 Subject: [PATCH] feat: reordered replies in profile --- components/timeline/TimelineHome.vue | 19 +------------------ composables/masto.ts | 17 +++++++++++++++++ pages/[[server]]/@[account]/index/index.vue | 2 +- pages/[[server]]/@[account]/index/media.vue | 2 +- .../@[account]/index/with_replies.vue | 2 +- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/components/timeline/TimelineHome.vue b/components/timeline/TimelineHome.vue index 9581e452..7a0c77ae 100644 --- a/components/timeline/TimelineHome.vue +++ b/components/timeline/TimelineHome.vue @@ -3,28 +3,11 @@ import type { Status } from 'masto' const paginator = useMasto().timelines.iterateHome() const stream = useMasto().stream.streamUser() onBeforeUnmount(() => stream?.then(s => s.disconnect())) - -const maxDistance = 10 -function preprocess(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++) { - const inReplyToId = newItems[i - k].inReplyToId // TODO: ?? newItems[i - k].reblog?.inReplyToId - if (inReplyToId === newItems[i].reblog?.id || inReplyToId === newItems[i].id) { - const item = newItems.splice(i, 1)[0] - newItems.splice(i - k, 0, item) - k = 1 - } - } - } - return newItems -} diff --git a/composables/masto.ts b/composables/masto.ts index df8b7bcb..0d708cfe 100644 --- a/composables/masto.ts +++ b/composables/masto.ts @@ -172,3 +172,20 @@ async function fetchRelationships() { for (let i = 0; i < requested.length; i++) requested[i][1].value = relationships[i] } + +const maxDistance = 10 +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++) { + const inReplyToId = newItems[i - k].inReplyToId // TODO: ?? newItems[i - k].reblog?.inReplyToId + if (inReplyToId === newItems[i].reblog?.id || inReplyToId === newItems[i].id) { + const item = newItems.splice(i, 1)[0] + newItems.splice(i - k, 0, item) + k = 1 + } + } + } + return newItems +} diff --git a/pages/[[server]]/@[account]/index/index.vue b/pages/[[server]]/@[account]/index/index.vue index b11a3bfd..6ff53fa6 100644 --- a/pages/[[server]]/@[account]/index/index.vue +++ b/pages/[[server]]/@[account]/index/index.vue @@ -26,6 +26,6 @@ if (account) { diff --git a/pages/[[server]]/@[account]/index/media.vue b/pages/[[server]]/@[account]/index/media.vue index 385ba498..daf25590 100644 --- a/pages/[[server]]/@[account]/index/media.vue +++ b/pages/[[server]]/@[account]/index/media.vue @@ -24,6 +24,6 @@ if (account) { diff --git a/pages/[[server]]/@[account]/index/with_replies.vue b/pages/[[server]]/@[account]/index/with_replies.vue index a3af2523..48154054 100644 --- a/pages/[[server]]/@[account]/index/with_replies.vue +++ b/pages/[[server]]/@[account]/index/with_replies.vue @@ -24,6 +24,6 @@ if (account) {