migrate the record-mint mutations to sdk actions
like/repost/follow/delete and upsertProfile move off the bridge agent's sugar methods onto @bsky.app/sdk actions over the pds client. The mute/unmute and thread-mute writes route through the appview client, and the profile reads move to the appview client behind their existing legacy-typed hook signatures.
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
import {useMemo} from 'react'
|
import {useMemo} from 'react'
|
||||||
|
import {setPersonalDetails} from '@bsky.app/sdk'
|
||||||
import {useMutation, useQueryClient} from '@tanstack/react-query'
|
import {useMutation, useQueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {restrictChatSettings} from '#/state/queries/messages/restrictChatSettings'
|
import {restrictChatSettings} from '#/state/queries/messages/restrictChatSettings'
|
||||||
import {preferencesQueryKey} from '#/state/queries/preferences'
|
import {preferencesQueryKey} from '#/state/queries/preferences'
|
||||||
import {useAgent, usePdsClient, useSession} from '#/state/session'
|
import {usePdsClient, useSession} from '#/state/session'
|
||||||
import {usePatchAgeAssuranceOtherRequiredData} from '#/ageAssurance'
|
import {usePatchAgeAssuranceOtherRequiredData} from '#/ageAssurance'
|
||||||
import {isUnderAge} from '#/ageAssurance/util'
|
import {isUnderAge} from '#/ageAssurance/util'
|
||||||
import {IS_DEV} from '#/env'
|
import {IS_DEV} from '#/env'
|
||||||
@@ -54,14 +55,14 @@ export function useIsBirthdateUpdateAllowed() {
|
|||||||
|
|
||||||
export function useBirthdateMutation() {
|
export function useBirthdateMutation() {
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const agent = useAgent()
|
const {currentAccount} = useSession()
|
||||||
const pdsClient = usePdsClient()
|
const pdsClient = usePdsClient()
|
||||||
const patchOtherRequiredData = usePatchAgeAssuranceOtherRequiredData()
|
const patchOtherRequiredData = usePatchAgeAssuranceOtherRequiredData()
|
||||||
|
|
||||||
return useMutation<void, unknown, {birthDate: Date}>({
|
return useMutation<void, unknown, {birthDate: Date}>({
|
||||||
mutationFn: async ({birthDate}: {birthDate: Date}) => {
|
mutationFn: async ({birthDate}: {birthDate: Date}) => {
|
||||||
const bday = birthDate.toISOString()
|
const bday = birthDate.toISOString()
|
||||||
await agent.setPersonalDetails({birthDate: bday})
|
await pdsClient.call(setPersonalDetails, {birthDate})
|
||||||
// triggers a refetch
|
// triggers a refetch
|
||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
queryKey: preferencesQueryKey,
|
queryKey: preferencesQueryKey,
|
||||||
@@ -80,7 +81,9 @@ export function useBirthdateMutation() {
|
|||||||
* birthdate, which may change the user's age assurance access level.
|
* birthdate, which may change the user's age assurance access level.
|
||||||
*/
|
*/
|
||||||
void patchOtherRequiredData({birthdate: bday})
|
void patchOtherRequiredData({birthdate: bday})
|
||||||
snoozeBirthdateUpdateAllowedForDid(agent.sessionManager.did!)
|
if (currentAccount) {
|
||||||
|
snoozeBirthdateUpdateAllowedForDid(currentAccount.did)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,27 @@
|
|||||||
|
import {type AtUriString} from '@atproto/syntax'
|
||||||
|
import {deleteLike, like} from '@bsky.app/sdk'
|
||||||
import {useMutation} from '@tanstack/react-query'
|
import {useMutation} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useAgent} from '#/state/session'
|
import {usePdsClient} from '#/state/session'
|
||||||
|
|
||||||
export function useLikeMutation() {
|
export function useLikeMutation() {
|
||||||
const agent = useAgent()
|
const pdsClient = usePdsClient()
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async ({uri, cid}: {uri: string; cid: string}) => {
|
mutationFn: async ({uri, cid}: {uri: string; cid: string}) => {
|
||||||
const res = await agent.like(uri, cid)
|
const res = await pdsClient.call(like, {
|
||||||
|
uri: uri as AtUriString,
|
||||||
|
cid,
|
||||||
|
})
|
||||||
return {uri: res.uri}
|
return {uri: res.uri}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useUnlikeMutation() {
|
export function useUnlikeMutation() {
|
||||||
const agent = useAgent()
|
const pdsClient = usePdsClient()
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async ({uri}: {uri: string}) => {
|
mutationFn: async ({uri}: {uri: string}) => {
|
||||||
await agent.deleteLike(uri)
|
await pdsClient.call(deleteLike, uri as AtUriString)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {useMutation, useQueryClient} from '@tanstack/react-query'
|
|||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {RQKEY as FEED_RQKEY} from '#/state/queries/post-feed'
|
import {RQKEY as FEED_RQKEY} from '#/state/queries/post-feed'
|
||||||
import * as Toast from '#/components/Toast'
|
import * as Toast from '#/components/Toast'
|
||||||
import {app} from '#/lexicons'
|
import {app, type com} from '#/lexicons'
|
||||||
import {updatePostShadow} from '../cache/post-shadow'
|
import {updatePostShadow} from '../cache/post-shadow'
|
||||||
import {useAppviewClient, useSession} from '../session'
|
import {useAppviewClient, useSession} from '../session'
|
||||||
import {useProfileUpdateMutation} from './profile'
|
import {useProfileUpdateMutation} from './profile'
|
||||||
@@ -47,7 +47,11 @@ export function usePinnedPostMutation() {
|
|||||||
profile,
|
profile,
|
||||||
updates: existing => {
|
updates: existing => {
|
||||||
existing.pinnedPost = pinCurrentPost
|
existing.pinnedPost = pinCurrentPost
|
||||||
? {uri: postUri, cid: postCid}
|
? // the caller's uri/cid are unbranded strings
|
||||||
|
({
|
||||||
|
uri: postUri,
|
||||||
|
cid: postCid,
|
||||||
|
} as com.atproto.repo.strongRef.Main)
|
||||||
: undefined
|
: undefined
|
||||||
return existing
|
return existing
|
||||||
},
|
},
|
||||||
|
|||||||
+39
-17
@@ -1,5 +1,7 @@
|
|||||||
import {useCallback} from 'react'
|
import {useCallback} from 'react'
|
||||||
import {type AppBskyActorDefs, type AppBskyFeedDefs, AtUri} from '@atproto/api'
|
import {type AppBskyActorDefs, type AppBskyFeedDefs, AtUri} from '@atproto/api'
|
||||||
|
import {type AtUriString} from '@atproto/syntax'
|
||||||
|
import {deleteLike, deletePost, deleteRepost, like, repost} from '@bsky.app/sdk'
|
||||||
import {
|
import {
|
||||||
type QueryClient,
|
type QueryClient,
|
||||||
useMutation,
|
useMutation,
|
||||||
@@ -10,10 +12,16 @@ import {
|
|||||||
import {useToggleMutationQueue} from '#/lib/hooks/useToggleMutationQueue'
|
import {useToggleMutationQueue} from '#/lib/hooks/useToggleMutationQueue'
|
||||||
import {updatePostShadow} from '#/state/cache/post-shadow'
|
import {updatePostShadow} from '#/state/cache/post-shadow'
|
||||||
import {type Shadow} from '#/state/cache/types'
|
import {type Shadow} from '#/state/cache/types'
|
||||||
import {useAgent, useSession} from '#/state/session'
|
import {
|
||||||
|
useAgent,
|
||||||
|
useAppviewClient,
|
||||||
|
usePdsClient,
|
||||||
|
useSession,
|
||||||
|
} from '#/state/session'
|
||||||
import * as userActionHistory from '#/state/userActionHistory'
|
import * as userActionHistory from '#/state/userActionHistory'
|
||||||
import {useAnalytics} from '#/analytics'
|
import {useAnalytics} from '#/analytics'
|
||||||
import {type Metrics, toClout} from '#/analytics/metrics'
|
import {type Metrics, toClout} from '#/analytics/metrics'
|
||||||
|
import {app} from '#/lexicons'
|
||||||
import {useIsThreadMuted, useSetThreadMute} from '../cache/thread-mutes'
|
import {useIsThreadMuted, useSetThreadMute} from '../cache/thread-mutes'
|
||||||
import {findProfileQueryData} from './profile'
|
import {findProfileQueryData} from './profile'
|
||||||
|
|
||||||
@@ -184,7 +192,7 @@ function usePostLikeMutation(
|
|||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const postAuthor = post.author
|
const postAuthor = post.author
|
||||||
const agent = useAgent()
|
const pdsClient = usePdsClient()
|
||||||
const ax = useAnalytics()
|
const ax = useAnalytics()
|
||||||
return useMutation<
|
return useMutation<
|
||||||
{uri: string}, // responds with the uri of the like
|
{uri: string}, // responds with the uri of the like
|
||||||
@@ -215,7 +223,11 @@ function usePostLikeMutation(
|
|||||||
: undefined,
|
: undefined,
|
||||||
feedDescriptor: feedDescriptor,
|
feedDescriptor: feedDescriptor,
|
||||||
})
|
})
|
||||||
return agent.like(uri, cid, via)
|
return pdsClient.call(like, {
|
||||||
|
uri: uri as AtUriString,
|
||||||
|
cid: cid,
|
||||||
|
via: via ? {uri: via.uri as AtUriString, cid: via.cid} : undefined,
|
||||||
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -225,7 +237,7 @@ function usePostUnlikeMutation(
|
|||||||
logContext: Metrics['post:unlike']['logContext'],
|
logContext: Metrics['post:unlike']['logContext'],
|
||||||
post: Shadow<AppBskyFeedDefs.PostView>,
|
post: Shadow<AppBskyFeedDefs.PostView>,
|
||||||
) {
|
) {
|
||||||
const agent = useAgent()
|
const pdsClient = usePdsClient()
|
||||||
const ax = useAnalytics()
|
const ax = useAnalytics()
|
||||||
return useMutation<void, Error, {postUri: string; likeUri: string}>({
|
return useMutation<void, Error, {postUri: string; likeUri: string}>({
|
||||||
mutationFn: ({postUri, likeUri}) => {
|
mutationFn: ({postUri, likeUri}) => {
|
||||||
@@ -235,7 +247,7 @@ function usePostUnlikeMutation(
|
|||||||
logContext,
|
logContext,
|
||||||
feedDescriptor,
|
feedDescriptor,
|
||||||
})
|
})
|
||||||
return agent.deleteLike(likeUri)
|
return pdsClient.call(deleteLike, likeUri as AtUriString)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -309,7 +321,7 @@ function usePostRepostMutation(
|
|||||||
logContext: Metrics['post:repost']['logContext'],
|
logContext: Metrics['post:repost']['logContext'],
|
||||||
post: Shadow<AppBskyFeedDefs.PostView>,
|
post: Shadow<AppBskyFeedDefs.PostView>,
|
||||||
) {
|
) {
|
||||||
const agent = useAgent()
|
const pdsClient = usePdsClient()
|
||||||
const ax = useAnalytics()
|
const ax = useAnalytics()
|
||||||
return useMutation<
|
return useMutation<
|
||||||
{uri: string}, // responds with the uri of the repost
|
{uri: string}, // responds with the uri of the repost
|
||||||
@@ -323,7 +335,11 @@ function usePostRepostMutation(
|
|||||||
logContext,
|
logContext,
|
||||||
feedDescriptor,
|
feedDescriptor,
|
||||||
})
|
})
|
||||||
return agent.repost(uri, cid, via)
|
return pdsClient.call(repost, {
|
||||||
|
uri: uri as AtUriString,
|
||||||
|
cid: cid,
|
||||||
|
via: via ? {uri: via.uri as AtUriString, cid: via.cid} : undefined,
|
||||||
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -333,7 +349,7 @@ function usePostUnrepostMutation(
|
|||||||
logContext: Metrics['post:unrepost']['logContext'],
|
logContext: Metrics['post:unrepost']['logContext'],
|
||||||
post: Shadow<AppBskyFeedDefs.PostView>,
|
post: Shadow<AppBskyFeedDefs.PostView>,
|
||||||
) {
|
) {
|
||||||
const agent = useAgent()
|
const pdsClient = usePdsClient()
|
||||||
const ax = useAnalytics()
|
const ax = useAnalytics()
|
||||||
return useMutation<void, Error, {postUri: string; repostUri: string}>({
|
return useMutation<void, Error, {postUri: string; repostUri: string}>({
|
||||||
mutationFn: ({postUri, repostUri}) => {
|
mutationFn: ({postUri, repostUri}) => {
|
||||||
@@ -343,17 +359,17 @@ function usePostUnrepostMutation(
|
|||||||
logContext,
|
logContext,
|
||||||
feedDescriptor,
|
feedDescriptor,
|
||||||
})
|
})
|
||||||
return agent.deleteRepost(repostUri)
|
return pdsClient.call(deleteRepost, repostUri as AtUriString)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function usePostDeleteMutation() {
|
export function usePostDeleteMutation() {
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const agent = useAgent()
|
const pdsClient = usePdsClient()
|
||||||
return useMutation<void, Error, {uri: string}>({
|
return useMutation<void, Error, {uri: string}>({
|
||||||
mutationFn: async ({uri}) => {
|
mutationFn: async ({uri}) => {
|
||||||
await agent.deletePost(uri)
|
await pdsClient.call(deletePost, uri as AtUriString)
|
||||||
},
|
},
|
||||||
onSuccess(_, variables) {
|
onSuccess(_, variables) {
|
||||||
updatePostShadow(queryClient, variables.uri, {isDeleted: true})
|
updatePostShadow(queryClient, variables.uri, {isDeleted: true})
|
||||||
@@ -407,23 +423,29 @@ export function useThreadMuteMutationQueue(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function useThreadMuteMutation() {
|
function useThreadMuteMutation() {
|
||||||
const agent = useAgent()
|
const appviewClient = useAppviewClient()
|
||||||
return useMutation<
|
return useMutation<
|
||||||
{},
|
{},
|
||||||
Error,
|
Error,
|
||||||
{uri: string} // the root post's uri
|
{uri: string} // the root post's uri
|
||||||
>({
|
>({
|
||||||
mutationFn: ({uri}) => {
|
mutationFn: async ({uri}) => {
|
||||||
return agent.api.app.bsky.graph.muteThread({root: uri})
|
await appviewClient.call(app.bsky.graph.muteThread, {
|
||||||
|
root: uri as AtUriString,
|
||||||
|
})
|
||||||
|
return {}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function useThreadUnmuteMutation() {
|
function useThreadUnmuteMutation() {
|
||||||
const agent = useAgent()
|
const appviewClient = useAppviewClient()
|
||||||
return useMutation<{}, Error, {uri: string}>({
|
return useMutation<{}, Error, {uri: string}>({
|
||||||
mutationFn: ({uri}) => {
|
mutationFn: async ({uri}) => {
|
||||||
return agent.api.app.bsky.graph.unmuteThread({root: uri})
|
await appviewClient.call(app.bsky.graph.unmuteThread, {
|
||||||
|
root: uri as AtUriString,
|
||||||
|
})
|
||||||
|
return {}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,17 +3,24 @@ import {
|
|||||||
type AppBskyActorDefs,
|
type AppBskyActorDefs,
|
||||||
type AppBskyActorGetProfile,
|
type AppBskyActorGetProfile,
|
||||||
type AppBskyActorGetProfiles,
|
type AppBskyActorGetProfiles,
|
||||||
type AppBskyActorProfile,
|
|
||||||
type AppBskyGraphGetFollows,
|
type AppBskyGraphGetFollows,
|
||||||
type AtpAgent,
|
|
||||||
AtUri,
|
AtUri,
|
||||||
type Un$Typed,
|
type Un$Typed,
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
|
import {type Client} from '@atproto/lex'
|
||||||
import {
|
import {
|
||||||
type AtIdentifierString,
|
type AtIdentifierString,
|
||||||
|
type AtUriString,
|
||||||
type DidString,
|
type DidString,
|
||||||
toDatetimeString,
|
toDatetimeString,
|
||||||
} from '@atproto/syntax'
|
} from '@atproto/syntax'
|
||||||
|
import {
|
||||||
|
deleteFollow,
|
||||||
|
follow,
|
||||||
|
muteActor,
|
||||||
|
unmuteActor,
|
||||||
|
upsertProfile,
|
||||||
|
} from '@bsky.app/sdk'
|
||||||
import {
|
import {
|
||||||
type InfiniteData,
|
type InfiniteData,
|
||||||
keepPreviousData,
|
keepPreviousData,
|
||||||
@@ -24,7 +31,6 @@ import {
|
|||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {uploadBlob} from '#/lib/api'
|
import {uploadBlob} from '#/lib/api'
|
||||||
import {toLegacyBlobRef} from '#/lib/api/legacy-blob'
|
|
||||||
import {until} from '#/lib/async/until'
|
import {until} from '#/lib/async/until'
|
||||||
import {useToggleMutationQueue} from '#/lib/hooks/useToggleMutationQueue'
|
import {useToggleMutationQueue} from '#/lib/hooks/useToggleMutationQueue'
|
||||||
import {updateProfileShadow} from '#/state/cache/profile-shadow'
|
import {updateProfileShadow} from '#/state/cache/profile-shadow'
|
||||||
@@ -38,7 +44,7 @@ import {
|
|||||||
useUnstableProfileViewCache,
|
useUnstableProfileViewCache,
|
||||||
} from '#/state/queries/unstable-profile-cache'
|
} from '#/state/queries/unstable-profile-cache'
|
||||||
import {useUpdateProfileVerificationCache} from '#/state/queries/verification/useUpdateProfileVerificationCache'
|
import {useUpdateProfileVerificationCache} from '#/state/queries/verification/useUpdateProfileVerificationCache'
|
||||||
import {useAgent, usePdsClient, useSession} from '#/state/session'
|
import {useAppviewClient, usePdsClient, useSession} from '#/state/session'
|
||||||
import * as userActionHistory from '#/state/userActionHistory'
|
import * as userActionHistory from '#/state/userActionHistory'
|
||||||
import {useAnalytics} from '#/analytics'
|
import {useAnalytics} from '#/analytics'
|
||||||
import {type Metrics, toClout} from '#/analytics/metrics'
|
import {type Metrics, toClout} from '#/analytics/metrics'
|
||||||
@@ -74,7 +80,7 @@ export function useProfileQuery({
|
|||||||
did: string | undefined
|
did: string | undefined
|
||||||
staleTime?: number
|
staleTime?: number
|
||||||
}) {
|
}) {
|
||||||
const agent = useAgent()
|
const client = useAppviewClient()
|
||||||
const {getUnstableProfile} = useUnstableProfileViewCache()
|
const {getUnstableProfile} = useUnstableProfileViewCache()
|
||||||
return useQuery<AppBskyActorDefs.ProfileViewDetailed>({
|
return useQuery<AppBskyActorDefs.ProfileViewDetailed>({
|
||||||
// WARNING
|
// WARNING
|
||||||
@@ -85,8 +91,9 @@ export function useProfileQuery({
|
|||||||
refetchOnWindowFocus: true,
|
refetchOnWindowFocus: true,
|
||||||
queryKey: RQKEY(did ?? ''),
|
queryKey: RQKEY(did ?? ''),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await agent.getProfile({actor: did ?? ''})
|
return await client.call(app.bsky.actor.getProfile, {
|
||||||
return res.data
|
actor: (did ?? '') as AtIdentifierString,
|
||||||
|
})
|
||||||
},
|
},
|
||||||
placeholderData: () => {
|
placeholderData: () => {
|
||||||
if (!did) return
|
if (!did) return
|
||||||
@@ -103,21 +110,22 @@ export function useProfilesQuery({
|
|||||||
handles: string[]
|
handles: string[]
|
||||||
maintainData?: boolean
|
maintainData?: boolean
|
||||||
}) {
|
}) {
|
||||||
const agent = useAgent()
|
const client = useAppviewClient()
|
||||||
return useQuery({
|
return useQuery({
|
||||||
enabled: handles.length > 0,
|
enabled: handles.length > 0,
|
||||||
staleTime: STALE.MINUTES.FIVE,
|
staleTime: STALE.MINUTES.FIVE,
|
||||||
queryKey: profilesQueryKey(handles),
|
queryKey: profilesQueryKey(handles),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await agent.getProfiles({actors: handles})
|
return await client.call(app.bsky.actor.getProfiles, {
|
||||||
return res.data
|
actors: handles as AtIdentifierString[],
|
||||||
|
})
|
||||||
},
|
},
|
||||||
placeholderData: maintainData ? keepPreviousData : undefined,
|
placeholderData: maintainData ? keepPreviousData : undefined,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function usePrefetchProfileQuery() {
|
export function usePrefetchProfileQuery() {
|
||||||
const agent = useAgent()
|
const client = useAppviewClient()
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const prefetchProfileQuery = useCallback(
|
const prefetchProfileQuery = useCallback(
|
||||||
async (did: string) => {
|
async (did: string) => {
|
||||||
@@ -125,12 +133,13 @@ export function usePrefetchProfileQuery() {
|
|||||||
staleTime: STALE.SECONDS.THIRTY,
|
staleTime: STALE.SECONDS.THIRTY,
|
||||||
queryKey: RQKEY(did),
|
queryKey: RQKEY(did),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await agent.getProfile({actor: did || ''})
|
return await client.call(app.bsky.actor.getProfile, {
|
||||||
return res.data
|
actor: (did || '') as AtIdentifierString,
|
||||||
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
[queryClient, agent],
|
[queryClient, client],
|
||||||
)
|
)
|
||||||
return prefetchProfileQuery
|
return prefetchProfileQuery
|
||||||
}
|
}
|
||||||
@@ -138,18 +147,18 @@ export function usePrefetchProfileQuery() {
|
|||||||
interface ProfileUpdateParams {
|
interface ProfileUpdateParams {
|
||||||
profile: AppBskyActorDefs.ProfileViewDetailed
|
profile: AppBskyActorDefs.ProfileViewDetailed
|
||||||
updates:
|
updates:
|
||||||
| Un$Typed<AppBskyActorProfile.Record>
|
| Un$Typed<app.bsky.actor.profile.Main>
|
||||||
| ((
|
| ((
|
||||||
existing: Un$Typed<AppBskyActorProfile.Record>,
|
existing: Un$Typed<app.bsky.actor.profile.Main>,
|
||||||
) => Un$Typed<AppBskyActorProfile.Record>)
|
) => Un$Typed<app.bsky.actor.profile.Main>)
|
||||||
newUserAvatar?: ImageMeta | undefined | null
|
newUserAvatar?: ImageMeta | undefined | null
|
||||||
newUserBanner?: ImageMeta | undefined | null
|
newUserBanner?: ImageMeta | undefined | null
|
||||||
checkCommitted?: (res: AppBskyActorGetProfile.Response) => boolean
|
checkCommitted?: (res: AppBskyActorGetProfile.Response) => boolean
|
||||||
}
|
}
|
||||||
export function useProfileUpdateMutation() {
|
export function useProfileUpdateMutation() {
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const agent = useAgent()
|
|
||||||
const pdsClient = usePdsClient()
|
const pdsClient = usePdsClient()
|
||||||
|
const appviewClient = useAppviewClient()
|
||||||
const updateProfileVerificationCache = useUpdateProfileVerificationCache()
|
const updateProfileVerificationCache = useUpdateProfileVerificationCache()
|
||||||
return useMutation<void, Error, ProfileUpdateParams>({
|
return useMutation<void, Error, ProfileUpdateParams>({
|
||||||
mutationFn: async ({
|
mutationFn: async ({
|
||||||
@@ -175,8 +184,8 @@ export function useProfileUpdateMutation() {
|
|||||||
newUserBanner.mime,
|
newUserBanner.mime,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
await agent.upsertProfile(async existing => {
|
await pdsClient.call(upsertProfile, async existing => {
|
||||||
let next: Un$Typed<AppBskyActorProfile.Record> = existing || {}
|
let next: Un$Typed<app.bsky.actor.profile.Main> = existing || {}
|
||||||
if (typeof updates === 'function') {
|
if (typeof updates === 'function') {
|
||||||
next = updates(next)
|
next = updates(next)
|
||||||
} else {
|
} else {
|
||||||
@@ -188,20 +197,20 @@ export function useProfileUpdateMutation() {
|
|||||||
}
|
}
|
||||||
if (newUserAvatarPromise) {
|
if (newUserAvatarPromise) {
|
||||||
const res = await newUserAvatarPromise
|
const res = await newUserAvatarPromise
|
||||||
next.avatar = toLegacyBlobRef(res.blob)
|
next.avatar = res.blob
|
||||||
} else if (newUserAvatar === null) {
|
} else if (newUserAvatar === null) {
|
||||||
next.avatar = undefined
|
next.avatar = undefined
|
||||||
}
|
}
|
||||||
if (newUserBannerPromise) {
|
if (newUserBannerPromise) {
|
||||||
const res = await newUserBannerPromise
|
const res = await newUserBannerPromise
|
||||||
next.banner = toLegacyBlobRef(res.blob)
|
next.banner = res.blob
|
||||||
} else if (newUserBanner === null) {
|
} else if (newUserBanner === null) {
|
||||||
next.banner = undefined
|
next.banner = undefined
|
||||||
}
|
}
|
||||||
return next
|
return next
|
||||||
})
|
})
|
||||||
await whenAppViewReady(
|
await whenAppViewReady(
|
||||||
agent,
|
appviewClient,
|
||||||
profile.did,
|
profile.did,
|
||||||
checkCommitted ||
|
checkCommitted ||
|
||||||
(res => {
|
(res => {
|
||||||
@@ -252,7 +261,7 @@ export function useProfileFollowMutationQueue(
|
|||||||
position?: number,
|
position?: number,
|
||||||
contextProfileDid?: string,
|
contextProfileDid?: string,
|
||||||
) {
|
) {
|
||||||
const agent = useAgent()
|
const client = useAppviewClient()
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const did = profile.did
|
const did = profile.did
|
||||||
@@ -333,12 +342,12 @@ export function useProfileFollowMutationQueue(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (finalFollowingUri) {
|
if (finalFollowingUri) {
|
||||||
void agent.app.bsky.graph
|
void client
|
||||||
.getSuggestedFollowsByActor({
|
.call(app.bsky.graph.getSuggestedFollowsByActor, {
|
||||||
actor: did,
|
actor: did as AtIdentifierString,
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
const dids = res.data.suggestions
|
const dids = res.suggestions
|
||||||
.filter(a => !a.viewer?.following)
|
.filter(a => !a.viewer?.following)
|
||||||
.map(a => a.did)
|
.map(a => a.did)
|
||||||
.slice(0, 8)
|
.slice(0, 8)
|
||||||
@@ -375,7 +384,7 @@ function useProfileFollowMutation(
|
|||||||
) {
|
) {
|
||||||
const ax = useAnalytics()
|
const ax = useAnalytics()
|
||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const agent = useAgent()
|
const pdsClient = usePdsClient()
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const {captureAction} = useProgressGuideControls()
|
const {captureAction} = useProgressGuideControls()
|
||||||
|
|
||||||
@@ -400,7 +409,7 @@ function useProfileFollowMutation(
|
|||||||
position,
|
position,
|
||||||
contextProfileDid,
|
contextProfileDid,
|
||||||
})
|
})
|
||||||
return await agent.follow(did)
|
return await pdsClient.call(follow, {did: did as DidString})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -409,11 +418,11 @@ function useProfileUnfollowMutation(
|
|||||||
logContext: Metrics['profile:unfollow']['logContext'],
|
logContext: Metrics['profile:unfollow']['logContext'],
|
||||||
) {
|
) {
|
||||||
const ax = useAnalytics()
|
const ax = useAnalytics()
|
||||||
const agent = useAgent()
|
const pdsClient = usePdsClient()
|
||||||
return useMutation<void, Error, {did: string; followUri: string}>({
|
return useMutation<void, Error, {did: string; followUri: string}>({
|
||||||
mutationFn: async ({followUri}) => {
|
mutationFn: async ({followUri}) => {
|
||||||
ax.metric('profile:unfollow', {logContext})
|
ax.metric('profile:unfollow', {logContext})
|
||||||
return await agent.deleteFollow(followUri)
|
return await pdsClient.call(deleteFollow, followUri as AtUriString)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -536,10 +545,10 @@ export function useProfileMuteRepostsMutationQueue(
|
|||||||
|
|
||||||
function useProfileMuteMutation() {
|
function useProfileMuteMutation() {
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const agent = useAgent()
|
const appviewClient = useAppviewClient()
|
||||||
return useMutation<void, Error, {did: string}>({
|
return useMutation<void, Error, {did: string}>({
|
||||||
mutationFn: async ({did}) => {
|
mutationFn: async ({did}) => {
|
||||||
await agent.mute(did)
|
await appviewClient.call(muteActor, {actor: did as AtIdentifierString})
|
||||||
},
|
},
|
||||||
onSuccess() {
|
onSuccess() {
|
||||||
void queryClient.invalidateQueries({queryKey: RQKEY_MY_MUTED()})
|
void queryClient.invalidateQueries({queryKey: RQKEY_MY_MUTED()})
|
||||||
@@ -562,10 +571,10 @@ function useProfileMuteRepostsMutation() {
|
|||||||
|
|
||||||
function useProfileUnmuteMutation() {
|
function useProfileUnmuteMutation() {
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const agent = useAgent()
|
const appviewClient = useAppviewClient()
|
||||||
return useMutation<void, Error, {did: string}>({
|
return useMutation<void, Error, {did: string}>({
|
||||||
mutationFn: async ({did}) => {
|
mutationFn: async ({did}) => {
|
||||||
await agent.unmute(did)
|
await appviewClient.call(unmuteActor, {actor: did as AtIdentifierString})
|
||||||
},
|
},
|
||||||
onSuccess() {
|
onSuccess() {
|
||||||
void queryClient.invalidateQueries({queryKey: RQKEY_MY_MUTED()})
|
void queryClient.invalidateQueries({queryKey: RQKEY_MY_MUTED()})
|
||||||
@@ -679,7 +688,7 @@ function useProfileUnblockMutation() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function whenAppViewReady(
|
async function whenAppViewReady(
|
||||||
agent: AtpAgent,
|
client: Client,
|
||||||
actor: string,
|
actor: string,
|
||||||
fn: (res: AppBskyActorGetProfile.Response) => boolean,
|
fn: (res: AppBskyActorGetProfile.Response) => boolean,
|
||||||
) {
|
) {
|
||||||
@@ -687,7 +696,17 @@ async function whenAppViewReady(
|
|||||||
5, // 5 tries
|
5, // 5 tries
|
||||||
1e3, // 1s delay between tries
|
1e3, // 1s delay between tries
|
||||||
fn,
|
fn,
|
||||||
() => agent.app.bsky.actor.getProfile({actor}),
|
/*
|
||||||
|
* `checkCommitted` callbacks are still written against the legacy
|
||||||
|
* `Response` envelope, so wrap the lex output until those consumers move.
|
||||||
|
*/
|
||||||
|
async () => ({
|
||||||
|
success: true,
|
||||||
|
headers: {},
|
||||||
|
data: await client.call(app.bsky.actor.getProfile, {
|
||||||
|
actor: actor as AtIdentifierString,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user