Refactor age assurance flags and contexts (#10794)
This commit is contained in:
@@ -13,9 +13,14 @@ import {DEFAULT_LOGGED_OUT_LABEL_PREFERENCES} from '#/state/queries/preferences/
|
||||
import {
|
||||
getDidFromAgentSession,
|
||||
getOtherRequiredDataFromCache,
|
||||
useAgeAssuranceDataContext,
|
||||
useAgeAssuranceServerDataContext,
|
||||
} from '#/ageAssurance/data'
|
||||
import {AgeAssuranceAccess} from '#/ageAssurance/types'
|
||||
import {
|
||||
AgeAssuranceAccess,
|
||||
type AgeAssuranceFlags,
|
||||
type AgeAssuranceMetadata,
|
||||
type AgeAssuranceState,
|
||||
} from '#/ageAssurance/types'
|
||||
import {type Geolocation, useGeolocation} from '#/geolocation'
|
||||
|
||||
export const MIN_ACCESS_AGE = 13
|
||||
@@ -62,7 +67,7 @@ export function getAgeAssuranceRegionConfigWithFallback(
|
||||
*/
|
||||
export function useAgeAssuranceRegionConfig() {
|
||||
const geolocation = useGeolocation()
|
||||
const {config} = useAgeAssuranceDataContext()
|
||||
const {config} = useAgeAssuranceServerDataContext()
|
||||
return useMemo(() => {
|
||||
if (!config) return
|
||||
// use generic helper, we want to potentially return undefined
|
||||
@@ -128,3 +133,34 @@ export function maybeRestrictChatSettings({agent}: {agent: AtpAgent}) {
|
||||
if (data?.actorDeclaration?.allowIncoming === 'none') return
|
||||
restrictChatSettings({agent, did})
|
||||
}
|
||||
|
||||
export function computeAgeAssuranceFlags({
|
||||
state,
|
||||
regionConfig,
|
||||
metadata,
|
||||
}: {
|
||||
state: AgeAssuranceState
|
||||
regionConfig: AppBskyAgeassuranceDefs.ConfigRegion
|
||||
metadata?: AgeAssuranceMetadata
|
||||
}): AgeAssuranceFlags {
|
||||
const chatDisabled = state.access !== AgeAssuranceAccess.Full
|
||||
const isDeclaredUnderAdultAge = metadata?.declaredAge
|
||||
? metadata.declaredAge < 18
|
||||
: true
|
||||
const isOverRegionMinAccessAge = metadata?.declaredAge
|
||||
? metadata.declaredAge >= regionConfig.minAccessAge
|
||||
: false
|
||||
const isOverAppMinAccessAge = metadata?.declaredAge
|
||||
? metadata.declaredAge >= MIN_ACCESS_AGE
|
||||
: false
|
||||
const adultContentDisabled =
|
||||
state.access !== AgeAssuranceAccess.Full || isDeclaredUnderAdultAge
|
||||
|
||||
return {
|
||||
adultContentDisabled,
|
||||
chatDisabled,
|
||||
isDeclaredUnderAdultAge,
|
||||
isOverRegionMinAccessAge,
|
||||
isOverAppMinAccessAge,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user