diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-04-12 18:26:38 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-12 18:26:38 -0700 |
commit | 2fed6c402159c6084dd481ab87c5e8b034e910ac (patch) | |
tree | 5907b2b67c900ef78de89e12ad9ae4c0d5ef6715 /src/state/models/ui/preferences.ts | |
parent | a20d034ba5b18c4512f3a36f733bb5cd2199424e (diff) | |
download | voidsky-2fed6c402159c6084dd481ab87c5e8b034e910ac.tar.zst |
Add first round of labeling tools (#467)
* Rework notifications to sync locally in full and give users better control * Fix positioning of load more btn on web * Improve behavior of load more notifications btn * Fix to post rendering * Fix notification fetch abort condition * Add start of post-hiding by labels * Create a standard postcontainer and improve show/hide UI on posts * Add content hiding to expanded post form * Improve label rendering to give more context to users when appropriate * Fix rendering bug * Add user/profile labeling * Implement content filtering preferences * Filter notifications by content prefs * Update test-pds config * Bump deps
Diffstat (limited to 'src/state/models/ui/preferences.ts')
-rw-r--r-- | src/state/models/ui/preferences.ts | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/state/models/ui/preferences.ts b/src/state/models/ui/preferences.ts index bffb2d89b..5ab5d13fc 100644 --- a/src/state/models/ui/preferences.ts +++ b/src/state/models/ui/preferences.ts @@ -1,11 +1,33 @@ import {makeAutoObservable} from 'mobx' import {getLocales} from 'expo-localization' import {isObj, hasProp} from 'lib/type-guards' +import {ComAtprotoLabelDefs} from '@atproto/api' +import {getLabelValueGroup} from 'lib/labeling/helpers' +import { + LabelValGroup, + UNKNOWN_LABEL_GROUP, + ILLEGAL_LABEL_GROUP, +} from 'lib/labeling/const' const deviceLocales = getLocales() +export type LabelPreference = 'show' | 'warn' | 'hide' + +export class LabelPreferencesModel { + nsfw: LabelPreference = 'warn' + gore: LabelPreference = 'hide' + hate: LabelPreference = 'hide' + spam: LabelPreference = 'hide' + impersonation: LabelPreference = 'warn' + + constructor() { + makeAutoObservable(this, {}, {autoBind: true}) + } +} + export class PreferencesModel { _contentLanguages: string[] | undefined + contentLabels = new LabelPreferencesModel() constructor() { makeAutoObservable(this, {}, {autoBind: true}) @@ -22,6 +44,7 @@ export class PreferencesModel { serialize() { return { contentLanguages: this._contentLanguages, + contentLabels: this.contentLabels, } } @@ -34,6 +57,46 @@ export class PreferencesModel { ) { this._contentLanguages = v.contentLanguages } + if (hasProp(v, 'contentLabels') && typeof v.contentLabels === 'object') { + Object.assign(this.contentLabels, v.contentLabels) + } + } + } + + setContentLabelPref( + key: keyof LabelPreferencesModel, + value: LabelPreference, + ) { + this.contentLabels[key] = value + } + + getLabelPreference(labels: ComAtprotoLabelDefs.Label[] | undefined): { + pref: LabelPreference + desc: LabelValGroup + } { + let res: {pref: LabelPreference; desc: LabelValGroup} = { + pref: 'show', + desc: UNKNOWN_LABEL_GROUP, + } + if (!labels?.length) { + return res + } + for (const label of labels) { + const group = getLabelValueGroup(label.val) + if (group.id === 'illegal') { + return {pref: 'hide', desc: ILLEGAL_LABEL_GROUP} + } else if (group.id === 'unknown') { + continue + } + let pref = this.contentLabels[group.id] + if (pref === 'hide') { + res.pref = 'hide' + res.desc = group + } else if (pref === 'warn' && res.pref === 'show') { + res.pref = 'warn' + res.desc = group + } } + return res } } |