Add test-environment mod authority

This commit is contained in:
Paul Frazee
2024-03-09 13:25:22 -08:00
parent 8862c1f540
commit 185c3d6ee1
6 changed files with 39 additions and 46 deletions
+4
View File
@@ -35,6 +35,10 @@ export const MAX_GRAPHEME_LENGTH = 300
// but increasing limit per user feedback // but increasing limit per user feedback
export const MAX_ALT_TEXT = 1000 export const MAX_ALT_TEXT = 1000
export function IS_TEST_USER(handle?: string) {
return handle && handle?.endsWith('.test')
}
export function IS_PROD_SERVICE(url?: string) { export function IS_PROD_SERVICE(url?: string) {
return url && url !== STAGING_SERVICE && url !== LOCAL_DEV_SERVICE return url && url !== STAGING_SERVICE && url !== LOCAL_DEV_SERVICE
} }
+4 -35
View File
@@ -21,10 +21,10 @@ import {ScrollView} from '#/view/com/util/Views'
import { import {
UsePreferencesQueryResponse, UsePreferencesQueryResponse,
useMyLabelers,
usePreferencesQuery, usePreferencesQuery,
usePreferencesSetAdultContentMutation, usePreferencesSetAdultContentMutation,
} from '#/state/queries/preferences' } from '#/state/queries/preferences'
import {useLabelersDetailedInfoQuery} from '#/state/queries/labeler'
import {logger} from '#/logger' import {logger} from '#/logger'
import {useTheme, atoms as a, useBreakpoints} from '#/alf' import {useTheme, atoms as a, useBreakpoints} from '#/alf'
@@ -86,16 +86,11 @@ export function ModerationScreen(
error: preferencesError, error: preferencesError,
data: preferences, data: preferences,
} = usePreferencesQuery() } = usePreferencesQuery()
const labelerDids = preferences
? preferences.moderationPrefs.labelers.map(l => l.did)
: []
const { const {
isLoading: isLabelersLoading, isLoading: isLabelersLoading,
data: labelers, data: labelers,
error: labelersError, error: labelersError,
} = useLabelersDetailedInfoQuery({ } = useMyLabelers()
dids: labelerDids,
})
const {gtMobile} = useBreakpoints() const {gtMobile} = useBreakpoints()
const {height} = useSafeAreaFrame() const {height} = useSafeAreaFrame()
@@ -411,36 +406,10 @@ export function ModerationScreenInner({
<Trans>Advanced</Trans> <Trans>Advanced</Trans>
</Text> </Text>
<View style={[a.rounded_sm, t.atoms.bg_contrast_25]}> <View style={[a.rounded_sm, t.atoms.bg_contrast_25]}>
<ModerationServiceCard.Link {labelers.map((mod, i) => {
labeler={{
uri: '',
cid: '',
policies: {
labelValues: [],
},
creator: {
did: '',
handle: 'safety.bsky.app',
displayName: 'Bluesky Safety',
},
indexedAt: new Date().toISOString(),
}}>
<ModerationServiceCard.Card.Outer>
<ModerationServiceCard.Card.Avatar avatar={undefined} />
<ModerationServiceCard.Card.Content
title={getModerationServiceTitle({
displayName: 'Bluesky Safety',
handle: 'safety.bsky.app',
})}
handle={'safety.bsky.app'}
description={'Official moderation team'}
/>
</ModerationServiceCard.Card.Outer>
</ModerationServiceCard.Link>
{labelers.map(mod => {
return ( return (
<React.Fragment key={mod.creator.did}> <React.Fragment key={mod.creator.did}>
<Divider /> {i !== 0 && <Divider />}
<ModerationServiceCard.Link labeler={mod}> <ModerationServiceCard.Link labeler={mod}>
<ModerationServiceCard.Card.Outer> <ModerationServiceCard.Card.Outer>
<ModerationServiceCard.Card.Avatar <ModerationServiceCard.Card.Avatar
+3 -3
View File
@@ -21,7 +21,7 @@ import {
import {FeedCard} from '#/screens/Onboarding/StepAlgoFeeds/FeedCard' import {FeedCard} from '#/screens/Onboarding/StepAlgoFeeds/FeedCard'
import {aggregateInterestItems} from '#/screens/Onboarding/util' import {aggregateInterestItems} from '#/screens/Onboarding/util'
import {IconCircle} from '#/components/IconCircle' import {IconCircle} from '#/components/IconCircle'
import {IS_PROD_SERVICE} from 'lib/constants' import {IS_TEST_USER} from 'lib/constants'
import {useSession} from 'state/session' import {useSession} from 'state/session'
export function StepTopicalFeeds() { export function StepTopicalFeeds() {
@@ -32,14 +32,14 @@ export function StepTopicalFeeds() {
const [selectedFeedUris, setSelectedFeedUris] = React.useState<string[]>([]) const [selectedFeedUris, setSelectedFeedUris] = React.useState<string[]>([])
const [saving, setSaving] = React.useState(false) const [saving, setSaving] = React.useState(false)
const suggestedFeedUris = React.useMemo(() => { const suggestedFeedUris = React.useMemo(() => {
if (!IS_PROD_SERVICE(currentAccount?.service)) return [] if (IS_TEST_USER(currentAccount?.handle)) return []
return aggregateInterestItems( return aggregateInterestItems(
state.interestsStepResults.selectedInterests, state.interestsStepResults.selectedInterests,
state.interestsStepResults.apiResponse.suggestedFeedUris, state.interestsStepResults.apiResponse.suggestedFeedUris,
state.interestsStepResults.apiResponse.suggestedFeedUris.default || [], state.interestsStepResults.apiResponse.suggestedFeedUris.default || [],
).slice(0, 10) ).slice(0, 10)
}, [ }, [
currentAccount?.service, currentAccount?.handle,
state.interestsStepResults.apiResponse.suggestedFeedUris, state.interestsStepResults.apiResponse.suggestedFeedUris,
state.interestsStepResults.selectedInterests, state.interestsStepResults.selectedInterests,
]) ])
+4 -5
View File
@@ -1,6 +1,6 @@
import { import {
DEFAULT_LABEL_SETTINGS, DEFAULT_LABEL_SETTINGS,
BSKY_LABELER_DID, BskyAgent,
interpretLabelValueDefinitions, interpretLabelValueDefinitions,
} from '@atproto/api' } from '@atproto/api'
@@ -17,10 +17,9 @@ 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.labelers.map(l => l.did) || [] const dids = BskyAgent.modAuthoritiesHeader.concat(
if (!dids.includes(BSKY_LABELER_DID)) { prefs.data?.moderationPrefs.labelers.map(l => l.did) || [],
dids.push(BSKY_LABELER_DID) )
}
const labelers = useLabelersDetailedInfoQuery({dids}) const labelers = useLabelersDetailedInfoQuery({dids})
return { return {
isLoading: prefs.isLoading || labelers.isLoading, isLoading: prefs.isLoading || labelers.isLoading,
+22 -1
View File
@@ -1,9 +1,14 @@
import React from 'react' import React from 'react'
import {BskyAgent, AtpPersistSessionHandler} from '@atproto/api' import {
BskyAgent,
AtpPersistSessionHandler,
BSKY_LABELER_DID,
} from '@atproto/api'
import {useQueryClient} from '@tanstack/react-query' import {useQueryClient} from '@tanstack/react-query'
import {jwtDecode} from 'jwt-decode' import {jwtDecode} from 'jwt-decode'
import {IS_DEV} from '#/env' import {IS_DEV} from '#/env'
import {IS_TEST_USER} from '#/lib/constants'
import {isWeb} from '#/platform/detection' import {isWeb} from '#/platform/detection'
import {networkRetry} from '#/lib/async/retry' import {networkRetry} from '#/lib/async/retry'
import {logger} from '#/logger' import {logger} from '#/logger'
@@ -257,6 +262,8 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
deactivated, deactivated,
} }
await configureModeration(agent, account)
agent.setPersistSessionHandler( agent.setPersistSessionHandler(
createPersistSessionHandler( createPersistSessionHandler(
account, account,
@@ -300,6 +307,8 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
deactivated: isSessionDeactivated(agent.session.accessJwt), deactivated: isSessionDeactivated(agent.session.accessJwt),
} }
await configureModeration(agent, account)
agent.setPersistSessionHandler( agent.setPersistSessionHandler(
createPersistSessionHandler( createPersistSessionHandler(
account, account,
@@ -354,6 +363,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
}) })
// @ts-ignore // @ts-ignore
if (IS_DEV && isWeb) window.agent = agent if (IS_DEV && isWeb) window.agent = agent
await configureModeration(agent, account)
let canReusePrevSession = false let canReusePrevSession = false
try { try {
@@ -649,6 +659,17 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
) )
} }
async function configureModeration(agent: BskyAgent, account: SessionAccount) {
if (IS_TEST_USER(account.handle)) {
console.warn('USING TEST ENV MODERATION')
const did = (await agent.resolveHandle({handle: 'mod-authority.test'})).data
.did
BskyAgent.configure({modAuthorities: [did]})
} else {
BskyAgent.configure({modAuthorities: [BSKY_LABELER_DID]})
}
}
export function useSession() { export function useSession() {
return React.useContext(StateContext) return React.useContext(StateContext)
} }
+2 -2
View File
@@ -12,7 +12,7 @@ import {createFullHandle, validateHandle} from '#/lib/strings/handles'
import {cleanError} from '#/lib/strings/errors' import {cleanError} from '#/lib/strings/errors'
import {useOnboardingDispatch} from '#/state/shell/onboarding' import {useOnboardingDispatch} from '#/state/shell/onboarding'
import {useSessionApi} from '#/state/session' import {useSessionApi} from '#/state/session'
import {DEFAULT_SERVICE, IS_PROD_SERVICE} from '#/lib/constants' import {DEFAULT_SERVICE, IS_TEST_USER} from '#/lib/constants'
import { import {
DEFAULT_PROD_FEEDS, DEFAULT_PROD_FEEDS,
usePreferencesSetBirthDateMutation, usePreferencesSetBirthDateMutation,
@@ -147,7 +147,7 @@ export function useSubmitCreateAccount(
: undefined, : undefined,
}) })
setBirthDate({birthDate: uiState.birthDate}) setBirthDate({birthDate: uiState.birthDate})
if (IS_PROD_SERVICE(uiState.serviceUrl)) { if (!IS_TEST_USER(uiState.handle)) {
setSavedFeeds(DEFAULT_PROD_FEEDS) setSavedFeeds(DEFAULT_PROD_FEEDS)
} }
} catch (e: any) { } catch (e: any) {