From a5c779aa2e021d6f3d8bb7aa100dc10172f48dd5 Mon Sep 17 00:00:00 2001 From: Ayo Date: Sat, 21 Jan 2023 20:34:50 +0100 Subject: [PATCH] refactor: removeFilteredItems function --- composables/timeline.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/composables/timeline.ts b/composables/timeline.ts index f884f96d..380f2865 100644 --- a/composables/timeline.ts +++ b/composables/timeline.ts @@ -9,14 +9,18 @@ function areStatusesConsecutive(a: mastodon.v1.Status, b: mastodon.v1.Status) { return !!inReplyToId && (inReplyToId === a.reblog?.id || inReplyToId === a.id) } -export function reorderedTimeline(items: mastodon.v1.Status[], context: mastodon.v1.FilterContext) { - let steps = 0 - +function removeFilteredItems(items: mastodon.v1.Status[], context: mastodon.v1.FilterContext): mastodon.v1.Status[] { const isStrict = (filter: mastodon.v1.FilterResult) => filter.filter.filterAction === 'hide' && filter.filter.context.includes(context) const isFiltered = (item: mastodon.v1.Status) => !item.filtered?.find(isStrict) const isReblogFiltered = (item: mastodon.v1.Status) => !item.reblog?.filtered?.find(isStrict) - const newItems = [...items].filter(isFiltered).filter(isReblogFiltered) + return [...items].filter(isFiltered).filter(isReblogFiltered) +} + +export function reorderedTimeline(items: mastodon.v1.Status[], context: mastodon.v1.FilterContext) { + let steps = 0 + + const newItems = removeFilteredItems(items, context) for (let i = newItems.length - 1; i > 0; i--) { for (let k = 1; k <= maxDistance && i - k >= 0; k++) {