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 { import {
AppBskyEmbedRecord,
AppBskyEmbedRecordWithMedia,
AppBskyFeedDefs, AppBskyFeedDefs,
AppBskyFeedPost, AppBskyFeedPost,
AppBskyEmbedRecordWithMedia,
AppBskyEmbedRecord,
} from '@atproto/api' } from '@atproto/api'
import {ReasonFeedSource} from './feed/types'
import {isPostInLanguage} from '../../locale/helpers' import {isPostInLanguage} from '../../locale/helpers'
import {ReasonFeedSource} from './feed/types'
type FeedViewPost = AppBskyFeedDefs.FeedViewPost type FeedViewPost = AppBskyFeedDefs.FeedViewPost
export type FeedTunerFn = ( export type FeedTunerFn = (
@ -341,6 +342,8 @@ export class FeedTuner {
tuner: FeedTuner, tuner: FeedTuner,
slices: FeedViewPostsSlice[], slices: FeedViewPostsSlice[],
): FeedViewPostsSlice[] => { ): FeedViewPostsSlice[] => {
const candidateSlices = slices.slice()
// early return if no languages have been specified // early return if no languages have been specified
if (!preferredLangsCode2.length || preferredLangsCode2.length === 0) { if (!preferredLangsCode2.length || preferredLangsCode2.length === 0) {
return slices return slices
@ -357,11 +360,18 @@ export class FeedTuner {
// if item does not fit preferred language, remove it // if item does not fit preferred language, remove it
if (!hasPreferredLang) { if (!hasPreferredLang) {
slices.splice(i, 1) candidateSlices.splice(i, 1)
} }
} }
// 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 slices
} }
return candidateSlices
}
} }
} }