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:
@@ -3,7 +3,10 @@ import {type ChatBskyActorDeclaration} from '@atproto/api'
|
||||
|
||||
import {networkRetry} from '#/lib/async/retry'
|
||||
import {logger} from '#/logger'
|
||||
import {setOtherRequiredDataActorDeclarationCache} from '#/ageAssurance/data'
|
||||
import {
|
||||
getOtherRequiredDataFromCache,
|
||||
setOtherRequiredDataActorDeclarationCache,
|
||||
} from '#/ageAssurance/data'
|
||||
|
||||
/**
|
||||
* Helper to update the chat settings record.
|
||||
@@ -37,3 +40,44 @@ export async function restrictChatSettings({
|
||||
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`)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user