Update chat settings (#10449)

This commit is contained in:
DS Boyce
2026-05-08 15:49:44 -07:00
committed by GitHub
parent 75d8fb3dbd
commit 1609778ff6
4 changed files with 276 additions and 119 deletions
@@ -21,8 +21,21 @@ export function useUpdateActorDeclaration({
const agent = useAgent()
return useMutation({
mutationFn: async (allowIncoming: 'all' | 'none' | 'following') => {
mutationFn: async (update: {
allowIncoming?: 'all' | 'none' | 'following'
allowGroupInvites?: 'all' | 'none' | 'following'
}) => {
if (!currentAccount) throw new Error('Not signed in')
const current =
queryClient.getQueryData<AppBskyActorDefs.ProfileViewDetailed>(
PROFILE_RKEY(currentAccount.did),
)
const allowIncoming =
update.allowIncoming ??
current?.associated?.chat?.allowIncoming ??
'following'
const allowGroupInvites =
update.allowGroupInvites ?? current?.associated?.chat?.allowGroupInvites
const result = await agent.com.atproto.repo.putRecord({
repo: currentAccount.did,
collection: 'chat.bsky.actor.declaration',
@@ -30,11 +43,12 @@ export function useUpdateActorDeclaration({
record: {
$type: 'chat.bsky.actor.declaration',
allowIncoming,
...(allowGroupInvites && {allowGroupInvites}),
},
})
return result
},
onMutate: allowIncoming => {
onMutate: update => {
if (!currentAccount) return
queryClient.setQueryData(
PROFILE_RKEY(currentAccount?.did),
@@ -45,7 +59,9 @@ export function useUpdateActorDeclaration({
associated: {
...old.associated,
chat: {
allowIncoming,
allowIncoming: 'following',
...old.associated?.chat,
...update,
},
},
} satisfies AppBskyActorDefs.ProfileViewDetailed