Update to use new sdk updates

This commit is contained in:
Paul Frazee
2024-03-07 16:16:53 -08:00
parent b951bacdff
commit 59d5c8ecc0
13 changed files with 35 additions and 32 deletions
@@ -1,6 +1,6 @@
import React from 'react' import React from 'react'
import {View} from 'react-native' import {View} from 'react-native'
import {InterprettedLabelValueDefinition, LabelPreference} from '@atproto/api' import {InterpretedLabelValueDefinition, LabelPreference} from '@atproto/api'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {msg} from '@lingui/macro' import {msg} from '@lingui/macro'
@@ -18,7 +18,7 @@ export function GlobalModerationLabelPref({
labelValueDefinition, labelValueDefinition,
disabled, disabled,
}: { }: {
labelValueDefinition: InterprettedLabelValueDefinition labelValueDefinition: InterpretedLabelValueDefinition
disabled?: boolean disabled?: boolean
}) { }) {
const {_} = useLingui() const {_} = useLingui()
@@ -1,6 +1,6 @@
import React from 'react' import React from 'react'
import {Pressable, View} from 'react-native' import {Pressable, View} from 'react-native'
import {InterprettedLabelValueDefinition, LabelPreference} from '@atproto/api' import {InterpretedLabelValueDefinition, LabelPreference} from '@atproto/api'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {msg, Trans} from '@lingui/macro' import {msg, Trans} from '@lingui/macro'
@@ -27,7 +27,7 @@ export function ModerationLabelPref({
labelerDid, labelerDid,
disabled, disabled,
}: { }: {
labelValueDefinition: InterprettedLabelValueDefinition labelValueDefinition: InterpretedLabelValueDefinition
labelerDid: string | undefined labelerDid: string | undefined
disabled?: boolean disabled?: boolean
}) { }) {
@@ -39,9 +39,8 @@ export function ModerationLabelPref({
const {data: preferences} = usePreferencesQuery() const {data: preferences} = usePreferencesQuery()
const {mutate, variables} = usePreferencesSetContentLabelMutation() const {mutate, variables} = usePreferencesSetContentLabelMutation()
const savedPref = labelerDid const savedPref = labelerDid
? preferences?.moderationPrefs.mods.find(m => m.did === labelerDid)?.labels[ ? preferences?.moderationPrefs.labelers.find(l => l.did === labelerDid)
identifier ?.labels[identifier]
]
: preferences?.moderationPrefs.labels[identifier] : preferences?.moderationPrefs.labels[identifier]
const pref = variables?.visibility ?? savedPref ?? 'warn' const pref = variables?.visibility ?? savedPref ?? 'warn'
+3 -3
View File
@@ -1,7 +1,7 @@
import { import {
ModerationCause, ModerationCause,
ModerationUI, ModerationUI,
InterprettedLabelValueDefinition, InterpretedLabelValueDefinition,
LABELS, LABELS,
} from '@atproto/api' } from '@atproto/api'
@@ -39,8 +39,8 @@ export function getModerationServiceTitle({
export function lookupLabelValueDefinition( export function lookupLabelValueDefinition(
labelValue: string, labelValue: string,
customDefs: InterprettedLabelValueDefinition[] | undefined, customDefs: InterpretedLabelValueDefinition[] | undefined,
): InterprettedLabelValueDefinition | undefined { ): InterpretedLabelValueDefinition | undefined {
let def let def
if (!labelValue.startsWith('!') && customDefs) { if (!labelValue.startsWith('!') && customDefs) {
def = customDefs.find(d => d.identifier === labelValue) def = customDefs.find(d => d.identifier === labelValue)
@@ -1,9 +1,9 @@
import {InterprettedLabelValueDefinition, LabelPreference} from '@atproto/api' import {InterpretedLabelValueDefinition, LabelPreference} from '@atproto/api'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {msg} from '@lingui/macro' import {msg} from '@lingui/macro'
export function useLabelBehaviorDescription( export function useLabelBehaviorDescription(
labelValueDef: InterprettedLabelValueDefinition, labelValueDef: InterpretedLabelValueDefinition,
pref: LabelPreference, pref: LabelPreference,
) { ) {
const {_} = useLingui() const {_} = useLingui()
@@ -39,7 +39,7 @@ export function useLabelBehaviorDescription(
} }
export function useLabelLongBehaviorDescription( export function useLabelLongBehaviorDescription(
labelValueDef: InterprettedLabelValueDefinition, labelValueDef: InterpretedLabelValueDefinition,
pref: LabelPreference, pref: LabelPreference,
) { ) {
const {_} = useLingui() const {_} = useLingui()
+6 -5
View File
@@ -3,7 +3,7 @@ import {
AppBskyLabelerDefs, AppBskyLabelerDefs,
LABELS, LABELS,
interpretLabelValueDefinition, interpretLabelValueDefinition,
InterprettedLabelValueDefinition, InterpretedLabelValueDefinition,
} from '@atproto/api' } from '@atproto/api'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import * as bcp47Match from 'bcp-47-match' import * as bcp47Match from 'bcp-47-match'
@@ -16,7 +16,7 @@ import {useLabelDefinitions} from '#/state/queries/preferences'
export interface LabelInfo { export interface LabelInfo {
label: ComAtprotoLabelDefs.Label label: ComAtprotoLabelDefs.Label
def: InterprettedLabelValueDefinition def: InterpretedLabelValueDefinition
strings: ComAtprotoLabelDefs.LabelValueDefinitionStrings strings: ComAtprotoLabelDefs.LabelValueDefinitionStrings
labeler: AppBskyLabelerDefs.LabelerViewDetailed | undefined labeler: AppBskyLabelerDefs.LabelerViewDetailed | undefined
} }
@@ -35,9 +35,9 @@ export function useLabelInfo(label: ComAtprotoLabelDefs.Label): LabelInfo {
} }
export function getDefinition( export function getDefinition(
labelDefs: Record<string, InterprettedLabelValueDefinition[]>, labelDefs: Record<string, InterpretedLabelValueDefinition[]>,
label: ComAtprotoLabelDefs.Label, label: ComAtprotoLabelDefs.Label,
): InterprettedLabelValueDefinition { ): InterpretedLabelValueDefinition {
// check local definitions // check local definitions
const customDef = const customDef =
!label.val.startsWith('!') && !label.val.startsWith('!') &&
@@ -60,6 +60,7 @@ export function getDefinition(
identifier: label.val, identifier: label.val,
severity: 'none', severity: 'none',
blurs: 'none', blurs: 'none',
defaultSetting: 'ignore',
locales: [], locales: [],
}, },
label.src, label.src,
@@ -69,7 +70,7 @@ export function getDefinition(
export function getLabelStrings( export function getLabelStrings(
locale: string, locale: string,
globalLabelStrings: GlobalLabelStrings, globalLabelStrings: GlobalLabelStrings,
def: InterprettedLabelValueDefinition, def: InterpretedLabelValueDefinition,
): ComAtprotoLabelDefs.LabelValueDefinitionStrings { ): ComAtprotoLabelDefs.LabelValueDefinitionStrings {
if (!def.definedBy) { if (!def.definedBy) {
// global definition, look up strings // global definition, look up strings
+3 -1
View File
@@ -86,7 +86,9 @@ export function ModerationScreen(
data: labelers, data: labelers,
error: labelersError, error: labelersError,
} = useLabelersDetailedInfoQuery({ } = useLabelersDetailedInfoQuery({
dids: preferences ? preferences.moderationPrefs.mods.map(m => m.did) : [], dids: preferences
? preferences.moderationPrefs.labelers.map(l => l.did)
: [],
}) })
const {gtMobile} = useBreakpoints() const {gtMobile} = useBreakpoints()
const {height} = useSafeAreaFrame() const {height} = useSafeAreaFrame()
@@ -1,6 +1,6 @@
import React from 'react' import React from 'react'
import {View} from 'react-native' import {View} from 'react-native'
import {LabelPreference, InterprettedLabelValueDefinition} from '@atproto/api' import {LabelPreference, InterpretedLabelValueDefinition} from '@atproto/api'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {msg} from '@lingui/macro' import {msg} from '@lingui/macro'
import Animated, {Easing, Layout, FadeIn} from 'react-native-reanimated' import Animated, {Easing, Layout, FadeIn} from 'react-native-reanimated'
@@ -18,7 +18,7 @@ export function ModerationOption({
labelValueDefinition, labelValueDefinition,
isMounted, isMounted,
}: { }: {
labelValueDefinition: InterprettedLabelValueDefinition labelValueDefinition: InterpretedLabelValueDefinition
isMounted: React.MutableRefObject<boolean> isMounted: React.MutableRefObject<boolean>
}) { }) {
const {_} = useLingui() const {_} = useLingui()
@@ -75,10 +75,10 @@ let ProfileHeaderLabeler = ({
useLabelerSubscriptionMutation() useLabelerSubscriptionMutation()
const isSubscribed = const isSubscribed =
variables?.subscribe ?? variables?.subscribe ??
preferences?.moderationPrefs.mods.find(mod => mod.did === profile.did) preferences?.moderationPrefs.labelers.find(l => l.did === profile.did)
const canSubscribe = const canSubscribe =
isSubscribed || isSubscribed ||
(preferences ? preferences?.moderationPrefs.mods.length < 10 : false) (preferences ? preferences?.moderationPrefs.labelers.length < 10 : false)
const {mutateAsync: likeMod, isPending: isLikePending} = useLikeMutation() const {mutateAsync: likeMod, isPending: isLikePending} = useLikeMutation()
const {mutateAsync: unlikeMod, isPending: isUnlikePending} = const {mutateAsync: unlikeMod, isPending: isUnlikePending} =
useUnlikeMutation() useUnlikeMutation()
+4 -4
View File
@@ -4,7 +4,7 @@ import {
AppBskyLabelerDefs, AppBskyLabelerDefs,
ModerationOpts, ModerationOpts,
interpretLabelValueDefinitions, interpretLabelValueDefinitions,
InterprettedLabelValueDefinition, InterpretedLabelValueDefinition,
} from '@atproto/api' } from '@atproto/api'
import {Trans, msg} from '@lingui/macro' import {Trans, msg} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
@@ -126,8 +126,8 @@ export function ProfileLabelsSectionInner({
}) })
const {labelValues} = labelerInfo.policies const {labelValues} = labelerInfo.policies
const isSubscribed = moderationOpts.prefs.mods.find( const isSubscribed = moderationOpts.prefs.labelers.find(
mod => mod.did === labelerInfo.creator.did, l => l.did === labelerInfo.creator.did,
) )
const labelDefs = React.useMemo(() => { const labelDefs = React.useMemo(() => {
const customDefs = interpretLabelValueDefinitions(labelerInfo) const customDefs = interpretLabelValueDefinitions(labelerInfo)
@@ -135,7 +135,7 @@ export function ProfileLabelsSectionInner({
.map(val => lookupLabelValueDefinition(val, customDefs)) .map(val => lookupLabelValueDefinition(val, customDefs))
.filter( .filter(
def => def && def?.configurable, def => def && def?.configurable,
) as InterprettedLabelValueDefinition[] ) as InterpretedLabelValueDefinition[]
}, [labelerInfo, labelValues]) }, [labelerInfo, labelValues])
return ( return (
+2 -2
View File
@@ -73,9 +73,9 @@ export function useLabelerSubscriptionMutation() {
}).parse({did, subscribe}) }).parse({did, subscribe})
if (subscribe) { if (subscribe) {
await getAgent().addModService(did) await getAgent().addLabeler(did)
} else { } else {
await getAgent().removeModService(did) await getAgent().removeLabeler(did)
} }
}, },
onSuccess() { onSuccess() {
+1 -1
View File
@@ -37,7 +37,7 @@ export const DEFAULT_LOGGED_OUT_PREFERENCES: UsePreferencesQueryResponse = {
moderationPrefs: { moderationPrefs: {
adultContentEnabled: false, adultContentEnabled: false,
labels: DEFAULT_LOGGED_OUT_LABEL_PREFERENCES, labels: DEFAULT_LOGGED_OUT_LABEL_PREFERENCES,
mods: [], labelers: [],
}, },
feedViewPrefs: DEFAULT_HOME_FEED_PREFS, feedViewPrefs: DEFAULT_HOME_FEED_PREFS,
threadViewPrefs: DEFAULT_THREAD_VIEW_PREFS, threadViewPrefs: DEFAULT_THREAD_VIEW_PREFS,
+1 -1
View File
@@ -17,7 +17,7 @@ export const DEFAULT_LOGGED_OUT_LABEL_PREFERENCES: typeof DEFAULT_LABEL_SETTINGS
export function useMyLabelers() { export function useMyLabelers() {
const prefs = usePreferencesQuery() const prefs = usePreferencesQuery()
const dids = prefs.data?.moderationPrefs.mods.map(m => m.did) || [] const dids = prefs.data?.moderationPrefs.labelers.map(l => l.did) || []
if (!dids.includes(BSKY_LABELER_DID)) { if (!dids.includes(BSKY_LABELER_DID)) {
dids.push(BSKY_LABELER_DID) dids.push(BSKY_LABELER_DID)
} }
+2 -1
View File
@@ -64,6 +64,7 @@ export const DebugModScreen = ({}: NativeStackScreenProps<
identifier: 'custom', identifier: 'custom',
blurs: 'content', blurs: 'content',
severity: 'alert', severity: 'alert',
defaultSetting: 'warn',
locales: [ locales: [
{ {
lang: 'en', lang: 'en',
@@ -235,7 +236,7 @@ export const DebugModScreen = ({}: NativeStackScreenProps<
labels: { labels: {
[label[0]]: visibility[0] as LabelPreference, [label[0]]: visibility[0] as LabelPreference,
}, },
mods: [ labelers: [
{ {
did: 'did:plc:fake-labeler', did: 'did:plc:fake-labeler',
labels: {[label[0]]: visibility[0] as LabelPreference}, labels: {[label[0]]: visibility[0] as LabelPreference},