Refactor age assurance flags and contexts (#10794)
This commit is contained in:
@@ -13,7 +13,7 @@ jest.mock('jwt-decode', () => ({
|
||||
jest.mock('../../birthdate')
|
||||
jest.mock('../../../ageAssurance/data')
|
||||
jest.mock('../../../ageAssurance/state', () => ({
|
||||
getAndComputeAgeAssuranceState: () => ({}),
|
||||
unsafeGetAndComputeAgeAssurance: () => ({state: {}}),
|
||||
}))
|
||||
jest.mock('#/lib/notifications/notifications', () => ({
|
||||
unregisterPushToken(_agents: BskyAgent[]) {
|
||||
|
||||
@@ -24,11 +24,11 @@ import {snoozeBirthdateUpdateAllowedForDid} from '#/state/birthdate'
|
||||
import {restrictChatSettings} from '#/state/queries/messages/restrictChatSettings'
|
||||
import {snoozeEmailConfirmationPrompt} from '#/state/shell/reminders'
|
||||
import {
|
||||
prefetchAgeAssuranceData,
|
||||
prefetchAgeAssuranceServerData,
|
||||
setBirthdateForDid,
|
||||
setCreatedAtForDid,
|
||||
} from '#/ageAssurance/data'
|
||||
import {getAndComputeAgeAssuranceState} from '#/ageAssurance/state'
|
||||
import {unsafeGetAndComputeAgeAssurance} from '#/ageAssurance/state'
|
||||
import {AgeAssuranceAccess} from '#/ageAssurance/types'
|
||||
import {features} from '#/analytics'
|
||||
import {emitNetworkConfirmed, emitNetworkLost} from '../events'
|
||||
@@ -74,7 +74,7 @@ export async function createAgentAndResume(
|
||||
}
|
||||
|
||||
// after session is attached
|
||||
const aa = prefetchAgeAssuranceData({agent})
|
||||
const aa = prefetchAgeAssuranceServerData({agent})
|
||||
|
||||
agent.configureProxy(BLUESKY_PROXY_HEADER.get())
|
||||
|
||||
@@ -113,7 +113,7 @@ export async function createAgentAndLogin(
|
||||
const account = agentToSessionAccountOrThrow(agent)
|
||||
const gates = features.refresh({strategy: 'prefer-fresh-gates'})
|
||||
const moderation = configureModerationForAccount(agent, account)
|
||||
const aa = prefetchAgeAssuranceData({agent})
|
||||
const aa = prefetchAgeAssuranceServerData({agent})
|
||||
|
||||
agent.configureProxy(BLUESKY_PROXY_HEADER.get())
|
||||
|
||||
@@ -175,7 +175,7 @@ export async function createAgentAndCreateAccount(
|
||||
setBirthdateForDid({did: account.did, birthdate})
|
||||
snoozeBirthdateUpdateAllowedForDid(account.did)
|
||||
// do this last
|
||||
const aa = prefetchAgeAssuranceData({agent})
|
||||
const aa = prefetchAgeAssuranceServerData({agent})
|
||||
|
||||
// Not awaited so that we can still get into onboarding.
|
||||
// This is OK because we won't let you toggle adult stuff until you set the date.
|
||||
@@ -219,7 +219,7 @@ export async function createAgentAndCreateAccount(
|
||||
}),
|
||||
// wait for AA data to load first, then check state
|
||||
aa.then(async () => {
|
||||
const state = getAndComputeAgeAssuranceState({did: account.did})
|
||||
const {state} = unsafeGetAndComputeAgeAssurance({did: account.did})
|
||||
if (state.access !== AgeAssuranceAccess.Full) {
|
||||
restrictChatSettings({agent, did: account.did})
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ import {
|
||||
} from '#/state/session/types'
|
||||
import {useOnboardingDispatch} from '#/state/shell/onboarding'
|
||||
import {
|
||||
clearAgeAssuranceData,
|
||||
clearAgeAssuranceDataForDid,
|
||||
clearAgeAssuranceServerDataForAll,
|
||||
clearAgeAssuranceServerDataForDid,
|
||||
} from '#/ageAssurance/data'
|
||||
|
||||
const StateContext = createContext<SessionStateContext>({
|
||||
@@ -203,7 +203,9 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
)
|
||||
addSessionDebugLog({type: 'method:end', method: 'logout'})
|
||||
if (prevState.currentAgentState.did) {
|
||||
clearAgeAssuranceDataForDid({did: prevState.currentAgentState.did})
|
||||
clearAgeAssuranceServerDataForDid({
|
||||
did: prevState.currentAgentState.did,
|
||||
})
|
||||
void clearPersistedQueryStorage(prevState.currentAgentState.did)
|
||||
}
|
||||
// reset onboarding flow on logout
|
||||
@@ -234,7 +236,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
},
|
||||
)
|
||||
addSessionDebugLog({type: 'method:end', method: 'logout'})
|
||||
clearAgeAssuranceData()
|
||||
clearAgeAssuranceServerDataForAll()
|
||||
for (const account of prevState.accounts) {
|
||||
void clearPersistedQueryStorage(account.did)
|
||||
}
|
||||
@@ -304,7 +306,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
accountDid: account.did,
|
||||
})
|
||||
addSessionDebugLog({type: 'method:end', method: 'removeAccount', account})
|
||||
clearAgeAssuranceDataForDid({did: account.did})
|
||||
clearAgeAssuranceServerDataForDid({did: account.did})
|
||||
},
|
||||
[store, cancelPendingTask],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user