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
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) {
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 {
UsePreferencesQueryResponse,
useMyLabelers,
usePreferencesQuery,
usePreferencesSetAdultContentMutation,
} from '#/state/queries/preferences'
import {useLabelersDetailedInfoQuery} from '#/state/queries/labeler'
import {logger} from '#/logger'
import {useTheme, atoms as a, useBreakpoints} from '#/alf'
@@ -86,16 +86,11 @@ export function ModerationScreen(
error: preferencesError,
data: preferences,
} = usePreferencesQuery()
const labelerDids = preferences
? preferences.moderationPrefs.labelers.map(l => l.did)
: []
const {
isLoading: isLabelersLoading,
data: labelers,
error: labelersError,
} = useLabelersDetailedInfoQuery({
dids: labelerDids,
})
} = useMyLabelers()
const {gtMobile} = useBreakpoints()
const {height} = useSafeAreaFrame()
@@ -411,36 +406,10 @@ export function ModerationScreenInner({
<Trans>Advanced</Trans>
</Text>
<View style={[a.rounded_sm, t.atoms.bg_contrast_25]}>
<ModerationServiceCard.Link
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 => {
{labelers.map((mod, i) => {
return (
<React.Fragment key={mod.creator.did}>
<Divider />
{i !== 0 && <Divider />}
<ModerationServiceCard.Link labeler={mod}>
<ModerationServiceCard.Card.Outer>
<ModerationServiceCard.Card.Avatar
+3 -3
View File
@@ -21,7 +21,7 @@ import {
import {FeedCard} from '#/screens/Onboarding/StepAlgoFeeds/FeedCard'
import {aggregateInterestItems} from '#/screens/Onboarding/util'
import {IconCircle} from '#/components/IconCircle'
import {IS_PROD_SERVICE} from 'lib/constants'
import {IS_TEST_USER} from 'lib/constants'
import {useSession} from 'state/session'
export function StepTopicalFeeds() {
@@ -32,14 +32,14 @@ export function StepTopicalFeeds() {
const [selectedFeedUris, setSelectedFeedUris] = React.useState<string[]>([])
const [saving, setSaving] = React.useState(false)
const suggestedFeedUris = React.useMemo(() => {
if (!IS_PROD_SERVICE(currentAccount?.service)) return []
if (IS_TEST_USER(currentAccount?.handle)) return []
return aggregateInterestItems(
state.interestsStepResults.selectedInterests,
state.interestsStepResults.apiResponse.suggestedFeedUris,
state.interestsStepResults.apiResponse.suggestedFeedUris.default || [],
).slice(0, 10)
}, [
currentAccount?.service,
currentAccount?.handle,
state.interestsStepResults.apiResponse.suggestedFeedUris,
state.interestsStepResults.selectedInterests,
])
+4 -5
View File
@@ -1,6 +1,6 @@
import {
DEFAULT_LABEL_SETTINGS,
BSKY_LABELER_DID,
BskyAgent,
interpretLabelValueDefinitions,
} from '@atproto/api'
@@ -17,10 +17,9 @@ export const DEFAULT_LOGGED_OUT_LABEL_PREFERENCES: typeof DEFAULT_LABEL_SETTINGS
export function useMyLabelers() {
const prefs = usePreferencesQuery()
const dids = prefs.data?.moderationPrefs.labelers.map(l => l.did) || []
if (!dids.includes(BSKY_LABELER_DID)) {
dids.push(BSKY_LABELER_DID)
}
const dids = BskyAgent.modAuthoritiesHeader.concat(
prefs.data?.moderationPrefs.labelers.map(l => l.did) || [],
)
const labelers = useLabelersDetailedInfoQuery({dids})
return {
isLoading: prefs.isLoading || labelers.isLoading,
+22 -1
View File
@@ -1,9 +1,14 @@
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 {jwtDecode} from 'jwt-decode'
import {IS_DEV} from '#/env'
import {IS_TEST_USER} from '#/lib/constants'
import {isWeb} from '#/platform/detection'
import {networkRetry} from '#/lib/async/retry'
import {logger} from '#/logger'
@@ -257,6 +262,8 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
deactivated,
}
await configureModeration(agent, account)
agent.setPersistSessionHandler(
createPersistSessionHandler(
account,
@@ -300,6 +307,8 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
deactivated: isSessionDeactivated(agent.session.accessJwt),
}
await configureModeration(agent, account)
agent.setPersistSessionHandler(
createPersistSessionHandler(
account,
@@ -354,6 +363,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
})
// @ts-ignore
if (IS_DEV && isWeb) window.agent = agent
await configureModeration(agent, account)
let canReusePrevSession = false
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() {
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 {useOnboardingDispatch} from '#/state/shell/onboarding'
import {useSessionApi} from '#/state/session'
import {DEFAULT_SERVICE, IS_PROD_SERVICE} from '#/lib/constants'
import {DEFAULT_SERVICE, IS_TEST_USER} from '#/lib/constants'
import {
DEFAULT_PROD_FEEDS,
usePreferencesSetBirthDateMutation,
@@ -147,7 +147,7 @@ export function useSubmitCreateAccount(
: undefined,
})
setBirthDate({birthDate: uiState.birthDate})
if (IS_PROD_SERVICE(uiState.serviceUrl)) {
if (!IS_TEST_USER(uiState.handle)) {
setSavedFeeds(DEFAULT_PROD_FEEDS)
}
} catch (e: any) {