feat: reordered replies in profile

This commit is contained in:
patak 2022-12-29 17:25:04 +01:00
parent 12280afe70
commit bc868da226
5 changed files with 21 additions and 21 deletions

View file

@ -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
}
</script>
<template>
<div>
<PublishWidget draft-key="home" border="b base" />
<TimelinePaginator v-bind="{ paginator, stream, preprocess }" context="home" />
<TimelinePaginator v-bind="{ paginator, stream }" :preprocess="timelineWithReorderedReplies" context="home" />
</div>
</template>

View file

@ -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
}

View file

@ -26,6 +26,6 @@ if (account) {
<template>
<div>
<AccountTabs />
<TimelinePaginator :paginator="paginator" context="account" />
<TimelinePaginator :paginator="paginator" :preprocess="timelineWithReorderedReplies" context="account" />
</div>
</template>

View file

@ -24,6 +24,6 @@ if (account) {
<template>
<div>
<AccountTabs />
<TimelinePaginator :paginator="paginator" context="account" />
<TimelinePaginator :paginator="paginator" :preprocess="timelineWithReorderedReplies" context="account" />
</div>
</template>

View file

@ -24,6 +24,6 @@ if (account) {
<template>
<div>
<AccountTabs />
<TimelinePaginator :paginator="paginator" context="account" />
<TimelinePaginator :paginator="paginator" :preprocess="timelineWithReorderedReplies" context="account" />
</div>
</template>