From 0a75969475854e849ae5c5a7383e1a1951c0b233 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 29 Aug 2024 20:22:18 +0100 Subject: [PATCH] Fix language filtering for feeds (#5026) * Fix language filtering for feeds * Simplify logic --- src/lib/api/feed-manip.ts | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/lib/api/feed-manip.ts b/src/lib/api/feed-manip.ts index c2b80ca0..a0ee647b 100644 --- a/src/lib/api/feed-manip.ts +++ b/src/lib/api/feed-manip.ts @@ -392,27 +392,20 @@ export class FeedTuner { slices: FeedViewPostsSlice[], _dryRun: boolean, ): FeedViewPostsSlice[] => { - const candidateSlices = slices.slice() - // early return if no languages have been specified if (!preferredLangsCode2.length || preferredLangsCode2.length === 0) { return slices } - for (let i = 0; i < slices.length; i++) { - let hasPreferredLang = false - for (const item of slices[i].items) { + const candidateSlices = slices.filter(slice => { + for (const item of slice.items) { if (isPostInLanguage(item.post, preferredLangsCode2)) { - hasPreferredLang = true - break + return true } } - // if item does not fit preferred language, remove it - if (!hasPreferredLang) { - candidateSlices.splice(i, 1) - } - } + return false + }) // if the language filter cleared out the entire page, return the original set // so that something always shows