Dont apply the content-language filter if it will remove all content (#3492)

* Dont apply the content-language filter if it will remove all content

* Improve code
zio/stable
Paul Frazee 2024-04-12 07:53:11 -07:00 committed by GitHub
parent ad97d4350c
commit ed2c8b720e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 5 deletions

View File

@ -1,11 +1,12 @@
import {
AppBskyEmbedRecord,
AppBskyEmbedRecordWithMedia,
AppBskyFeedDefs,
AppBskyFeedPost,
AppBskyEmbedRecordWithMedia,
AppBskyEmbedRecord,
} from '@atproto/api'
import {ReasonFeedSource} from './feed/types'
import {isPostInLanguage} from '../../locale/helpers'
import {ReasonFeedSource} from './feed/types'
type FeedViewPost = AppBskyFeedDefs.FeedViewPost
export type FeedTunerFn = (
@ -341,6 +342,8 @@ export class FeedTuner {
tuner: FeedTuner,
slices: FeedViewPostsSlice[],
): FeedViewPostsSlice[] => {
const candidateSlices = slices.slice()
// early return if no languages have been specified
if (!preferredLangsCode2.length || preferredLangsCode2.length === 0) {
return slices
@ -357,10 +360,17 @@ export class FeedTuner {
// if item does not fit preferred language, remove it
if (!hasPreferredLang) {
slices.splice(i, 1)
candidateSlices.splice(i, 1)
}
}
return slices
// if the language filter cleared out the entire page, return the original set
// so that something always shows
if (candidateSlices.length === 0) {
return slices
}
return candidateSlices
}
}
}