Use single restrictChatSettings util, use new flags
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import {createContext, useCallback, useContext, useMemo} from 'react'
|
import {createContext, useCallback, useContext, useMemo} from 'react'
|
||||||
|
|
||||||
import {useGetAndRegisterPushToken} from '#/lib/notifications/notifications'
|
import {useGetAndRegisterPushToken} from '#/lib/notifications/notifications'
|
||||||
|
import {restrictChatSettings} from '#/state/queries/messages/restrictChatSettings'
|
||||||
import {useAgent} from '#/state/session'
|
import {useAgent} from '#/state/session'
|
||||||
import {Provider as RedirectOverlayProvider} from '#/ageAssurance/components/RedirectOverlay'
|
import {Provider as RedirectOverlayProvider} from '#/ageAssurance/components/RedirectOverlay'
|
||||||
import {
|
import {
|
||||||
@@ -20,7 +21,6 @@ import {
|
|||||||
} from '#/ageAssurance/types'
|
} from '#/ageAssurance/types'
|
||||||
import {
|
import {
|
||||||
computeAgeAssuranceFlags,
|
computeAgeAssuranceFlags,
|
||||||
maybeRestrictChatSettings,
|
|
||||||
useAgeAssuranceRegionConfigWithFallback,
|
useAgeAssuranceRegionConfigWithFallback,
|
||||||
} from '#/ageAssurance/util'
|
} from '#/ageAssurance/util'
|
||||||
|
|
||||||
@@ -48,8 +48,10 @@ const AgeAssuranceStateContext = createContext<{
|
|||||||
access: AgeAssuranceAccess.Full,
|
access: AgeAssuranceAccess.Full,
|
||||||
},
|
},
|
||||||
flags: {
|
flags: {
|
||||||
|
isAgeRestricted: false,
|
||||||
adultContentDisabled: false,
|
adultContentDisabled: false,
|
||||||
chatDisabled: false,
|
chatDisabled: false,
|
||||||
|
groupChatDisabled: false,
|
||||||
isDeclaredUnderAdultAge: false,
|
isDeclaredUnderAdultAge: false,
|
||||||
isOverRegionMinAccessAge: false,
|
isOverRegionMinAccessAge: false,
|
||||||
isOverAppMinAccessAge: false,
|
isOverAppMinAccessAge: false,
|
||||||
@@ -84,13 +86,25 @@ function InnerProvider({children}: {children: React.ReactNode}) {
|
|||||||
|
|
||||||
const handleAccessUpdate = useCallback(
|
const handleAccessUpdate = useCallback(
|
||||||
(s: AgeAssuranceState) => {
|
(s: AgeAssuranceState) => {
|
||||||
const isAgeRestricted = s.access !== AgeAssuranceAccess.Full
|
const flags = computeAgeAssuranceFlags({
|
||||||
if (isAgeRestricted) {
|
state: s,
|
||||||
void getAndRegisterPushToken({isAgeRestricted})
|
regionConfig,
|
||||||
void maybeRestrictChatSettings({agent})
|
metadata,
|
||||||
|
})
|
||||||
|
if (flags.isAgeRestricted) {
|
||||||
|
void getAndRegisterPushToken({
|
||||||
|
isAgeRestricted: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (flags.chatDisabled || flags.groupChatDisabled) {
|
||||||
|
void restrictChatSettings({
|
||||||
|
agent,
|
||||||
|
restrictIncoming: flags.chatDisabled,
|
||||||
|
restrictGroupInvites: flags.groupChatDisabled,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[agent, getAndRegisterPushToken],
|
[agent, getAndRegisterPushToken, regionConfig, metadata],
|
||||||
)
|
)
|
||||||
useOnAgeAssuranceAccessUpdate(handleAccessUpdate)
|
useOnAgeAssuranceAccessUpdate(handleAccessUpdate)
|
||||||
|
|
||||||
|
|||||||
@@ -30,8 +30,10 @@ export type AgeAssuranceState = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type AgeAssuranceFlags = {
|
export type AgeAssuranceFlags = {
|
||||||
|
isAgeRestricted: boolean
|
||||||
adultContentDisabled: boolean
|
adultContentDisabled: boolean
|
||||||
chatDisabled: boolean
|
chatDisabled: boolean
|
||||||
|
groupChatDisabled: boolean
|
||||||
isDeclaredUnderAdultAge: boolean
|
isDeclaredUnderAdultAge: boolean
|
||||||
isOverRegionMinAccessAge: boolean
|
isOverRegionMinAccessAge: boolean
|
||||||
isOverAppMinAccessAge: boolean
|
isOverAppMinAccessAge: boolean
|
||||||
|
|||||||
@@ -2,19 +2,13 @@ import {useMemo} from 'react'
|
|||||||
import {
|
import {
|
||||||
ageAssuranceRuleIDs as ids,
|
ageAssuranceRuleIDs as ids,
|
||||||
type AppBskyAgeassuranceDefs,
|
type AppBskyAgeassuranceDefs,
|
||||||
type AtpAgent,
|
|
||||||
getAgeAssuranceRegionConfig,
|
getAgeAssuranceRegionConfig,
|
||||||
type ModerationPrefs,
|
type ModerationPrefs,
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
|
|
||||||
import {getAge} from '#/lib/strings/time'
|
import {getAge} from '#/lib/strings/time'
|
||||||
import {restrictChatSettings} from '#/state/queries/messages/restrictChatSettings'
|
|
||||||
import {DEFAULT_LOGGED_OUT_LABEL_PREFERENCES} from '#/state/queries/preferences/moderation'
|
import {DEFAULT_LOGGED_OUT_LABEL_PREFERENCES} from '#/state/queries/preferences/moderation'
|
||||||
import {
|
import {useAgeAssuranceServerDataContext} from '#/ageAssurance/data'
|
||||||
getDidFromAgentSession,
|
|
||||||
getOtherRequiredDataFromCache,
|
|
||||||
useAgeAssuranceServerDataContext,
|
|
||||||
} from '#/ageAssurance/data'
|
|
||||||
import {
|
import {
|
||||||
AgeAssuranceAccess,
|
AgeAssuranceAccess,
|
||||||
type AgeAssuranceFlags,
|
type AgeAssuranceFlags,
|
||||||
@@ -121,19 +115,6 @@ export const makeAgeRestrictedModerationPrefs = (
|
|||||||
labels: DEFAULT_LOGGED_OUT_LABEL_PREFERENCES,
|
labels: DEFAULT_LOGGED_OUT_LABEL_PREFERENCES,
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks our cache of the actor's chat declaration record, and if it's not
|
|
||||||
* already restricted, restricts it.
|
|
||||||
*/
|
|
||||||
export function maybeRestrictChatSettings({agent}: {agent: AtpAgent}) {
|
|
||||||
const did = getDidFromAgentSession(agent)
|
|
||||||
if (!did) return
|
|
||||||
const data = getOtherRequiredDataFromCache({did})
|
|
||||||
// ...update the chat setting record if allowIncoming is not already 'none'.
|
|
||||||
if (data?.actorDeclaration?.allowIncoming === 'none') return
|
|
||||||
restrictChatSettings({agent, did})
|
|
||||||
}
|
|
||||||
|
|
||||||
export function computeAgeAssuranceFlags({
|
export function computeAgeAssuranceFlags({
|
||||||
state,
|
state,
|
||||||
regionConfig,
|
regionConfig,
|
||||||
@@ -143,10 +124,12 @@ export function computeAgeAssuranceFlags({
|
|||||||
regionConfig: AppBskyAgeassuranceDefs.ConfigRegion
|
regionConfig: AppBskyAgeassuranceDefs.ConfigRegion
|
||||||
metadata?: AgeAssuranceMetadata
|
metadata?: AgeAssuranceMetadata
|
||||||
}): AgeAssuranceFlags {
|
}): AgeAssuranceFlags {
|
||||||
const chatDisabled = state.access !== AgeAssuranceAccess.Full
|
const isAgeRestricted = state.access !== AgeAssuranceAccess.Full
|
||||||
|
const chatDisabled = isAgeRestricted
|
||||||
const isDeclaredUnderAdultAge = metadata?.declaredAge
|
const isDeclaredUnderAdultAge = metadata?.declaredAge
|
||||||
? metadata.declaredAge < 18
|
? metadata.declaredAge < 18
|
||||||
: true
|
: true
|
||||||
|
const groupChatDisabled = chatDisabled || isDeclaredUnderAdultAge
|
||||||
const isOverRegionMinAccessAge = metadata?.declaredAge
|
const isOverRegionMinAccessAge = metadata?.declaredAge
|
||||||
? metadata.declaredAge >= regionConfig.minAccessAge
|
? metadata.declaredAge >= regionConfig.minAccessAge
|
||||||
: false
|
: false
|
||||||
@@ -157,8 +140,10 @@ export function computeAgeAssuranceFlags({
|
|||||||
state.access !== AgeAssuranceAccess.Full || isDeclaredUnderAdultAge
|
state.access !== AgeAssuranceAccess.Full || isDeclaredUnderAdultAge
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
isAgeRestricted,
|
||||||
adultContentDisabled,
|
adultContentDisabled,
|
||||||
chatDisabled,
|
chatDisabled,
|
||||||
|
groupChatDisabled,
|
||||||
isDeclaredUnderAdultAge,
|
isDeclaredUnderAdultAge,
|
||||||
isOverRegionMinAccessAge,
|
isOverRegionMinAccessAge,
|
||||||
isOverAppMinAccessAge,
|
isOverAppMinAccessAge,
|
||||||
|
|||||||
@@ -335,7 +335,7 @@ export function InitiateChatFlow({
|
|||||||
if (
|
if (
|
||||||
chatState === ChatState.NEW_CHAT &&
|
chatState === ChatState.NEW_CHAT &&
|
||||||
searchText === '' &&
|
searchText === '' &&
|
||||||
!aa.flags.isDeclaredUnderAdultAge
|
!aa.flags.groupChatDisabled
|
||||||
) {
|
) {
|
||||||
_items.unshift({type: 'newGroupChat', key: 'newGroupChat'})
|
_items.unshift({type: 'newGroupChat', key: 'newGroupChat'})
|
||||||
}
|
}
|
||||||
@@ -350,7 +350,7 @@ export function InitiateChatFlow({
|
|||||||
results,
|
results,
|
||||||
currentAccount?.did,
|
currentAccount?.did,
|
||||||
follows,
|
follows,
|
||||||
aa.flags.isDeclaredUnderAdultAge,
|
aa.flags.groupChatDisabled,
|
||||||
])
|
])
|
||||||
|
|
||||||
if (searchText && !isFetching && !items.length && !isError) {
|
if (searchText && !isFetching && !items.length && !isError) {
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ export function ChatList({
|
|||||||
|
|
||||||
const {refetch: refetchInbox} = useListConvosQuery({
|
const {refetch: refetchInbox} = useListConvosQuery({
|
||||||
status: 'request',
|
status: 'request',
|
||||||
kind: aa.flags.isDeclaredUnderAdultAge ? 'direct' : 'all',
|
kind: aa.flags.groupChatDisabled ? 'direct' : 'all',
|
||||||
})
|
})
|
||||||
|
|
||||||
useRefreshOnFocus(refetch)
|
useRefreshOnFocus(refetch)
|
||||||
@@ -465,7 +465,7 @@ export function Header({
|
|||||||
useListConvosQuery({
|
useListConvosQuery({
|
||||||
status: 'request',
|
status: 'request',
|
||||||
readState: 'unread',
|
readState: 'unread',
|
||||||
kind: aa.flags.isDeclaredUnderAdultAge ? 'direct' : 'all',
|
kind: aa.flags.groupChatDisabled ? 'direct' : 'all',
|
||||||
})
|
})
|
||||||
|
|
||||||
const inboxAllConvos =
|
const inboxAllConvos =
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import {ChevronRight_Stroke2_Corner0_Rounded as ChevronRightIcon} from '#/compon
|
|||||||
import * as Layout from '#/components/Layout'
|
import * as Layout from '#/components/Layout'
|
||||||
import * as Toast from '#/components/Toast'
|
import * as Toast from '#/components/Toast'
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
|
import {useAgeAssurance} from '#/ageAssurance'
|
||||||
import {useAnalytics} from '#/analytics'
|
import {useAnalytics} from '#/analytics'
|
||||||
import {IS_NATIVE} from '#/env'
|
import {IS_NATIVE} from '#/env'
|
||||||
import {useBackgroundNotificationPreferences} from '../../../modules/expo-background-notification-handler/src/BackgroundNotificationHandlerProvider'
|
import {useBackgroundNotificationPreferences} from '../../../modules/expo-background-notification-handler/src/BackgroundNotificationHandlerProvider'
|
||||||
@@ -46,6 +47,7 @@ export function MessagesSettingsScreenInner({}: Props) {
|
|||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {t: l} = useLingui()
|
const {t: l} = useLingui()
|
||||||
const ax = useAnalytics()
|
const ax = useAnalytics()
|
||||||
|
const aa = useAgeAssurance()
|
||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const {data: profile} = useProfileQuery({
|
const {data: profile} = useProfileQuery({
|
||||||
did: currentAccount!.did,
|
did: currentAccount!.did,
|
||||||
@@ -55,6 +57,7 @@ export function MessagesSettingsScreenInner({}: Props) {
|
|||||||
const exportCarControl = Dialog.useDialogControl()
|
const exportCarControl = Dialog.useDialogControl()
|
||||||
|
|
||||||
const isGroupChatEnabled = ax.features.enabled(ax.features.GroupChatsEnable)
|
const isGroupChatEnabled = ax.features.enabled(ax.features.GroupChatsEnable)
|
||||||
|
const groupInvitesLocked = aa.flags.groupChatDisabled
|
||||||
|
|
||||||
const allowMessagesFromOptions: {name: AllowIncoming; label: string}[] = [
|
const allowMessagesFromOptions: {name: AllowIncoming; label: string}[] = [
|
||||||
{
|
{
|
||||||
@@ -192,15 +195,26 @@ export function MessagesSettingsScreenInner({}: Props) {
|
|||||||
a.leading_snug,
|
a.leading_snug,
|
||||||
t.atoms.text_contrast_high,
|
t.atoms.text_contrast_high,
|
||||||
]}>
|
]}>
|
||||||
<Trans>
|
{groupInvitesLocked ? (
|
||||||
You can continue ongoing conversations regardless of which
|
<Trans>
|
||||||
setting you choose.
|
Group chats are only available to users 18 and over.
|
||||||
</Trans>
|
</Trans>
|
||||||
|
) : (
|
||||||
|
<Trans>
|
||||||
|
You can continue ongoing conversations regardless of which
|
||||||
|
setting you choose.
|
||||||
|
</Trans>
|
||||||
|
)}
|
||||||
</Text>
|
</Text>
|
||||||
<Toggle.Group
|
<Toggle.Group
|
||||||
|
disabled={groupInvitesLocked}
|
||||||
label={l`Allow group chat invites from`}
|
label={l`Allow group chat invites from`}
|
||||||
type="radio"
|
type="radio"
|
||||||
values={[resolveAllowGroupInvites(profile?.associated?.chat)]}
|
values={[
|
||||||
|
groupInvitesLocked
|
||||||
|
? 'none'
|
||||||
|
: resolveAllowGroupInvites(profile?.associated?.chat),
|
||||||
|
]}
|
||||||
onChange={onSelectGroupInvitesFrom}>
|
onChange={onSelectGroupInvitesFrom}>
|
||||||
<View>
|
<View>
|
||||||
{allowGroupInvitesFromOptions.map(option => (
|
{allowGroupInvitesFromOptions.map(option => (
|
||||||
|
|||||||
@@ -67,15 +67,11 @@ export function useBirthdateMutation() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (isUnderAge(birthDate.toISOString(), 18)) {
|
if (isUnderAge(birthDate.toISOString(), 18)) {
|
||||||
const did = agent.sessionManager.did
|
await restrictChatSettings({
|
||||||
if (did) {
|
agent,
|
||||||
await restrictChatSettings({
|
restrictIncoming: true,
|
||||||
agent,
|
restrictGroupInvites: true,
|
||||||
did,
|
})
|
||||||
restrictIncoming: true,
|
|
||||||
restrictGroupInvites: true,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ export function ListConvosProviderInner({
|
|||||||
readState: 'unread',
|
readState: 'unread',
|
||||||
limit: UNREAD_LIMIT,
|
limit: UNREAD_LIMIT,
|
||||||
lockStatus: 'unlocked',
|
lockStatus: 'unlocked',
|
||||||
kind: aa.flags.isDeclaredUnderAdultAge ? 'direct' : 'all',
|
kind: aa.flags.groupChatDisabled ? 'direct' : 'all',
|
||||||
})
|
})
|
||||||
const messagesBus = useMessagesEventBus()
|
const messagesBus = useMessagesEventBus()
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {type ChatBskyActorDeclaration} from '@atproto/api'
|
|||||||
import {networkRetry} from '#/lib/async/retry'
|
import {networkRetry} from '#/lib/async/retry'
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {
|
import {
|
||||||
|
getDidFromAgentSession,
|
||||||
getOtherRequiredDataFromCache,
|
getOtherRequiredDataFromCache,
|
||||||
setOtherRequiredDataActorDeclarationCache,
|
setOtherRequiredDataActorDeclarationCache,
|
||||||
} from '#/ageAssurance/data'
|
} from '#/ageAssurance/data'
|
||||||
@@ -24,15 +25,16 @@ import {
|
|||||||
*/
|
*/
|
||||||
export async function restrictChatSettings({
|
export async function restrictChatSettings({
|
||||||
agent,
|
agent,
|
||||||
did,
|
|
||||||
restrictIncoming = false,
|
restrictIncoming = false,
|
||||||
restrictGroupInvites = false,
|
restrictGroupInvites = false,
|
||||||
}: {
|
}: {
|
||||||
agent: AtpAgent
|
agent: AtpAgent
|
||||||
did: string
|
|
||||||
restrictIncoming?: boolean
|
restrictIncoming?: boolean
|
||||||
restrictGroupInvites?: boolean
|
restrictGroupInvites?: boolean
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
|
const did = getDidFromAgentSession(agent)
|
||||||
|
if (!did) return
|
||||||
|
|
||||||
const cached = getOtherRequiredDataFromCache({did})?.actorDeclaration
|
const cached = getOtherRequiredDataFromCache({did})?.actorDeclaration
|
||||||
|
|
||||||
// When the cache is empty we fall back to defaults for any dimension we're
|
// When the cache is empty we fall back to defaults for any dimension we're
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import {
|
|||||||
setCreatedAtForDid,
|
setCreatedAtForDid,
|
||||||
} from '#/ageAssurance/data'
|
} from '#/ageAssurance/data'
|
||||||
import {unsafeGetAndComputeAgeAssurance} from '#/ageAssurance/state'
|
import {unsafeGetAndComputeAgeAssurance} from '#/ageAssurance/state'
|
||||||
import {AgeAssuranceAccess} from '#/ageAssurance/types'
|
|
||||||
import {features} from '#/analytics'
|
import {features} from '#/analytics'
|
||||||
import {emitNetworkConfirmed, emitNetworkLost} from '../events'
|
import {emitNetworkConfirmed, emitNetworkLost} from '../events'
|
||||||
import {addSessionErrorLog} from './logging'
|
import {addSessionErrorLog} from './logging'
|
||||||
@@ -218,10 +217,14 @@ export async function createAgentAndCreateAccount(
|
|||||||
throw e
|
throw e
|
||||||
}),
|
}),
|
||||||
// wait for AA data to load first, then check state
|
// wait for AA data to load first, then check state
|
||||||
aa.then(async () => {
|
aa.then(() => {
|
||||||
const {state} = unsafeGetAndComputeAgeAssurance({did: account.did})
|
const {flags} = unsafeGetAndComputeAgeAssurance({did: account.did})
|
||||||
if (state.access !== AgeAssuranceAccess.Full) {
|
if (flags?.chatDisabled || flags?.groupChatDisabled) {
|
||||||
restrictChatSettings({agent, did: account.did})
|
void restrictChatSettings({
|
||||||
|
agent,
|
||||||
|
restrictIncoming: flags.chatDisabled,
|
||||||
|
restrictGroupInvites: flags.groupChatDisabled,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
]).then(promises => {
|
]).then(promises => {
|
||||||
|
|||||||
Reference in New Issue
Block a user