diff options
Diffstat (limited to 'src/state')
-rw-r--r-- | src/state/models/feed-view.ts | 4 | ||||
-rw-r--r-- | src/state/models/root-store.ts | 6 | ||||
-rw-r--r-- | src/state/models/ui/preferences.ts | 39 |
3 files changed, 48 insertions, 1 deletions
diff --git a/src/state/models/feed-view.ts b/src/state/models/feed-view.ts index e40539d5d..954c19a8d 100644 --- a/src/state/models/feed-view.ts +++ b/src/state/models/feed-view.ts @@ -341,7 +341,9 @@ export class FeedModel { return [ FeedTuner.dedupReposts, FeedTuner.likedRepliesOnly, - FeedTuner.englishOnly, + FeedTuner.preferredLangOnly( + this.rootStore.preferences.contentLanguages, + ), ] } if (this.feedType === 'home') { diff --git a/src/state/models/root-store.ts b/src/state/models/root-store.ts index 4a8d09b41..d8336d005 100644 --- a/src/state/models/root-store.ts +++ b/src/state/models/root-store.ts @@ -16,6 +16,7 @@ import {ProfilesViewModel} from './profiles-view' import {LinkMetasCache} from './cache/link-metas' import {NotificationsViewItemModel} from './notifications-view' import {MeModel} from './me' +import {PreferencesModel} from './ui/preferences' import {resetToTab} from '../../Navigation' import {ImageSizesCache} from './cache/image-sizes' @@ -33,6 +34,7 @@ export class RootStoreModel { log = new LogModel() session = new SessionModel(this) shell = new ShellUiModel(this) + preferences = new PreferencesModel() me = new MeModel(this) profiles = new ProfilesViewModel(this) linkMetas = new LinkMetasCache(this) @@ -83,6 +85,7 @@ export class RootStoreModel { session: this.session.serialize(), me: this.me.serialize(), shell: this.shell.serialize(), + preferences: this.preferences.serialize(), } } @@ -103,6 +106,9 @@ export class RootStoreModel { if (hasProp(v, 'shell')) { this.shell.hydrate(v.shell) } + if (hasProp(v, 'preferences')) { + this.preferences.hydrate(v.preferences) + } } } diff --git a/src/state/models/ui/preferences.ts b/src/state/models/ui/preferences.ts new file mode 100644 index 000000000..bffb2d89b --- /dev/null +++ b/src/state/models/ui/preferences.ts @@ -0,0 +1,39 @@ +import {makeAutoObservable} from 'mobx' +import {getLocales} from 'expo-localization' +import {isObj, hasProp} from 'lib/type-guards' + +const deviceLocales = getLocales() + +export class PreferencesModel { + _contentLanguages: string[] | undefined + + constructor() { + makeAutoObservable(this, {}, {autoBind: true}) + } + + // gives an array of BCP 47 language tags without region codes + get contentLanguages() { + if (this._contentLanguages) { + return this._contentLanguages + } + return deviceLocales.map(locale => locale.languageCode) + } + + serialize() { + return { + contentLanguages: this._contentLanguages, + } + } + + hydrate(v: unknown) { + if (isObj(v)) { + if ( + hasProp(v, 'contentLanguages') && + Array.isArray(v.contentLanguages) && + typeof v.contentLanguages.every(item => typeof item === 'string') + ) { + this._contentLanguages = v.contentLanguages + } + } + } +} |