Override mod prefs
This commit is contained in:
@@ -0,0 +1,11 @@
|
|||||||
|
import {type ModerationPrefs} from '@atproto/api'
|
||||||
|
|
||||||
|
import {DEFAULT_LOGGED_OUT_LABEL_PREFERENCES} from '#/state/queries/preferences/moderation'
|
||||||
|
|
||||||
|
export const AGE_RESTRICTED_MODERATION_PREFS: ModerationPrefs = {
|
||||||
|
adultContentEnabled: false,
|
||||||
|
labels: DEFAULT_LOGGED_OUT_LABEL_PREFERENCES,
|
||||||
|
labelers: [],
|
||||||
|
mutedWords: [],
|
||||||
|
hiddenPosts: [],
|
||||||
|
}
|
||||||
@@ -1,8 +1,5 @@
|
|||||||
import {createContext, useContext, useMemo} from 'react'
|
import {createContext, useContext, useMemo} from 'react'
|
||||||
import {
|
import {useQuery, useQueryClient} from '@tanstack/react-query'
|
||||||
// useQueryClient,
|
|
||||||
useQuery,
|
|
||||||
} from '@tanstack/react-query'
|
|
||||||
|
|
||||||
import {wait} from '#/lib/async/wait'
|
import {wait} from '#/lib/async/wait'
|
||||||
import {isNetworkError} from '#/lib/strings/errors'
|
import {isNetworkError} from '#/lib/strings/errors'
|
||||||
@@ -13,6 +10,7 @@ import {
|
|||||||
type AppBskyUnspeccedDefs,
|
type AppBskyUnspeccedDefs,
|
||||||
} from '#/state/age-assurance/types'
|
} from '#/state/age-assurance/types'
|
||||||
import {useGeolocation} from '#/state/geolocation'
|
import {useGeolocation} from '#/state/geolocation'
|
||||||
|
import {preferencesQueryKey} from '#/state/queries/preferences'
|
||||||
import {useAgent} from '#/state/session'
|
import {useAgent} from '#/state/session'
|
||||||
|
|
||||||
const logger = Logger.create(Logger.Context.AgeAssurance)
|
const logger = Logger.create(Logger.Context.AgeAssurance)
|
||||||
@@ -35,7 +33,7 @@ const AgeAssuranceAPIContext = createContext<AgeAssuranceAPIContextType>({
|
|||||||
})
|
})
|
||||||
|
|
||||||
export function Provider({children}: {children: React.ReactNode}) {
|
export function Provider({children}: {children: React.ReactNode}) {
|
||||||
// const qc = useQueryClient()
|
const qc = useQueryClient()
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
const {geolocation} = useGeolocation()
|
const {geolocation} = useGeolocation()
|
||||||
|
|
||||||
@@ -59,6 +57,8 @@ export function Provider({children}: {children: React.ReactNode}) {
|
|||||||
account: agent.session?.did,
|
account: agent.session?.did,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
qc.invalidateQueries({queryKey: preferencesQueryKey})
|
||||||
|
|
||||||
return data
|
return data
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!isNetworkError(e)) {
|
if (!isNetworkError(e)) {
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import {useCallback} from 'react'
|
||||||
|
import {type ModerationPrefs} from '@atproto/api'
|
||||||
|
|
||||||
|
import {useAgeAssuranceContext} from '#/state/age-assurance'
|
||||||
|
import {AGE_RESTRICTED_MODERATION_PREFS} from '#/state/age-assurance/const'
|
||||||
|
|
||||||
|
export function useMaybeApplyAgeRestrictedModerationPrefs() {
|
||||||
|
const {isLoaded, isAgeRestricted, isExempt} = useAgeAssuranceContext()
|
||||||
|
return useCallback(
|
||||||
|
(prev: ModerationPrefs) => {
|
||||||
|
const isDefinitelyAgeRestricted = isLoaded && isAgeRestricted
|
||||||
|
const notSureYet = !isLoaded && isAgeRestricted
|
||||||
|
|
||||||
|
if (isExempt) return prev
|
||||||
|
if (notSureYet || isDefinitelyAgeRestricted)
|
||||||
|
return AGE_RESTRICTED_MODERATION_PREFS
|
||||||
|
return prev
|
||||||
|
},
|
||||||
|
[isLoaded, isAgeRestricted, isExempt],
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ import {PROD_DEFAULT_FEED} from '#/lib/constants'
|
|||||||
import {replaceEqualDeep} from '#/lib/functions'
|
import {replaceEqualDeep} from '#/lib/functions'
|
||||||
import {getAge} from '#/lib/strings/time'
|
import {getAge} from '#/lib/strings/time'
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
|
import {useMaybeApplyAgeRestrictedModerationPrefs} from '#/state/age-assurance/useMaybeApplyAgeRestrictedModerationPrefs'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
import {
|
import {
|
||||||
DEFAULT_HOME_FEED_PREFS,
|
DEFAULT_HOME_FEED_PREFS,
|
||||||
@@ -31,7 +32,8 @@ export const preferencesQueryKey = [preferencesQueryKeyRoot]
|
|||||||
|
|
||||||
export function usePreferencesQuery() {
|
export function usePreferencesQuery() {
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
return useQuery({
|
const overrideModPrefs = useMaybeApplyAgeRestrictedModerationPrefs()
|
||||||
|
const query = useQuery({
|
||||||
staleTime: STALE.SECONDS.FIFTEEN,
|
staleTime: STALE.SECONDS.FIFTEEN,
|
||||||
structuralSharing: replaceEqualDeep,
|
structuralSharing: replaceEqualDeep,
|
||||||
refetchOnWindowFocus: true,
|
refetchOnWindowFocus: true,
|
||||||
@@ -69,6 +71,12 @@ export function usePreferencesQuery() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (query.data) {
|
||||||
|
query.data.moderationPrefs = overrideModPrefs(query.data.moderationPrefs)
|
||||||
|
}
|
||||||
|
|
||||||
|
return query
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useClearPreferencesMutation() {
|
export function useClearPreferencesMutation() {
|
||||||
|
|||||||
Reference in New Issue
Block a user