From 3f2227ef4ce5700caa6d4f324a40f0ef064934b8 Mon Sep 17 00:00:00 2001 From: Ayo Date: Tue, 10 Jan 2023 17:57:58 +0100 Subject: [PATCH] feat: filter stream items if filterAction is 'hide' --- composables/timeline.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/composables/timeline.ts b/composables/timeline.ts index 0d0d9b4c..8fb1dc7f 100644 --- a/composables/timeline.ts +++ b/composables/timeline.ts @@ -9,10 +9,16 @@ 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[]) { +export function reorderedTimeline(items: mastodon.v1.Status[], context: mastodon.v1.FilterContext = 'public') { let steps = 0 - const newItems = [...items] - for (let i = items.length - 1; i > 0; i--) { + + 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) + + for (let i = newItems.length - 1; i > 0; i--) { for (let k = 1; k <= maxDistance && i - k >= 0; k++) { // Prevent infinite loops steps++