gate group chats for under-18 users
Per the group chats spec, users under 18 cannot be added to or participate in group chats. This wires up the client-side half: - expose isUnder18 flag from the AA context (conservative default when birthdate is unknown) - new restrictGroupChatSettings helper that writes allowGroupInvites: 'none' to the chat actor declaration, called on signup and on birthdate-update when the user is under 18 - hide the 'New group chat' entry in InitiateChatFlow for under-18 users - lock the 'Allow group chat invites from' toggle to 'none' for under-18 in chat settings, with explanatory copy - pass kind: 'direct' to listConvos for under-18 users so groups don't show in the requests inbox or count toward the unread/requests badges
This commit is contained in:
@@ -41,6 +41,7 @@ const AgeAssuranceStateContext = createContext<{
|
|||||||
flags: {
|
flags: {
|
||||||
adultContentDisabled: boolean
|
adultContentDisabled: boolean
|
||||||
chatDisabled: boolean
|
chatDisabled: boolean
|
||||||
|
isUnder18: boolean
|
||||||
isOverRegionMinAccessAge: boolean
|
isOverRegionMinAccessAge: boolean
|
||||||
isOverAppMinAccessAge: boolean
|
isOverAppMinAccessAge: boolean
|
||||||
}
|
}
|
||||||
@@ -55,6 +56,7 @@ const AgeAssuranceStateContext = createContext<{
|
|||||||
flags: {
|
flags: {
|
||||||
adultContentDisabled: false,
|
adultContentDisabled: false,
|
||||||
chatDisabled: false,
|
chatDisabled: false,
|
||||||
|
isUnder18: false,
|
||||||
isOverRegionMinAccessAge: false,
|
isOverRegionMinAccessAge: false,
|
||||||
isOverAppMinAccessAge: false,
|
isOverAppMinAccessAge: false,
|
||||||
},
|
},
|
||||||
@@ -106,7 +108,9 @@ function InnerProvider({children}: {children: React.ReactNode}) {
|
|||||||
<AgeAssuranceStateContext.Provider
|
<AgeAssuranceStateContext.Provider
|
||||||
value={useMemo(() => {
|
value={useMemo(() => {
|
||||||
const chatDisabled = state.access !== AgeAssuranceAccess.Full
|
const chatDisabled = state.access !== AgeAssuranceAccess.Full
|
||||||
const isUnderAdultAge = data?.birthdate
|
// Conservative default: if we don't yet know the birthdate, treat as
|
||||||
|
// under 18 so we don't briefly expose group-chat UI.
|
||||||
|
const isUnder18 = data?.birthdate
|
||||||
? isUnderAge(data.birthdate, 18)
|
? isUnderAge(data.birthdate, 18)
|
||||||
: true
|
: true
|
||||||
const isOverRegionMinAccessAge = data?.birthdate
|
const isOverRegionMinAccessAge = data?.birthdate
|
||||||
@@ -116,7 +120,7 @@ function InnerProvider({children}: {children: React.ReactNode}) {
|
|||||||
? !isUnderAge(data.birthdate, MIN_ACCESS_AGE)
|
? !isUnderAge(data.birthdate, MIN_ACCESS_AGE)
|
||||||
: false
|
: false
|
||||||
const adultContentDisabled =
|
const adultContentDisabled =
|
||||||
state.access !== AgeAssuranceAccess.Full || isUnderAdultAge
|
state.access !== AgeAssuranceAccess.Full || isUnder18
|
||||||
return {
|
return {
|
||||||
Access: AgeAssuranceAccess,
|
Access: AgeAssuranceAccess,
|
||||||
Status: AgeAssuranceStatus,
|
Status: AgeAssuranceStatus,
|
||||||
@@ -124,6 +128,7 @@ function InnerProvider({children}: {children: React.ReactNode}) {
|
|||||||
flags: {
|
flags: {
|
||||||
adultContentDisabled,
|
adultContentDisabled,
|
||||||
chatDisabled,
|
chatDisabled,
|
||||||
|
isUnder18,
|
||||||
isOverRegionMinAccessAge,
|
isOverRegionMinAccessAge,
|
||||||
isOverAppMinAccessAge,
|
isOverAppMinAccessAge,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import {PersonGroup_Stroke2_Corner2_Rounded as PersonGroupIcon} from '#/componen
|
|||||||
import {TimesLarge_Stroke2_Corner0_Rounded as XIcon} from '#/components/icons/Times'
|
import {TimesLarge_Stroke2_Corner0_Rounded as XIcon} from '#/components/icons/Times'
|
||||||
import * as ProfileCard from '#/components/ProfileCard'
|
import * as ProfileCard from '#/components/ProfileCard'
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
|
import {useAgeAssurance} from '#/ageAssurance'
|
||||||
import {IS_NATIVE, IS_WEB} from '#/env'
|
import {IS_NATIVE, IS_WEB} from '#/env'
|
||||||
import type * as bsky from '#/types/bsky'
|
import type * as bsky from '#/types/bsky'
|
||||||
import {ChatProfileTabs} from './ChatProfileTabs'
|
import {ChatProfileTabs} from './ChatProfileTabs'
|
||||||
@@ -205,6 +206,7 @@ export function InitiateChatFlow({
|
|||||||
const [footerHeight, setFooterHeight] = useState(0)
|
const [footerHeight, setFooterHeight] = useState(0)
|
||||||
const listRef = useRef<ListMethods>(null)
|
const listRef = useRef<ListMethods>(null)
|
||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
|
const aa = useAgeAssurance()
|
||||||
const inputRef = useRef<TextInput>(null)
|
const inputRef = useRef<TextInput>(null)
|
||||||
|
|
||||||
const [searchText, setSearchText] = useState('')
|
const [searchText, setSearchText] = useState('')
|
||||||
@@ -320,7 +322,11 @@ export function InitiateChatFlow({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chatState === ChatState.NEW_CHAT && searchText === '') {
|
if (
|
||||||
|
chatState === ChatState.NEW_CHAT &&
|
||||||
|
searchText === '' &&
|
||||||
|
!aa.flags.isUnder18
|
||||||
|
) {
|
||||||
_items.unshift({type: 'newGroupChat', key: 'newGroupChat'})
|
_items.unshift({type: 'newGroupChat', key: 'newGroupChat'})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -334,6 +340,7 @@ export function InitiateChatFlow({
|
|||||||
results,
|
results,
|
||||||
currentAccount?.did,
|
currentAccount?.did,
|
||||||
follows,
|
follows,
|
||||||
|
aa.flags.isUnder18,
|
||||||
])
|
])
|
||||||
|
|
||||||
if (searchText && !isFetching && !items.length && !isError) {
|
if (searchText && !isFetching && !items.length && !isError) {
|
||||||
|
|||||||
@@ -174,6 +174,7 @@ export function ChatList({
|
|||||||
}) {
|
}) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {t: l} = useLingui()
|
const {t: l} = useLingui()
|
||||||
|
const aa = useAgeAssurance()
|
||||||
const scrollElRef: ListRef = useAnimatedRef()
|
const scrollElRef: ListRef = useAnimatedRef()
|
||||||
const {isWithinSplitView} = useIsWithinSplitView()
|
const {isWithinSplitView} = useIsWithinSplitView()
|
||||||
|
|
||||||
@@ -206,6 +207,7 @@ export function ChatList({
|
|||||||
|
|
||||||
const {refetch: refetchInbox} = useListConvosQuery({
|
const {refetch: refetchInbox} = useListConvosQuery({
|
||||||
status: 'request',
|
status: 'request',
|
||||||
|
kind: aa.flags.isUnder18 ? 'direct' : 'all',
|
||||||
})
|
})
|
||||||
|
|
||||||
useRefreshOnFocus(refetch)
|
useRefreshOnFocus(refetch)
|
||||||
@@ -408,6 +410,7 @@ export function ChatList({
|
|||||||
export function Header({newChatControl}: {newChatControl: DialogControlProps}) {
|
export function Header({newChatControl}: {newChatControl: DialogControlProps}) {
|
||||||
const {t: l} = useLingui()
|
const {t: l} = useLingui()
|
||||||
const {gtMobile} = useBreakpoints()
|
const {gtMobile} = useBreakpoints()
|
||||||
|
const aa = useAgeAssurance()
|
||||||
const requireEmailVerification = useRequireEmailVerification()
|
const requireEmailVerification = useRequireEmailVerification()
|
||||||
const leftConvos = useLeftConvos()
|
const leftConvos = useLeftConvos()
|
||||||
|
|
||||||
@@ -415,6 +418,7 @@ export function Header({newChatControl}: {newChatControl: DialogControlProps}) {
|
|||||||
useListConvosQuery({
|
useListConvosQuery({
|
||||||
status: 'request',
|
status: 'request',
|
||||||
readState: 'unread',
|
readState: 'unread',
|
||||||
|
kind: aa.flags.isUnder18 ? 'direct' : 'all',
|
||||||
})
|
})
|
||||||
|
|
||||||
const inboxAllConvos =
|
const inboxAllConvos =
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import * as Layout from '#/components/Layout'
|
|||||||
import {ListFooter} from '#/components/Lists'
|
import {ListFooter} from '#/components/Lists'
|
||||||
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 {IS_NATIVE} from '#/env'
|
import {IS_NATIVE} from '#/env'
|
||||||
import {RequestListItem} from './components/RequestListItem'
|
import {RequestListItem} from './components/RequestListItem'
|
||||||
import {useIsWithinSplitView} from './components/splitView/context'
|
import {useIsWithinSplitView} from './components/splitView/context'
|
||||||
@@ -63,8 +64,12 @@ export function MessagesInboxScreen(props: Props) {
|
|||||||
|
|
||||||
export function MessagesInboxScreenInner({}: Props) {
|
export function MessagesInboxScreenInner({}: Props) {
|
||||||
const {gtTablet} = useBreakpoints()
|
const {gtTablet} = useBreakpoints()
|
||||||
|
const aa = useAgeAssurance()
|
||||||
|
|
||||||
const listConvosQuery = useListConvosQuery({status: 'request'})
|
const listConvosQuery = useListConvosQuery({
|
||||||
|
status: 'request',
|
||||||
|
kind: aa.flags.isUnder18 ? 'direct' : 'all',
|
||||||
|
})
|
||||||
const {data} = listConvosQuery
|
const {data} = listConvosQuery
|
||||||
|
|
||||||
const leftConvos = useLeftConvos()
|
const leftConvos = useLeftConvos()
|
||||||
|
|||||||
@@ -20,6 +20,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'
|
||||||
@@ -45,6 +46,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,
|
||||||
@@ -53,6 +55,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.isUnder18
|
||||||
|
|
||||||
const allowMessagesFromOptions: {name: AllowIncoming; label: string}[] = [
|
const allowMessagesFromOptions: {name: AllowIncoming; label: string}[] = [
|
||||||
{
|
{
|
||||||
@@ -190,17 +193,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={[
|
values={[
|
||||||
(profile?.associated?.chat
|
groupInvitesLocked
|
||||||
?.allowGroupInvites as AllowIncoming) ?? 'following',
|
? 'none'
|
||||||
|
: ((profile?.associated?.chat
|
||||||
|
?.allowGroupInvites as AllowIncoming) ?? 'following'),
|
||||||
]}
|
]}
|
||||||
onChange={onSelectGroupInvitesFrom}>
|
onChange={onSelectGroupInvitesFrom}>
|
||||||
<View>
|
<View>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import {useMemo} from 'react'
|
import {useMemo} from 'react'
|
||||||
import {useMutation, useQueryClient} from '@tanstack/react-query'
|
import {useMutation, useQueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
|
import {restrictGroupChatSettings} from '#/state/queries/messages/restrictChatSettings'
|
||||||
import {preferencesQueryKey} from '#/state/queries/preferences'
|
import {preferencesQueryKey} from '#/state/queries/preferences'
|
||||||
import {useAgent, useSession} from '#/state/session'
|
import {useAgent, useSession} from '#/state/session'
|
||||||
import {usePatchAgeAssuranceOtherRequiredData} from '#/ageAssurance'
|
import {usePatchAgeAssuranceOtherRequiredData} from '#/ageAssurance'
|
||||||
@@ -67,6 +68,10 @@ export function useBirthdateMutation() {
|
|||||||
|
|
||||||
if (isUnderAge(birthDate.toISOString(), 18)) {
|
if (isUnderAge(birthDate.toISOString(), 18)) {
|
||||||
maybeRestrictChatSettings({agent})
|
maybeRestrictChatSettings({agent})
|
||||||
|
const did = agent.sessionManager.did
|
||||||
|
if (did) {
|
||||||
|
await restrictGroupChatSettings({agent, did})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import {useMessagesEventBus} from '#/state/messages/events'
|
|||||||
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
||||||
import {useAgent, useSession} from '#/state/session'
|
import {useAgent, useSession} from '#/state/session'
|
||||||
import {parseConvoView} from '#/components/dms/util'
|
import {parseConvoView} from '#/components/dms/util'
|
||||||
|
import {useAgeAssurance} from '#/ageAssurance'
|
||||||
import {useLeftConvos} from './leave-conversation'
|
import {useLeftConvos} from './leave-conversation'
|
||||||
|
|
||||||
const DEFAULT_LIMIT = 10
|
const DEFAULT_LIMIT = 10
|
||||||
@@ -111,10 +112,12 @@ export function ListConvosProviderInner({
|
|||||||
}: {
|
}: {
|
||||||
children: React.ReactNode
|
children: React.ReactNode
|
||||||
}) {
|
}) {
|
||||||
|
const aa = useAgeAssurance()
|
||||||
const {refetch, data} = useListConvosQuery({
|
const {refetch, data} = useListConvosQuery({
|
||||||
readState: 'unread',
|
readState: 'unread',
|
||||||
limit: UNREAD_LIMIT,
|
limit: UNREAD_LIMIT,
|
||||||
lockStatus: 'unlocked',
|
lockStatus: 'unlocked',
|
||||||
|
kind: aa.flags.isUnder18 ? 'direct' : 'all',
|
||||||
})
|
})
|
||||||
const messagesBus = useMessagesEventBus()
|
const messagesBus = useMessagesEventBus()
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ 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 {setOtherRequiredDataActorDeclarationCache} from '#/ageAssurance/data'
|
import {
|
||||||
|
getOtherRequiredDataFromCache,
|
||||||
|
setOtherRequiredDataActorDeclarationCache,
|
||||||
|
} from '#/ageAssurance/data'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to update the chat settings record.
|
* Helper to update the chat settings record.
|
||||||
@@ -37,3 +40,44 @@ export async function restrictChatSettings({
|
|||||||
logger.error(`restrictChatSettings: failed to set chat declaration`)
|
logger.error(`restrictChatSettings: failed to set chat declaration`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Locks the user out of being added to group chats by setting
|
||||||
|
* `allowGroupInvites: 'none'` on the chat actor declaration. Used for under-18
|
||||||
|
* users, who per spec cannot participate in group chats.
|
||||||
|
*
|
||||||
|
* Preserves the existing `allowIncoming` value if one is cached, otherwise
|
||||||
|
* defaults to 'following' (the lexicon default) since the field is required.
|
||||||
|
*/
|
||||||
|
export async function restrictGroupChatSettings({
|
||||||
|
agent,
|
||||||
|
did,
|
||||||
|
}: {
|
||||||
|
agent: AtpAgent
|
||||||
|
did: string
|
||||||
|
}): Promise<void> {
|
||||||
|
const cached = getOtherRequiredDataFromCache({did})?.actorDeclaration
|
||||||
|
if (cached?.allowGroupInvites === 'none') return
|
||||||
|
|
||||||
|
try {
|
||||||
|
const record: ChatBskyActorDeclaration.Main = {
|
||||||
|
$type: 'chat.bsky.actor.declaration',
|
||||||
|
allowIncoming: cached?.allowIncoming ?? 'following',
|
||||||
|
allowGroupInvites: 'none',
|
||||||
|
}
|
||||||
|
await networkRetry(3, () =>
|
||||||
|
agent.com.atproto.repo.putRecord({
|
||||||
|
repo: did,
|
||||||
|
collection: 'chat.bsky.actor.declaration',
|
||||||
|
rkey: 'self',
|
||||||
|
record,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
setOtherRequiredDataActorDeclarationCache({
|
||||||
|
did,
|
||||||
|
actorDeclaration: record,
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
logger.error(`restrictGroupChatSettings: failed to set chat declaration`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,9 +19,13 @@ import {
|
|||||||
PUBLIC_BSKY_SERVICE,
|
PUBLIC_BSKY_SERVICE,
|
||||||
TIMELINE_SAVED_FEED,
|
TIMELINE_SAVED_FEED,
|
||||||
} from '#/lib/constants'
|
} from '#/lib/constants'
|
||||||
|
import {getAge} from '#/lib/strings/time'
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {snoozeBirthdateUpdateAllowedForDid} from '#/state/birthdate'
|
import {snoozeBirthdateUpdateAllowedForDid} from '#/state/birthdate'
|
||||||
import {restrictChatSettings} from '#/state/queries/messages/restrictChatSettings'
|
import {
|
||||||
|
restrictChatSettings,
|
||||||
|
restrictGroupChatSettings,
|
||||||
|
} from '#/state/queries/messages/restrictChatSettings'
|
||||||
import {snoozeEmailConfirmationPrompt} from '#/state/shell/reminders'
|
import {snoozeEmailConfirmationPrompt} from '#/state/shell/reminders'
|
||||||
import {
|
import {
|
||||||
prefetchAgeAssuranceData,
|
prefetchAgeAssuranceData,
|
||||||
@@ -223,6 +227,9 @@ export async function createAgentAndCreateAccount(
|
|||||||
if (state.access !== AgeAssuranceAccess.Full) {
|
if (state.access !== AgeAssuranceAccess.Full) {
|
||||||
restrictChatSettings({agent, did: account.did})
|
restrictChatSettings({agent, did: account.did})
|
||||||
}
|
}
|
||||||
|
if (getAge(birthDate) < 18) {
|
||||||
|
restrictGroupChatSettings({agent, did: account.did})
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
]).then(promises => {
|
]).then(promises => {
|
||||||
const rejected = promises.filter(p => p.status === 'rejected')
|
const rejected = promises.filter(p => p.status === 'rejected')
|
||||||
|
|||||||
Reference in New Issue
Block a user