Replace getAgent() with reading agent (#4243)
* Replace getAgent() with agent * Replace {agent} with agent
This commit is contained in:
parent
8a2f43c218
commit
9bd411c151
74 changed files with 400 additions and 438 deletions
|
@ -25,7 +25,7 @@ const stateContext = React.createContext<StateContext>({
|
|||
})
|
||||
|
||||
export function useFeedFeedback(feed: FeedDescriptor, hasSession: boolean) {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const enabled = isDiscoverFeed(feed) && hasSession
|
||||
const queue = React.useRef<Set<string>>(new Set())
|
||||
const history = React.useRef<
|
||||
|
@ -35,7 +35,7 @@ export function useFeedFeedback(feed: FeedDescriptor, hasSession: boolean) {
|
|||
>(new WeakSet())
|
||||
|
||||
const sendToFeedNoDelay = React.useCallback(() => {
|
||||
const proxyAgent = getAgent().withProxy(
|
||||
const proxyAgent = agent.withProxy(
|
||||
// @ts-ignore TODO need to update withProxy() to support this key -prf
|
||||
'bsky_fg',
|
||||
// TODO when we start sending to other feeds, we need to grab their DID -prf
|
||||
|
@ -50,7 +50,7 @@ export function useFeedFeedback(feed: FeedDescriptor, hasSession: boolean) {
|
|||
.catch((e: any) => {
|
||||
logger.warn('Failed to send feed interactions', {error: e})
|
||||
})
|
||||
}, [getAgent])
|
||||
}, [agent])
|
||||
|
||||
const sendToFeed = React.useMemo(
|
||||
() =>
|
||||
|
|
|
@ -58,13 +58,13 @@ export function ConvoProvider({
|
|||
convoId,
|
||||
}: Pick<ConvoParams, 'convoId'> & {children: React.ReactNode}) {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const events = useMessagesEventBus()
|
||||
const [convo] = useState(
|
||||
() =>
|
||||
new Convo({
|
||||
convoId,
|
||||
agent: getAgent(),
|
||||
agent,
|
||||
events,
|
||||
}),
|
||||
)
|
||||
|
|
|
@ -43,11 +43,11 @@ export function MessagesEventBusProviderInner({
|
|||
}: {
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const [bus] = React.useState(
|
||||
() =>
|
||||
new MessagesEventBus({
|
||||
agent: getAgent(),
|
||||
agent,
|
||||
}),
|
||||
)
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ export function useActorAutocompleteQuery(
|
|||
limit?: number,
|
||||
) {
|
||||
const moderationOpts = useModerationOpts()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
prefix = prefix.toLowerCase().trim()
|
||||
if (prefix.endsWith('.')) {
|
||||
|
@ -36,7 +36,7 @@ export function useActorAutocompleteQuery(
|
|||
queryKey: RQKEY(prefix || ''),
|
||||
async queryFn() {
|
||||
const res = prefix
|
||||
? await getAgent().searchActorsTypeahead({
|
||||
? await agent.searchActorsTypeahead({
|
||||
q: prefix,
|
||||
limit: limit || 8,
|
||||
})
|
||||
|
@ -57,7 +57,7 @@ export type ActorAutocompleteFn = ReturnType<typeof useActorAutocompleteFn>
|
|||
export function useActorAutocompleteFn() {
|
||||
const queryClient = useQueryClient()
|
||||
const moderationOpts = useModerationOpts()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return React.useCallback(
|
||||
async ({query, limit = 8}: {query: string; limit?: number}) => {
|
||||
|
@ -69,7 +69,7 @@ export function useActorAutocompleteFn() {
|
|||
staleTime: STALE.MINUTES.ONE,
|
||||
queryKey: RQKEY(query || ''),
|
||||
queryFn: () =>
|
||||
getAgent().searchActorsTypeahead({
|
||||
agent.searchActorsTypeahead({
|
||||
q: query,
|
||||
limit,
|
||||
}),
|
||||
|
@ -86,7 +86,7 @@ export function useActorAutocompleteFn() {
|
|||
moderationOpts || DEFAULT_MOD_OPTS,
|
||||
)
|
||||
},
|
||||
[queryClient, moderationOpts, getAgent],
|
||||
[queryClient, moderationOpts, agent],
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -14,12 +14,12 @@ export function useActorSearch({
|
|||
query: string
|
||||
enabled?: boolean
|
||||
}) {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useQuery<AppBskyActorDefs.ProfileView[]>({
|
||||
staleTime: STALE.MINUTES.ONE,
|
||||
queryKey: RQKEY(query || ''),
|
||||
async queryFn() {
|
||||
const res = await getAgent().searchActors({
|
||||
const res = await agent.searchActors({
|
||||
q: query,
|
||||
})
|
||||
return res.data.actors
|
||||
|
|
|
@ -8,12 +8,12 @@ const RQKEY_ROOT = 'app-passwords'
|
|||
export const RQKEY = () => [RQKEY_ROOT]
|
||||
|
||||
export function useAppPasswordsQuery() {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useQuery({
|
||||
staleTime: STALE.MINUTES.FIVE,
|
||||
queryKey: RQKEY(),
|
||||
queryFn: async () => {
|
||||
const res = await getAgent().com.atproto.server.listAppPasswords({})
|
||||
const res = await agent.com.atproto.server.listAppPasswords({})
|
||||
return res.data.passwords
|
||||
},
|
||||
})
|
||||
|
@ -21,7 +21,7 @@ export function useAppPasswordsQuery() {
|
|||
|
||||
export function useAppPasswordCreateMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useMutation<
|
||||
ComAtprotoServerCreateAppPassword.OutputSchema,
|
||||
Error,
|
||||
|
@ -29,7 +29,7 @@ export function useAppPasswordCreateMutation() {
|
|||
>({
|
||||
mutationFn: async ({name, privileged}) => {
|
||||
return (
|
||||
await getAgent().com.atproto.server.createAppPassword({
|
||||
await agent.com.atproto.server.createAppPassword({
|
||||
name,
|
||||
privileged,
|
||||
})
|
||||
|
@ -45,10 +45,10 @@ export function useAppPasswordCreateMutation() {
|
|||
|
||||
export function useAppPasswordDeleteMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useMutation<void, Error, {name: string}>({
|
||||
mutationFn: async ({name}) => {
|
||||
await getAgent().com.atproto.server.revokeAppPassword({
|
||||
await agent.com.atproto.server.revokeAppPassword({
|
||||
name,
|
||||
})
|
||||
},
|
||||
|
|
|
@ -147,7 +147,7 @@ export function getAvatarTypeFromUri(uri: string) {
|
|||
|
||||
export function useFeedSourceInfoQuery({uri}: {uri: string}) {
|
||||
const type = getFeedTypeFromUri(uri)
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useQuery({
|
||||
staleTime: STALE.INFINITY,
|
||||
|
@ -156,10 +156,10 @@ export function useFeedSourceInfoQuery({uri}: {uri: string}) {
|
|||
let view: FeedSourceInfo
|
||||
|
||||
if (type === 'feed') {
|
||||
const res = await getAgent().app.bsky.feed.getFeedGenerator({feed: uri})
|
||||
const res = await agent.app.bsky.feed.getFeedGenerator({feed: uri})
|
||||
view = hydrateFeedGenerator(res.data.view)
|
||||
} else {
|
||||
const res = await getAgent().app.bsky.graph.getList({
|
||||
const res = await agent.app.bsky.graph.getList({
|
||||
list: uri,
|
||||
limit: 1,
|
||||
})
|
||||
|
@ -174,7 +174,7 @@ export function useFeedSourceInfoQuery({uri}: {uri: string}) {
|
|||
export const useGetPopularFeedsQueryKey = ['getPopularFeeds']
|
||||
|
||||
export function useGetPopularFeedsQuery() {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useInfiniteQuery<
|
||||
AppBskyUnspeccedGetPopularFeedGenerators.OutputSchema,
|
||||
Error,
|
||||
|
@ -184,7 +184,7 @@ export function useGetPopularFeedsQuery() {
|
|||
>({
|
||||
queryKey: useGetPopularFeedsQueryKey,
|
||||
queryFn: async ({pageParam}) => {
|
||||
const res = await getAgent().app.bsky.unspecced.getPopularFeedGenerators({
|
||||
const res = await agent.app.bsky.unspecced.getPopularFeedGenerators({
|
||||
limit: 10,
|
||||
cursor: pageParam,
|
||||
})
|
||||
|
@ -196,10 +196,10 @@ export function useGetPopularFeedsQuery() {
|
|||
}
|
||||
|
||||
export function useSearchPopularFeedsMutation() {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useMutation({
|
||||
mutationFn: async (query: string) => {
|
||||
const res = await getAgent().app.bsky.unspecced.getPopularFeedGenerators({
|
||||
const res = await agent.app.bsky.unspecced.getPopularFeedGenerators({
|
||||
limit: 10,
|
||||
query: query,
|
||||
})
|
||||
|
@ -241,7 +241,7 @@ const pinnedFeedInfosQueryKeyRoot = 'pinnedFeedsInfos'
|
|||
|
||||
export function usePinnedFeedsInfos() {
|
||||
const {hasSession} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const {data: preferences, isLoading: isLoadingPrefs} = usePreferencesQuery()
|
||||
const pinnedItems = preferences?.savedFeeds.filter(feed => feed.pinned) ?? []
|
||||
|
||||
|
@ -264,8 +264,8 @@ export function usePinnedFeedsInfos() {
|
|||
const pinnedFeeds = pinnedItems.filter(feed => feed.type === 'feed')
|
||||
let feedsPromise = Promise.resolve()
|
||||
if (pinnedFeeds.length > 0) {
|
||||
feedsPromise = getAgent()
|
||||
.app.bsky.feed.getFeedGenerators({
|
||||
feedsPromise = agent.app.bsky.feed
|
||||
.getFeedGenerators({
|
||||
feeds: pinnedFeeds.map(f => f.value),
|
||||
})
|
||||
.then(res => {
|
||||
|
@ -279,8 +279,8 @@ export function usePinnedFeedsInfos() {
|
|||
// Get all lists. This currently has to be done individually.
|
||||
const pinnedLists = pinnedItems.filter(feed => feed.type === 'list')
|
||||
const listsPromises = pinnedLists.map(list =>
|
||||
getAgent()
|
||||
.app.bsky.graph.getList({
|
||||
agent.app.bsky.graph
|
||||
.getList({
|
||||
list: list.value,
|
||||
limit: 1,
|
||||
})
|
||||
|
|
|
@ -14,7 +14,7 @@ const fetchDidQueryKey = (handleOrDid: string) => [didQueryKeyRoot, handleOrDid]
|
|||
|
||||
export function useFetchHandle() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return React.useCallback(
|
||||
async (handleOrDid: string) => {
|
||||
|
@ -22,23 +22,23 @@ export function useFetchHandle() {
|
|||
const res = await queryClient.fetchQuery({
|
||||
staleTime: STALE.MINUTES.FIVE,
|
||||
queryKey: fetchHandleQueryKey(handleOrDid),
|
||||
queryFn: () => getAgent().getProfile({actor: handleOrDid}),
|
||||
queryFn: () => agent.getProfile({actor: handleOrDid}),
|
||||
})
|
||||
return res.data.handle
|
||||
}
|
||||
return handleOrDid
|
||||
},
|
||||
[queryClient, getAgent],
|
||||
[queryClient, agent],
|
||||
)
|
||||
}
|
||||
|
||||
export function useUpdateHandleMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({handle}: {handle: string}) => {
|
||||
await getAgent().updateHandle({handle})
|
||||
await agent.updateHandle({handle})
|
||||
},
|
||||
onSuccess(_data, variables) {
|
||||
queryClient.invalidateQueries({
|
||||
|
@ -50,7 +50,7 @@ export function useUpdateHandleMutation() {
|
|||
|
||||
export function useFetchDid() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return React.useCallback(
|
||||
async (handleOrDid: string) => {
|
||||
|
@ -60,13 +60,13 @@ export function useFetchDid() {
|
|||
queryFn: async () => {
|
||||
let identifier = handleOrDid
|
||||
if (!identifier.startsWith('did:')) {
|
||||
const res = await getAgent().resolveHandle({handle: identifier})
|
||||
const res = await agent.resolveHandle({handle: identifier})
|
||||
identifier = res.data.did
|
||||
}
|
||||
return identifier
|
||||
},
|
||||
})
|
||||
},
|
||||
[queryClient, getAgent],
|
||||
[queryClient, agent],
|
||||
)
|
||||
}
|
||||
|
|
|
@ -16,13 +16,13 @@ export type InviteCodesQueryResponse = Exclude<
|
|||
undefined
|
||||
>
|
||||
export function useInviteCodesQuery() {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useQuery({
|
||||
staleTime: STALE.MINUTES.FIVE,
|
||||
queryKey: [inviteCodesQueryKeyRoot],
|
||||
queryFn: async () => {
|
||||
const res = await getAgent()
|
||||
.com.atproto.server.getAccountInviteCodes({})
|
||||
const res = await agent.com.atproto.server
|
||||
.getAccountInviteCodes({})
|
||||
.catch(e => {
|
||||
if (cleanError(e) === 'Bad token scope') {
|
||||
return null
|
||||
|
|
|
@ -31,12 +31,12 @@ export function useLabelerInfoQuery({
|
|||
did?: string
|
||||
enabled?: boolean
|
||||
}) {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useQuery({
|
||||
enabled: !!did && enabled !== false,
|
||||
queryKey: labelerInfoQueryKey(did as string),
|
||||
queryFn: async () => {
|
||||
const res = await getAgent().app.bsky.labeler.getServices({
|
||||
const res = await agent.app.bsky.labeler.getServices({
|
||||
dids: [did as string],
|
||||
detailed: true,
|
||||
})
|
||||
|
@ -46,26 +46,26 @@ export function useLabelerInfoQuery({
|
|||
}
|
||||
|
||||
export function useLabelersInfoQuery({dids}: {dids: string[]}) {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useQuery({
|
||||
enabled: !!dids.length,
|
||||
queryKey: labelersInfoQueryKey(dids),
|
||||
queryFn: async () => {
|
||||
const res = await getAgent().app.bsky.labeler.getServices({dids})
|
||||
const res = await agent.app.bsky.labeler.getServices({dids})
|
||||
return res.data.views as AppBskyLabelerDefs.LabelerView[]
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useLabelersDetailedInfoQuery({dids}: {dids: string[]}) {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useQuery({
|
||||
enabled: !!dids.length,
|
||||
queryKey: labelersDetailedInfoQueryKey(dids),
|
||||
gcTime: 1000 * 60 * 60 * 6, // 6 hours
|
||||
staleTime: STALE.MINUTES.ONE,
|
||||
queryFn: async () => {
|
||||
const res = await getAgent().app.bsky.labeler.getServices({
|
||||
const res = await agent.app.bsky.labeler.getServices({
|
||||
dids,
|
||||
detailed: true,
|
||||
})
|
||||
|
@ -76,7 +76,7 @@ export function useLabelersDetailedInfoQuery({dids}: {dids: string[]}) {
|
|||
|
||||
export function useLabelerSubscriptionMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation({
|
||||
async mutationFn({did, subscribe}: {did: string; subscribe: boolean}) {
|
||||
|
@ -87,9 +87,9 @@ export function useLabelerSubscriptionMutation() {
|
|||
}).parse({did, subscribe})
|
||||
|
||||
if (subscribe) {
|
||||
await getAgent().addLabeler(did)
|
||||
await agent.addLabeler(did)
|
||||
} else {
|
||||
await getAgent().removeLabeler(did)
|
||||
await agent.removeLabeler(did)
|
||||
}
|
||||
},
|
||||
onSuccess() {
|
||||
|
|
|
@ -3,20 +3,20 @@ import {useMutation} from '@tanstack/react-query'
|
|||
import {useAgent} from '#/state/session'
|
||||
|
||||
export function useLikeMutation() {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useMutation({
|
||||
mutationFn: async ({uri, cid}: {uri: string; cid: string}) => {
|
||||
const res = await getAgent().like(uri, cid)
|
||||
const res = await agent.like(uri, cid)
|
||||
return {uri: res.uri}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useUnlikeMutation() {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useMutation({
|
||||
mutationFn: async ({uri}: {uri: string}) => {
|
||||
await getAgent().deleteLike(uri)
|
||||
await agent.deleteLike(uri)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ const RQKEY_ROOT = 'list-members'
|
|||
export const RQKEY = (uri: string) => [RQKEY_ROOT, uri]
|
||||
|
||||
export function useListMembersQuery(uri: string) {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useInfiniteQuery<
|
||||
AppBskyGraphGetList.OutputSchema,
|
||||
Error,
|
||||
|
@ -27,7 +27,7 @@ export function useListMembersQuery(uri: string) {
|
|||
staleTime: STALE.MINUTES.ONE,
|
||||
queryKey: RQKEY(uri),
|
||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||
const res = await getAgent().app.bsky.graph.getList({
|
||||
const res = await agent.app.bsky.graph.getList({
|
||||
list: uri,
|
||||
limit: PAGE_SIZE,
|
||||
cursor: pageParam,
|
||||
|
|
|
@ -40,7 +40,7 @@ export interface ListMembersip {
|
|||
*/
|
||||
export function useDangerousListMembershipsQuery() {
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useQuery<ListMembersip[]>({
|
||||
staleTime: STALE.MINUTES.FIVE,
|
||||
queryKey: RQKEY(),
|
||||
|
@ -51,7 +51,7 @@ export function useDangerousListMembershipsQuery() {
|
|||
let cursor
|
||||
let arr: ListMembersip[] = []
|
||||
for (let i = 0; i < SANITY_PAGE_LIMIT; i++) {
|
||||
const res = await getAgent().app.bsky.graph.listitem.list({
|
||||
const res = await agent.app.bsky.graph.listitem.list({
|
||||
repo: currentAccount.did,
|
||||
limit: PAGE_SIZE,
|
||||
cursor,
|
||||
|
@ -92,7 +92,7 @@ export function getMembership(
|
|||
|
||||
export function useListMembershipAddMutation() {
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation<
|
||||
{uri: string; cid: string},
|
||||
|
@ -103,7 +103,7 @@ export function useListMembershipAddMutation() {
|
|||
if (!currentAccount) {
|
||||
throw new Error('Not logged in')
|
||||
}
|
||||
const res = await getAgent().app.bsky.graph.listitem.create(
|
||||
const res = await agent.app.bsky.graph.listitem.create(
|
||||
{repo: currentAccount.did},
|
||||
{
|
||||
subject: actorDid,
|
||||
|
@ -151,7 +151,7 @@ export function useListMembershipAddMutation() {
|
|||
|
||||
export function useListMembershipRemoveMutation() {
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation<
|
||||
void,
|
||||
|
@ -163,7 +163,7 @@ export function useListMembershipRemoveMutation() {
|
|||
throw new Error('Not logged in')
|
||||
}
|
||||
const membershipUrip = new AtUri(membershipUri)
|
||||
await getAgent().app.bsky.graph.listitem.delete({
|
||||
await agent.app.bsky.graph.listitem.delete({
|
||||
repo: currentAccount.did,
|
||||
rkey: membershipUrip.rkey,
|
||||
})
|
||||
|
|
|
@ -21,7 +21,7 @@ const RQKEY_ROOT = 'list'
|
|||
export const RQKEY = (uri: string) => [RQKEY_ROOT, uri]
|
||||
|
||||
export function useListQuery(uri?: string) {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useQuery<AppBskyGraphDefs.ListView, Error>({
|
||||
staleTime: STALE.MINUTES.ONE,
|
||||
queryKey: RQKEY(uri || ''),
|
||||
|
@ -29,7 +29,7 @@ export function useListQuery(uri?: string) {
|
|||
if (!uri) {
|
||||
throw new Error('URI not provided')
|
||||
}
|
||||
const res = await getAgent().app.bsky.graph.getList({
|
||||
const res = await agent.app.bsky.graph.getList({
|
||||
list: uri,
|
||||
limit: 1,
|
||||
})
|
||||
|
@ -49,7 +49,7 @@ export interface ListCreateMutateParams {
|
|||
export function useListCreateMutation() {
|
||||
const {currentAccount} = useSession()
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useMutation<{uri: string; cid: string}, Error, ListCreateMutateParams>(
|
||||
{
|
||||
async mutationFn({
|
||||
|
@ -77,10 +77,10 @@ export function useListCreateMutation() {
|
|||
createdAt: new Date().toISOString(),
|
||||
}
|
||||
if (avatar) {
|
||||
const blobRes = await uploadBlob(getAgent(), avatar.path, avatar.mime)
|
||||
const blobRes = await uploadBlob(agent, avatar.path, avatar.mime)
|
||||
record.avatar = blobRes.data.blob
|
||||
}
|
||||
const res = await getAgent().app.bsky.graph.list.create(
|
||||
const res = await agent.app.bsky.graph.list.create(
|
||||
{
|
||||
repo: currentAccount.did,
|
||||
},
|
||||
|
@ -89,7 +89,7 @@ export function useListCreateMutation() {
|
|||
|
||||
// wait for the appview to update
|
||||
await whenAppViewReady(
|
||||
getAgent,
|
||||
agent,
|
||||
res.uri,
|
||||
(v: AppBskyGraphGetList.Response) => {
|
||||
return typeof v?.data?.list.uri === 'string'
|
||||
|
@ -116,7 +116,7 @@ export interface ListMetadataMutateParams {
|
|||
}
|
||||
export function useListMetadataMutation() {
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation<
|
||||
{uri: string; cid: string},
|
||||
|
@ -133,7 +133,7 @@ export function useListMetadataMutation() {
|
|||
}
|
||||
|
||||
// get the current record
|
||||
const {value: record} = await getAgent().app.bsky.graph.list.get({
|
||||
const {value: record} = await agent.app.bsky.graph.list.get({
|
||||
repo: currentAccount.did,
|
||||
rkey,
|
||||
})
|
||||
|
@ -143,13 +143,13 @@ export function useListMetadataMutation() {
|
|||
record.description = description
|
||||
record.descriptionFacets = descriptionFacets
|
||||
if (avatar) {
|
||||
const blobRes = await uploadBlob(getAgent(), avatar.path, avatar.mime)
|
||||
const blobRes = await uploadBlob(agent, avatar.path, avatar.mime)
|
||||
record.avatar = blobRes.data.blob
|
||||
} else if (avatar === null) {
|
||||
record.avatar = undefined
|
||||
}
|
||||
const res = (
|
||||
await getAgent().com.atproto.repo.putRecord({
|
||||
await agent.com.atproto.repo.putRecord({
|
||||
repo: currentAccount.did,
|
||||
collection: 'app.bsky.graph.list',
|
||||
rkey,
|
||||
|
@ -159,7 +159,7 @@ export function useListMetadataMutation() {
|
|||
|
||||
// wait for the appview to update
|
||||
await whenAppViewReady(
|
||||
getAgent,
|
||||
agent,
|
||||
res.uri,
|
||||
(v: AppBskyGraphGetList.Response) => {
|
||||
const list = v.data.list
|
||||
|
@ -184,7 +184,7 @@ export function useListMetadataMutation() {
|
|||
|
||||
export function useListDeleteMutation() {
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation<void, Error, {uri: string}>({
|
||||
mutationFn: async ({uri}) => {
|
||||
|
@ -195,7 +195,7 @@ export function useListDeleteMutation() {
|
|||
let cursor
|
||||
let listitemRecordUris: string[] = []
|
||||
for (let i = 0; i < 100; i++) {
|
||||
const res = await getAgent().app.bsky.graph.listitem.list({
|
||||
const res = await agent.app.bsky.graph.listitem.list({
|
||||
repo: currentAccount.did,
|
||||
cursor,
|
||||
limit: 100,
|
||||
|
@ -226,20 +226,16 @@ export function useListDeleteMutation() {
|
|||
|
||||
// apply in chunks
|
||||
for (const writesChunk of chunk(writes, 10)) {
|
||||
await getAgent().com.atproto.repo.applyWrites({
|
||||
await agent.com.atproto.repo.applyWrites({
|
||||
repo: currentAccount.did,
|
||||
writes: writesChunk,
|
||||
})
|
||||
}
|
||||
|
||||
// wait for the appview to update
|
||||
await whenAppViewReady(
|
||||
getAgent,
|
||||
uri,
|
||||
(v: AppBskyGraphGetList.Response) => {
|
||||
return !v?.success
|
||||
},
|
||||
)
|
||||
await whenAppViewReady(agent, uri, (v: AppBskyGraphGetList.Response) => {
|
||||
return !v?.success
|
||||
})
|
||||
},
|
||||
onSuccess() {
|
||||
invalidateMyLists(queryClient)
|
||||
|
@ -253,22 +249,18 @@ export function useListDeleteMutation() {
|
|||
|
||||
export function useListMuteMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useMutation<void, Error, {uri: string; mute: boolean}>({
|
||||
mutationFn: async ({uri, mute}) => {
|
||||
if (mute) {
|
||||
await getAgent().muteModList(uri)
|
||||
await agent.muteModList(uri)
|
||||
} else {
|
||||
await getAgent().unmuteModList(uri)
|
||||
await agent.unmuteModList(uri)
|
||||
}
|
||||
|
||||
await whenAppViewReady(
|
||||
getAgent,
|
||||
uri,
|
||||
(v: AppBskyGraphGetList.Response) => {
|
||||
return Boolean(v?.data.list.viewer?.muted) === mute
|
||||
},
|
||||
)
|
||||
await whenAppViewReady(agent, uri, (v: AppBskyGraphGetList.Response) => {
|
||||
return Boolean(v?.data.list.viewer?.muted) === mute
|
||||
})
|
||||
},
|
||||
onSuccess(data, variables) {
|
||||
queryClient.invalidateQueries({
|
||||
|
@ -280,24 +272,20 @@ export function useListMuteMutation() {
|
|||
|
||||
export function useListBlockMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useMutation<void, Error, {uri: string; block: boolean}>({
|
||||
mutationFn: async ({uri, block}) => {
|
||||
if (block) {
|
||||
await getAgent().blockModList(uri)
|
||||
await agent.blockModList(uri)
|
||||
} else {
|
||||
await getAgent().unblockModList(uri)
|
||||
await agent.unblockModList(uri)
|
||||
}
|
||||
|
||||
await whenAppViewReady(
|
||||
getAgent,
|
||||
uri,
|
||||
(v: AppBskyGraphGetList.Response) => {
|
||||
return block
|
||||
? typeof v?.data.list.viewer?.blocked === 'string'
|
||||
: !v?.data.list.viewer?.blocked
|
||||
},
|
||||
)
|
||||
await whenAppViewReady(agent, uri, (v: AppBskyGraphGetList.Response) => {
|
||||
return block
|
||||
? typeof v?.data.list.viewer?.blocked === 'string'
|
||||
: !v?.data.list.viewer?.blocked
|
||||
})
|
||||
},
|
||||
onSuccess(data, variables) {
|
||||
queryClient.invalidateQueries({
|
||||
|
@ -308,7 +296,7 @@ export function useListBlockMutation() {
|
|||
}
|
||||
|
||||
async function whenAppViewReady(
|
||||
getAgent: () => BskyAgent,
|
||||
agent: BskyAgent,
|
||||
uri: string,
|
||||
fn: (res: AppBskyGraphGetList.Response) => boolean,
|
||||
) {
|
||||
|
@ -317,7 +305,7 @@ async function whenAppViewReady(
|
|||
1e3, // 1s delay between tries
|
||||
fn,
|
||||
() =>
|
||||
getAgent().app.bsky.graph.getList({
|
||||
agent.app.bsky.graph.getList({
|
||||
list: uri,
|
||||
limit: 1,
|
||||
}),
|
||||
|
|
|
@ -14,12 +14,12 @@ export function useUpdateActorDeclaration({
|
|||
}) {
|
||||
const queryClient = useQueryClient()
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (allowIncoming: 'all' | 'none' | 'following') => {
|
||||
if (!currentAccount) throw new Error('Not logged in')
|
||||
const result = await getAgent().api.com.atproto.repo.putRecord({
|
||||
const result = await agent.api.com.atproto.repo.putRecord({
|
||||
repo: currentAccount.did,
|
||||
collection: 'chat.bsky.actor.declaration',
|
||||
rkey: 'self',
|
||||
|
@ -64,13 +64,13 @@ export function useUpdateActorDeclaration({
|
|||
// for use in the settings screen for testing
|
||||
export function useDeleteActorDeclaration() {
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async () => {
|
||||
if (!currentAccount) throw new Error('Not logged in')
|
||||
// TODO(sam): remove validate: false once PDSes have the new lexicon
|
||||
const result = await getAgent().api.com.atproto.repo.deleteRecord({
|
||||
const result = await agent.api.com.atproto.repo.deleteRecord({
|
||||
repo: currentAccount.did,
|
||||
collection: 'chat.bsky.actor.declaration',
|
||||
rkey: 'self',
|
||||
|
|
|
@ -11,12 +11,12 @@ const RQKEY_ROOT = 'convo'
|
|||
export const RQKEY = (convoId: string) => [RQKEY_ROOT, convoId]
|
||||
|
||||
export function useConvoQuery(convo: ChatBskyConvoDefs.ConvoView) {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useQuery({
|
||||
queryKey: RQKEY(convo.id),
|
||||
queryFn: async () => {
|
||||
const {data} = await getAgent().api.chat.bsky.convo.getConvo(
|
||||
const {data} = await agent.api.chat.bsky.convo.getConvo(
|
||||
{convoId: convo.id},
|
||||
{headers: DM_SERVICE_HEADERS},
|
||||
)
|
||||
|
@ -30,7 +30,7 @@ export function useConvoQuery(convo: ChatBskyConvoDefs.ConvoView) {
|
|||
export function useMarkAsReadMutation() {
|
||||
const optimisticUpdate = useOnMarkAsRead()
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
|
@ -42,7 +42,7 @@ export function useMarkAsReadMutation() {
|
|||
}) => {
|
||||
if (!convoId) throw new Error('No convoId provided')
|
||||
|
||||
await getAgent().api.chat.bsky.convo.updateRead(
|
||||
await agent.api.chat.bsky.convo.updateRead(
|
||||
{
|
||||
convoId,
|
||||
messageId,
|
||||
|
|
|
@ -18,11 +18,11 @@ export function useGetConvoForMembers({
|
|||
onError?: (error: Error) => void
|
||||
}) {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (members: string[]) => {
|
||||
const {data} = await getAgent().api.chat.bsky.convo.getConvoForMembers(
|
||||
const {data} = await agent.api.chat.bsky.convo.getConvoForMembers(
|
||||
{members: members},
|
||||
{headers: DM_SERVICE_HEADERS},
|
||||
)
|
||||
|
@ -44,16 +44,13 @@ export function useGetConvoForMembers({
|
|||
* Gets the conversation ID for a given DID. Returns null if it's not possible to message them.
|
||||
*/
|
||||
export function useMaybeConvoForUser(did: string) {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useQuery({
|
||||
queryKey: RQKEY(did),
|
||||
queryFn: async () => {
|
||||
const convo = await getAgent()
|
||||
.api.chat.bsky.convo.getConvoForMembers(
|
||||
{members: [did]},
|
||||
{headers: DM_SERVICE_HEADERS},
|
||||
)
|
||||
const convo = await agent.api.chat.bsky.convo
|
||||
.getConvoForMembers({members: [did]}, {headers: DM_SERVICE_HEADERS})
|
||||
.catch(() => ({success: null}))
|
||||
|
||||
if (convo.success) {
|
||||
|
|
|
@ -17,13 +17,13 @@ export function useLeaveConvo(
|
|||
},
|
||||
) {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async () => {
|
||||
if (!convoId) throw new Error('No convoId provided')
|
||||
|
||||
const {data} = await getAgent().api.chat.bsky.convo.leaveConvo(
|
||||
const {data} = await agent.api.chat.bsky.convo.leaveConvo(
|
||||
{convoId},
|
||||
{headers: DM_SERVICE_HEADERS, encoding: 'application/json'},
|
||||
)
|
||||
|
|
|
@ -27,12 +27,12 @@ export const RQKEY = ['convo-list']
|
|||
type RQPageParam = string | undefined
|
||||
|
||||
export function useListConvosQuery() {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useInfiniteQuery({
|
||||
queryKey: RQKEY,
|
||||
queryFn: async ({pageParam}) => {
|
||||
const {data} = await getAgent().api.chat.bsky.convo.listConvos(
|
||||
const {data} = await agent.api.chat.bsky.convo.listConvos(
|
||||
{cursor: pageParam},
|
||||
{headers: DM_SERVICE_HEADERS},
|
||||
)
|
||||
|
|
|
@ -21,13 +21,11 @@ export function useMuteConvo(
|
|||
},
|
||||
) {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({mute}: {mute: boolean}) => {
|
||||
if (!convoId) throw new Error('No convoId provided')
|
||||
|
||||
const agent = getAgent()
|
||||
if (mute) {
|
||||
const {data} = await agent.api.chat.bsky.convo.muteConvo(
|
||||
{convoId},
|
||||
|
|
|
@ -13,7 +13,7 @@ export const RQKEY = () => [RQKEY_ROOT]
|
|||
type RQPageParam = string | undefined
|
||||
|
||||
export function useMyBlockedAccountsQuery() {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useInfiniteQuery<
|
||||
AppBskyGraphGetBlocks.OutputSchema,
|
||||
Error,
|
||||
|
@ -23,7 +23,7 @@ export function useMyBlockedAccountsQuery() {
|
|||
>({
|
||||
queryKey: RQKEY(),
|
||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||
const res = await getAgent().app.bsky.graph.getBlocks({
|
||||
const res = await agent.app.bsky.graph.getBlocks({
|
||||
limit: 30,
|
||||
cursor: pageParam,
|
||||
})
|
||||
|
|
|
@ -16,7 +16,7 @@ export const RQKEY = (filter: MyListsFilter) => [RQKEY_ROOT, filter]
|
|||
|
||||
export function useMyListsQuery(filter: MyListsFilter) {
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useQuery<AppBskyGraphDefs.ListView[]>({
|
||||
staleTime: STALE.MINUTES.ONE,
|
||||
queryKey: RQKEY(filter),
|
||||
|
@ -24,8 +24,8 @@ export function useMyListsQuery(filter: MyListsFilter) {
|
|||
let lists: AppBskyGraphDefs.ListView[] = []
|
||||
const promises = [
|
||||
accumulate(cursor =>
|
||||
getAgent()
|
||||
.app.bsky.graph.getLists({
|
||||
agent.app.bsky.graph
|
||||
.getLists({
|
||||
actor: currentAccount!.did,
|
||||
cursor,
|
||||
limit: 50,
|
||||
|
@ -39,8 +39,8 @@ export function useMyListsQuery(filter: MyListsFilter) {
|
|||
if (filter === 'all-including-subscribed' || filter === 'mod') {
|
||||
promises.push(
|
||||
accumulate(cursor =>
|
||||
getAgent()
|
||||
.app.bsky.graph.getListMutes({
|
||||
agent.app.bsky.graph
|
||||
.getListMutes({
|
||||
cursor,
|
||||
limit: 50,
|
||||
})
|
||||
|
@ -52,8 +52,8 @@ export function useMyListsQuery(filter: MyListsFilter) {
|
|||
)
|
||||
promises.push(
|
||||
accumulate(cursor =>
|
||||
getAgent()
|
||||
.app.bsky.graph.getListBlocks({
|
||||
agent.app.bsky.graph
|
||||
.getListBlocks({
|
||||
cursor,
|
||||
limit: 50,
|
||||
})
|
||||
|
|
|
@ -13,7 +13,7 @@ export const RQKEY = () => [RQKEY_ROOT]
|
|||
type RQPageParam = string | undefined
|
||||
|
||||
export function useMyMutedAccountsQuery() {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useInfiniteQuery<
|
||||
AppBskyGraphGetMutes.OutputSchema,
|
||||
Error,
|
||||
|
@ -23,7 +23,7 @@ export function useMyMutedAccountsQuery() {
|
|||
>({
|
||||
queryKey: RQKEY(),
|
||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||
const res = await getAgent().app.bsky.graph.getMutes({
|
||||
const res = await agent.app.bsky.graph.getMutes({
|
||||
limit: 30,
|
||||
cursor: pageParam,
|
||||
})
|
||||
|
|
|
@ -47,7 +47,7 @@ export function RQKEY() {
|
|||
}
|
||||
|
||||
export function useNotificationFeedQuery(opts?: {enabled?: boolean}) {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const queryClient = useQueryClient()
|
||||
const moderationOpts = useModerationOpts()
|
||||
const threadMutes = useMutedThreads()
|
||||
|
@ -73,7 +73,7 @@ export function useNotificationFeedQuery(opts?: {enabled?: boolean}) {
|
|||
if (!page) {
|
||||
page = (
|
||||
await fetchPage({
|
||||
getAgent,
|
||||
agent,
|
||||
limit: PAGE_SIZE,
|
||||
cursor: pageParam,
|
||||
queryClient,
|
||||
|
|
|
@ -45,7 +45,7 @@ const apiContext = React.createContext<ApiContext>({
|
|||
|
||||
export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
const {hasSession} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const queryClient = useQueryClient()
|
||||
const moderationOpts = useModerationOpts()
|
||||
const threadMutes = useMutedThreads()
|
||||
|
@ -112,7 +112,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
|||
return {
|
||||
async markAllRead() {
|
||||
// update server
|
||||
await getAgent().updateSeenNotifications(
|
||||
await agent.updateSeenNotifications(
|
||||
cacheRef.current.syncedAt.toISOString(),
|
||||
)
|
||||
|
||||
|
@ -127,7 +127,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
|||
isPoll,
|
||||
}: {invalidate?: boolean; isPoll?: boolean} = {}) {
|
||||
try {
|
||||
if (!getAgent().session) return
|
||||
if (!agent.session) return
|
||||
if (AppState.currentState !== 'active') {
|
||||
return
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
|||
|
||||
// count
|
||||
const {page, indexedAt: lastIndexed} = await fetchPage({
|
||||
getAgent,
|
||||
agent,
|
||||
cursor: undefined,
|
||||
limit: 40,
|
||||
queryClient,
|
||||
|
@ -192,7 +192,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
|||
}
|
||||
},
|
||||
}
|
||||
}, [setNumUnread, queryClient, moderationOpts, threadMutes, getAgent])
|
||||
}, [setNumUnread, queryClient, moderationOpts, threadMutes, agent])
|
||||
checkUnreadRef.current = api.checkUnread
|
||||
|
||||
return (
|
||||
|
|
|
@ -23,7 +23,7 @@ const MS_2DAY = MS_1HR * 48
|
|||
// =
|
||||
|
||||
export async function fetchPage({
|
||||
getAgent,
|
||||
agent,
|
||||
cursor,
|
||||
limit,
|
||||
queryClient,
|
||||
|
@ -31,7 +31,7 @@ export async function fetchPage({
|
|||
threadMutes,
|
||||
fetchAdditionalData,
|
||||
}: {
|
||||
getAgent: () => BskyAgent
|
||||
agent: BskyAgent
|
||||
cursor: string | undefined
|
||||
limit: number
|
||||
queryClient: QueryClient
|
||||
|
@ -39,7 +39,7 @@ export async function fetchPage({
|
|||
threadMutes: string[]
|
||||
fetchAdditionalData: boolean
|
||||
}): Promise<{page: FeedPage; indexedAt: string | undefined}> {
|
||||
const res = await getAgent().listNotifications({
|
||||
const res = await agent.listNotifications({
|
||||
limit,
|
||||
cursor,
|
||||
})
|
||||
|
@ -56,7 +56,7 @@ export async function fetchPage({
|
|||
// we fetch subjects of notifications (usually posts) now instead of lazily
|
||||
// in the UI to avoid relayouts
|
||||
if (fetchAdditionalData) {
|
||||
const subjects = await fetchSubjects(getAgent, notifsGrouped)
|
||||
const subjects = await fetchSubjects(agent, notifsGrouped)
|
||||
for (const notif of notifsGrouped) {
|
||||
if (notif.subjectUri) {
|
||||
notif.subject = subjects.get(notif.subjectUri)
|
||||
|
@ -140,7 +140,7 @@ export function groupNotifications(
|
|||
}
|
||||
|
||||
async function fetchSubjects(
|
||||
getAgent: () => BskyAgent,
|
||||
agent: BskyAgent,
|
||||
groupedNotifs: FeedNotification[],
|
||||
): Promise<Map<string, AppBskyFeedDefs.PostView>> {
|
||||
const uris = new Set<string>()
|
||||
|
@ -152,9 +152,7 @@ async function fetchSubjects(
|
|||
const uriChunks = chunk(Array.from(uris), 25)
|
||||
const postsChunks = await Promise.all(
|
||||
uriChunks.map(uris =>
|
||||
getAgent()
|
||||
.app.bsky.feed.getPosts({uris})
|
||||
.then(res => res.data.posts),
|
||||
agent.app.bsky.feed.getPosts({uris}).then(res => res.data.posts),
|
||||
),
|
||||
)
|
||||
const map = new Map<string, AppBskyFeedDefs.PostView>()
|
||||
|
|
|
@ -117,7 +117,7 @@ export function usePostFeedQuery(
|
|||
f => f.pinned && f.value === 'following',
|
||||
) ?? -1
|
||||
const enableFollowingToDiscoverFallback = followingPinnedIndex === 0
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const lastRun = useRef<{
|
||||
data: InfiniteData<FeedPageUnselected>
|
||||
args: typeof selectArgs
|
||||
|
@ -155,7 +155,7 @@ export function usePostFeedQuery(
|
|||
feedDesc,
|
||||
feedParams: params || {},
|
||||
feedTuners,
|
||||
getAgent,
|
||||
agent,
|
||||
// Not in the query key because they don't change:
|
||||
userInterests,
|
||||
// Not in the query key. Reacting to it switching isn't important:
|
||||
|
@ -173,7 +173,7 @@ export function usePostFeedQuery(
|
|||
* moderations happen later, which results in some posts being shown and
|
||||
* some not.
|
||||
*/
|
||||
if (!getAgent().session) {
|
||||
if (!agent.session) {
|
||||
assertSomePostsPassModeration(res.feed)
|
||||
}
|
||||
|
||||
|
@ -397,50 +397,50 @@ function createApi({
|
|||
feedParams,
|
||||
feedTuners,
|
||||
userInterests,
|
||||
getAgent,
|
||||
agent,
|
||||
enableFollowingToDiscoverFallback,
|
||||
}: {
|
||||
feedDesc: FeedDescriptor
|
||||
feedParams: FeedParams
|
||||
feedTuners: FeedTunerFn[]
|
||||
userInterests?: string
|
||||
getAgent: () => BskyAgent
|
||||
agent: BskyAgent
|
||||
enableFollowingToDiscoverFallback: boolean
|
||||
}) {
|
||||
if (feedDesc === 'following') {
|
||||
if (feedParams.mergeFeedEnabled) {
|
||||
return new MergeFeedAPI({
|
||||
getAgent,
|
||||
agent,
|
||||
feedParams,
|
||||
feedTuners,
|
||||
userInterests,
|
||||
})
|
||||
} else {
|
||||
if (enableFollowingToDiscoverFallback) {
|
||||
return new HomeFeedAPI({getAgent, userInterests})
|
||||
return new HomeFeedAPI({agent, userInterests})
|
||||
} else {
|
||||
return new FollowingFeedAPI({getAgent})
|
||||
return new FollowingFeedAPI({agent})
|
||||
}
|
||||
}
|
||||
} else if (feedDesc.startsWith('author')) {
|
||||
const [_, actor, filter] = feedDesc.split('|')
|
||||
return new AuthorFeedAPI({getAgent, feedParams: {actor, filter}})
|
||||
return new AuthorFeedAPI({agent, feedParams: {actor, filter}})
|
||||
} else if (feedDesc.startsWith('likes')) {
|
||||
const [_, actor] = feedDesc.split('|')
|
||||
return new LikesFeedAPI({getAgent, feedParams: {actor}})
|
||||
return new LikesFeedAPI({agent, feedParams: {actor}})
|
||||
} else if (feedDesc.startsWith('feedgen')) {
|
||||
const [_, feed] = feedDesc.split('|')
|
||||
return new CustomFeedAPI({
|
||||
getAgent,
|
||||
agent,
|
||||
feedParams: {feed},
|
||||
userInterests,
|
||||
})
|
||||
} else if (feedDesc.startsWith('list')) {
|
||||
const [_, list] = feedDesc.split('|')
|
||||
return new ListFeedAPI({getAgent, feedParams: {list}})
|
||||
return new ListFeedAPI({agent, feedParams: {list}})
|
||||
} else {
|
||||
// shouldnt happen
|
||||
return new FollowingFeedAPI({getAgent})
|
||||
return new FollowingFeedAPI({agent})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ const RQKEY_ROOT = 'liked-by'
|
|||
export const RQKEY = (resolvedUri: string) => [RQKEY_ROOT, resolvedUri]
|
||||
|
||||
export function useLikedByQuery(resolvedUri: string | undefined) {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useInfiniteQuery<
|
||||
AppBskyFeedGetLikes.OutputSchema,
|
||||
Error,
|
||||
|
@ -26,7 +26,7 @@ export function useLikedByQuery(resolvedUri: string | undefined) {
|
|||
>({
|
||||
queryKey: RQKEY(resolvedUri || ''),
|
||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||
const res = await getAgent().getLikes({
|
||||
const res = await agent.getLikes({
|
||||
uri: resolvedUri || '',
|
||||
limit: PAGE_SIZE,
|
||||
cursor: pageParam,
|
||||
|
|
|
@ -16,7 +16,7 @@ const RQKEY_ROOT = 'post-reposted-by'
|
|||
export const RQKEY = (resolvedUri: string) => [RQKEY_ROOT, resolvedUri]
|
||||
|
||||
export function usePostRepostedByQuery(resolvedUri: string | undefined) {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useInfiniteQuery<
|
||||
AppBskyFeedGetRepostedBy.OutputSchema,
|
||||
Error,
|
||||
|
@ -26,7 +26,7 @@ export function usePostRepostedByQuery(resolvedUri: string | undefined) {
|
|||
>({
|
||||
queryKey: RQKEY(resolvedUri || ''),
|
||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||
const res = await getAgent().getRepostedBy({
|
||||
const res = await agent.getRepostedBy({
|
||||
uri: resolvedUri || '',
|
||||
limit: PAGE_SIZE,
|
||||
cursor: pageParam,
|
||||
|
|
|
@ -68,12 +68,12 @@ export type ThreadModerationCache = WeakMap<ThreadNode, ModerationDecision>
|
|||
|
||||
export function usePostThreadQuery(uri: string | undefined) {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useQuery<ThreadNode, Error>({
|
||||
gcTime: 0,
|
||||
queryKey: RQKEY(uri || ''),
|
||||
async queryFn() {
|
||||
const res = await getAgent().getPostThread({uri: uri!})
|
||||
const res = await agent.getPostThread({uri: uri!})
|
||||
if (res.success) {
|
||||
return responseToThreadNodes(res.data.thread)
|
||||
}
|
||||
|
|
|
@ -14,11 +14,11 @@ const RQKEY_ROOT = 'post'
|
|||
export const RQKEY = (postUri: string) => [RQKEY_ROOT, postUri]
|
||||
|
||||
export function usePostQuery(uri: string | undefined) {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useQuery<AppBskyFeedDefs.PostView>({
|
||||
queryKey: RQKEY(uri || ''),
|
||||
async queryFn() {
|
||||
const res = await getAgent().getPosts({uris: [uri!]})
|
||||
const res = await agent.getPosts({uris: [uri!]})
|
||||
if (res.success && res.data.posts[0]) {
|
||||
return res.data.posts[0]
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ export function usePostQuery(uri: string | undefined) {
|
|||
|
||||
export function useGetPost() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useCallback(
|
||||
async ({uri}: {uri: string}) => {
|
||||
return queryClient.fetchQuery({
|
||||
|
@ -40,13 +40,13 @@ export function useGetPost() {
|
|||
const urip = new AtUri(uri)
|
||||
|
||||
if (!urip.host.startsWith('did:')) {
|
||||
const res = await getAgent().resolveHandle({
|
||||
const res = await agent.resolveHandle({
|
||||
handle: urip.host,
|
||||
})
|
||||
urip.host = res.data.did
|
||||
}
|
||||
|
||||
const res = await getAgent().getPosts({
|
||||
const res = await agent.getPosts({
|
||||
uris: [urip.toString()!],
|
||||
})
|
||||
|
||||
|
@ -58,7 +58,7 @@ export function useGetPost() {
|
|||
},
|
||||
})
|
||||
},
|
||||
[queryClient, getAgent],
|
||||
[queryClient, agent],
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -127,7 +127,7 @@ function usePostLikeMutation(
|
|||
const {currentAccount} = useSession()
|
||||
const queryClient = useQueryClient()
|
||||
const postAuthor = post.author
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useMutation<
|
||||
{uri: string}, // responds with the uri of the like
|
||||
Error,
|
||||
|
@ -154,7 +154,7 @@ function usePostLikeMutation(
|
|||
? toClout(post.likeCount + post.repostCount + post.replyCount)
|
||||
: undefined,
|
||||
})
|
||||
return getAgent().like(uri, cid)
|
||||
return agent.like(uri, cid)
|
||||
},
|
||||
onSuccess() {
|
||||
track('Post:Like')
|
||||
|
@ -165,11 +165,11 @@ function usePostLikeMutation(
|
|||
function usePostUnlikeMutation(
|
||||
logContext: LogEvents['post:unlike']['logContext'],
|
||||
) {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useMutation<void, Error, {postUri: string; likeUri: string}>({
|
||||
mutationFn: ({likeUri}) => {
|
||||
logEvent('post:unlike', {logContext})
|
||||
return getAgent().deleteLike(likeUri)
|
||||
return agent.deleteLike(likeUri)
|
||||
},
|
||||
onSuccess() {
|
||||
track('Post:Unlike')
|
||||
|
@ -238,7 +238,7 @@ export function usePostRepostMutationQueue(
|
|||
function usePostRepostMutation(
|
||||
logContext: LogEvents['post:repost']['logContext'],
|
||||
) {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useMutation<
|
||||
{uri: string}, // responds with the uri of the repost
|
||||
Error,
|
||||
|
@ -246,7 +246,7 @@ function usePostRepostMutation(
|
|||
>({
|
||||
mutationFn: post => {
|
||||
logEvent('post:repost', {logContext})
|
||||
return getAgent().repost(post.uri, post.cid)
|
||||
return agent.repost(post.uri, post.cid)
|
||||
},
|
||||
onSuccess() {
|
||||
track('Post:Repost')
|
||||
|
@ -257,11 +257,11 @@ function usePostRepostMutation(
|
|||
function usePostUnrepostMutation(
|
||||
logContext: LogEvents['post:unrepost']['logContext'],
|
||||
) {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useMutation<void, Error, {postUri: string; repostUri: string}>({
|
||||
mutationFn: ({repostUri}) => {
|
||||
logEvent('post:unrepost', {logContext})
|
||||
return getAgent().deleteRepost(repostUri)
|
||||
return agent.deleteRepost(repostUri)
|
||||
},
|
||||
onSuccess() {
|
||||
track('Post:Unrepost')
|
||||
|
@ -271,10 +271,10 @@ function usePostUnrepostMutation(
|
|||
|
||||
export function usePostDeleteMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useMutation<void, Error, {uri: string}>({
|
||||
mutationFn: async ({uri}) => {
|
||||
await getAgent().deletePost(uri)
|
||||
await agent.deletePost(uri)
|
||||
},
|
||||
onSuccess(data, variables) {
|
||||
updatePostShadow(queryClient, variables.uri, {isDeleted: true})
|
||||
|
|
|
@ -30,15 +30,13 @@ const preferencesQueryKeyRoot = 'getPreferences'
|
|||
export const preferencesQueryKey = [preferencesQueryKeyRoot]
|
||||
|
||||
export function usePreferencesQuery() {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useQuery({
|
||||
staleTime: STALE.SECONDS.FIFTEEN,
|
||||
structuralSharing: replaceEqualDeep,
|
||||
refetchOnWindowFocus: true,
|
||||
queryKey: preferencesQueryKey,
|
||||
queryFn: async () => {
|
||||
const agent = getAgent()
|
||||
|
||||
if (agent.session?.did === undefined) {
|
||||
return DEFAULT_LOGGED_OUT_PREFERENCES
|
||||
} else {
|
||||
|
@ -75,11 +73,11 @@ export function usePreferencesQuery() {
|
|||
|
||||
export function useClearPreferencesMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async () => {
|
||||
await getAgent().app.bsky.actor.putPreferences({preferences: []})
|
||||
await agent.app.bsky.actor.putPreferences({preferences: []})
|
||||
// triggers a refetch
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: preferencesQueryKey,
|
||||
|
@ -89,7 +87,7 @@ export function useClearPreferencesMutation() {
|
|||
}
|
||||
|
||||
export function usePreferencesSetContentLabelMutation() {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation<
|
||||
|
@ -98,7 +96,7 @@ export function usePreferencesSetContentLabelMutation() {
|
|||
{label: string; visibility: LabelPreference; labelerDid: string | undefined}
|
||||
>({
|
||||
mutationFn: async ({label, visibility, labelerDid}) => {
|
||||
await getAgent().setContentLabelPref(label, visibility, labelerDid)
|
||||
await agent.setContentLabelPref(label, visibility, labelerDid)
|
||||
// triggers a refetch
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: preferencesQueryKey,
|
||||
|
@ -109,7 +107,7 @@ export function usePreferencesSetContentLabelMutation() {
|
|||
|
||||
export function useSetContentLabelMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
|
@ -121,7 +119,7 @@ export function useSetContentLabelMutation() {
|
|||
visibility: LabelPreference
|
||||
labelerDid?: string
|
||||
}) => {
|
||||
await getAgent().setContentLabelPref(label, visibility, labelerDid)
|
||||
await agent.setContentLabelPref(label, visibility, labelerDid)
|
||||
// triggers a refetch
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: preferencesQueryKey,
|
||||
|
@ -132,11 +130,11 @@ export function useSetContentLabelMutation() {
|
|||
|
||||
export function usePreferencesSetAdultContentMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation<void, unknown, {enabled: boolean}>({
|
||||
mutationFn: async ({enabled}) => {
|
||||
await getAgent().setAdultContentEnabled(enabled)
|
||||
await agent.setAdultContentEnabled(enabled)
|
||||
// triggers a refetch
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: preferencesQueryKey,
|
||||
|
@ -147,11 +145,11 @@ export function usePreferencesSetAdultContentMutation() {
|
|||
|
||||
export function usePreferencesSetBirthDateMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation<void, unknown, {birthDate: Date}>({
|
||||
mutationFn: async ({birthDate}: {birthDate: Date}) => {
|
||||
await getAgent().setPersonalDetails({birthDate: birthDate.toISOString()})
|
||||
await agent.setPersonalDetails({birthDate: birthDate.toISOString()})
|
||||
// triggers a refetch
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: preferencesQueryKey,
|
||||
|
@ -162,7 +160,7 @@ export function usePreferencesSetBirthDateMutation() {
|
|||
|
||||
export function useSetFeedViewPreferencesMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation<void, unknown, Partial<BskyFeedViewPreference>>({
|
||||
mutationFn: async prefs => {
|
||||
|
@ -170,7 +168,7 @@ export function useSetFeedViewPreferencesMutation() {
|
|||
* special handling here, merged into `feedViewPrefs` above, since
|
||||
* following was previously called `home`
|
||||
*/
|
||||
await getAgent().setFeedViewPrefs('home', prefs)
|
||||
await agent.setFeedViewPrefs('home', prefs)
|
||||
// triggers a refetch
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: preferencesQueryKey,
|
||||
|
@ -181,11 +179,11 @@ export function useSetFeedViewPreferencesMutation() {
|
|||
|
||||
export function useSetThreadViewPreferencesMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation<void, unknown, Partial<ThreadViewPreferences>>({
|
||||
mutationFn: async prefs => {
|
||||
await getAgent().setThreadViewPrefs(prefs)
|
||||
await agent.setThreadViewPrefs(prefs)
|
||||
// triggers a refetch
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: preferencesQueryKey,
|
||||
|
@ -196,11 +194,11 @@ export function useSetThreadViewPreferencesMutation() {
|
|||
|
||||
export function useOverwriteSavedFeedsMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation<void, unknown, AppBskyActorDefs.SavedFeed[]>({
|
||||
mutationFn: async savedFeeds => {
|
||||
await getAgent().overwriteSavedFeeds(savedFeeds)
|
||||
await agent.overwriteSavedFeeds(savedFeeds)
|
||||
// triggers a refetch
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: preferencesQueryKey,
|
||||
|
@ -211,7 +209,7 @@ export function useOverwriteSavedFeedsMutation() {
|
|||
|
||||
export function useAddSavedFeedsMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation<
|
||||
void,
|
||||
|
@ -219,7 +217,7 @@ export function useAddSavedFeedsMutation() {
|
|||
Pick<AppBskyActorDefs.SavedFeed, 'type' | 'value' | 'pinned'>[]
|
||||
>({
|
||||
mutationFn: async savedFeeds => {
|
||||
await getAgent().addSavedFeeds(savedFeeds)
|
||||
await agent.addSavedFeeds(savedFeeds)
|
||||
track('CustomFeed:Save')
|
||||
// triggers a refetch
|
||||
await queryClient.invalidateQueries({
|
||||
|
@ -231,11 +229,11 @@ export function useAddSavedFeedsMutation() {
|
|||
|
||||
export function useRemoveFeedMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation<void, unknown, Pick<AppBskyActorDefs.SavedFeed, 'id'>>({
|
||||
mutationFn: async savedFeed => {
|
||||
await getAgent().removeSavedFeeds([savedFeed.id])
|
||||
await agent.removeSavedFeeds([savedFeed.id])
|
||||
track('CustomFeed:Unsave')
|
||||
// triggers a refetch
|
||||
await queryClient.invalidateQueries({
|
||||
|
@ -247,7 +245,7 @@ export function useRemoveFeedMutation() {
|
|||
|
||||
export function useReplaceForYouWithDiscoverFeedMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
|
@ -258,10 +256,10 @@ export function useReplaceForYouWithDiscoverFeedMutation() {
|
|||
discoverFeedConfig: AppBskyActorDefs.SavedFeed | undefined
|
||||
}) => {
|
||||
if (forYouFeedConfig) {
|
||||
await getAgent().removeSavedFeeds([forYouFeedConfig.id])
|
||||
await agent.removeSavedFeeds([forYouFeedConfig.id])
|
||||
}
|
||||
if (!discoverFeedConfig) {
|
||||
await getAgent().addSavedFeeds([
|
||||
await agent.addSavedFeeds([
|
||||
{
|
||||
type: 'feed',
|
||||
value: PROD_DEFAULT_FEED('whats-hot'),
|
||||
|
@ -269,7 +267,7 @@ export function useReplaceForYouWithDiscoverFeedMutation() {
|
|||
},
|
||||
])
|
||||
} else {
|
||||
await getAgent().updateSavedFeeds([
|
||||
await agent.updateSavedFeeds([
|
||||
{
|
||||
...discoverFeedConfig,
|
||||
pinned: true,
|
||||
|
@ -286,11 +284,11 @@ export function useReplaceForYouWithDiscoverFeedMutation() {
|
|||
|
||||
export function useUpdateSavedFeedsMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation<void, unknown, AppBskyActorDefs.SavedFeed[]>({
|
||||
mutationFn: async feeds => {
|
||||
await getAgent().updateSavedFeeds(feeds)
|
||||
await agent.updateSavedFeeds(feeds)
|
||||
|
||||
// triggers a refetch
|
||||
await queryClient.invalidateQueries({
|
||||
|
@ -302,11 +300,11 @@ export function useUpdateSavedFeedsMutation() {
|
|||
|
||||
export function useUpsertMutedWordsMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (mutedWords: AppBskyActorDefs.MutedWord[]) => {
|
||||
await getAgent().upsertMutedWords(mutedWords)
|
||||
await agent.upsertMutedWords(mutedWords)
|
||||
// triggers a refetch
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: preferencesQueryKey,
|
||||
|
@ -317,11 +315,11 @@ export function useUpsertMutedWordsMutation() {
|
|||
|
||||
export function useUpdateMutedWordMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (mutedWord: AppBskyActorDefs.MutedWord) => {
|
||||
await getAgent().updateMutedWord(mutedWord)
|
||||
await agent.updateMutedWord(mutedWord)
|
||||
// triggers a refetch
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: preferencesQueryKey,
|
||||
|
@ -332,11 +330,11 @@ export function useUpdateMutedWordMutation() {
|
|||
|
||||
export function useRemoveMutedWordMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (mutedWord: AppBskyActorDefs.MutedWord) => {
|
||||
await getAgent().removeMutedWord(mutedWord)
|
||||
await agent.removeMutedWord(mutedWord)
|
||||
// triggers a refetch
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: preferencesQueryKey,
|
||||
|
|
|
@ -15,7 +15,7 @@ export function useProfileFeedgensQuery(
|
|||
opts?: {enabled?: boolean},
|
||||
) {
|
||||
const enabled = opts?.enabled !== false
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useInfiniteQuery<
|
||||
AppBskyFeedGetActorFeeds.OutputSchema,
|
||||
Error,
|
||||
|
@ -25,7 +25,7 @@ export function useProfileFeedgensQuery(
|
|||
>({
|
||||
queryKey: RQKEY(did),
|
||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||
const res = await getAgent().app.bsky.feed.getActorFeeds({
|
||||
const res = await agent.app.bsky.feed.getActorFeeds({
|
||||
actor: did,
|
||||
limit: PAGE_SIZE,
|
||||
cursor: pageParam,
|
||||
|
|
|
@ -15,7 +15,7 @@ const RQKEY_ROOT = 'profile-followers'
|
|||
export const RQKEY = (did: string) => [RQKEY_ROOT, did]
|
||||
|
||||
export function useProfileFollowersQuery(did: string | undefined) {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useInfiniteQuery<
|
||||
AppBskyGraphGetFollowers.OutputSchema,
|
||||
Error,
|
||||
|
@ -25,7 +25,7 @@ export function useProfileFollowersQuery(did: string | undefined) {
|
|||
>({
|
||||
queryKey: RQKEY(did || ''),
|
||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||
const res = await getAgent().app.bsky.graph.getFollowers({
|
||||
const res = await agent.app.bsky.graph.getFollowers({
|
||||
actor: did || '',
|
||||
limit: PAGE_SIZE,
|
||||
cursor: pageParam,
|
||||
|
|
|
@ -26,7 +26,7 @@ export function useProfileFollowsQuery(
|
|||
limit: PAGE_SIZE,
|
||||
},
|
||||
) {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useInfiniteQuery<
|
||||
AppBskyGraphGetFollows.OutputSchema,
|
||||
Error,
|
||||
|
@ -37,7 +37,7 @@ export function useProfileFollowsQuery(
|
|||
staleTime: STALE.MINUTES.ONE,
|
||||
queryKey: RQKEY(did || ''),
|
||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||
const res = await getAgent().app.bsky.graph.getFollows({
|
||||
const res = await agent.app.bsky.graph.getFollows({
|
||||
actor: did || '',
|
||||
limit: limit || PAGE_SIZE,
|
||||
cursor: pageParam,
|
||||
|
|
|
@ -11,7 +11,7 @@ export const RQKEY = (did: string) => [RQKEY_ROOT, did]
|
|||
|
||||
export function useProfileListsQuery(did: string, opts?: {enabled?: boolean}) {
|
||||
const enabled = opts?.enabled !== false
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useInfiniteQuery<
|
||||
AppBskyGraphGetLists.OutputSchema,
|
||||
Error,
|
||||
|
@ -21,7 +21,7 @@ export function useProfileListsQuery(did: string, opts?: {enabled?: boolean}) {
|
|||
>({
|
||||
queryKey: RQKEY(did),
|
||||
async queryFn({pageParam}: {pageParam: RQPageParam}) {
|
||||
const res = await getAgent().app.bsky.graph.getLists({
|
||||
const res = await agent.app.bsky.graph.getLists({
|
||||
actor: did,
|
||||
limit: PAGE_SIZE,
|
||||
cursor: pageParam,
|
||||
|
|
|
@ -52,7 +52,7 @@ export function useProfileQuery({
|
|||
staleTime?: number
|
||||
}) {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useQuery<AppBskyActorDefs.ProfileViewDetailed>({
|
||||
// WARNING
|
||||
// this staleTime is load-bearing
|
||||
|
@ -62,7 +62,7 @@ export function useProfileQuery({
|
|||
refetchOnWindowFocus: true,
|
||||
queryKey: RQKEY(did ?? ''),
|
||||
queryFn: async () => {
|
||||
const res = await getAgent().getProfile({actor: did ?? ''})
|
||||
const res = await agent.getProfile({actor: did ?? ''})
|
||||
return res.data
|
||||
},
|
||||
placeholderData: () => {
|
||||
|
@ -77,31 +77,31 @@ export function useProfileQuery({
|
|||
}
|
||||
|
||||
export function useProfilesQuery({handles}: {handles: string[]}) {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useQuery({
|
||||
staleTime: STALE.MINUTES.FIVE,
|
||||
queryKey: profilesQueryKey(handles),
|
||||
queryFn: async () => {
|
||||
const res = await getAgent().getProfiles({actors: handles})
|
||||
const res = await agent.getProfiles({actors: handles})
|
||||
return res.data
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function usePrefetchProfileQuery() {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const queryClient = useQueryClient()
|
||||
const prefetchProfileQuery = useCallback(
|
||||
async (did: string) => {
|
||||
await queryClient.prefetchQuery({
|
||||
queryKey: RQKEY(did),
|
||||
queryFn: async () => {
|
||||
const res = await getAgent().getProfile({actor: did || ''})
|
||||
const res = await agent.getProfile({actor: did || ''})
|
||||
return res.data
|
||||
},
|
||||
})
|
||||
},
|
||||
[queryClient, getAgent],
|
||||
[queryClient, agent],
|
||||
)
|
||||
return prefetchProfileQuery
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ interface ProfileUpdateParams {
|
|||
}
|
||||
export function useProfileUpdateMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useMutation<void, Error, ProfileUpdateParams>({
|
||||
mutationFn: async ({
|
||||
profile,
|
||||
|
@ -131,7 +131,7 @@ export function useProfileUpdateMutation() {
|
|||
| undefined
|
||||
if (newUserAvatar) {
|
||||
newUserAvatarPromise = uploadBlob(
|
||||
getAgent(),
|
||||
agent,
|
||||
newUserAvatar.path,
|
||||
newUserAvatar.mime,
|
||||
)
|
||||
|
@ -141,12 +141,12 @@ export function useProfileUpdateMutation() {
|
|||
| undefined
|
||||
if (newUserBanner) {
|
||||
newUserBannerPromise = uploadBlob(
|
||||
getAgent(),
|
||||
agent,
|
||||
newUserBanner.path,
|
||||
newUserBanner.mime,
|
||||
)
|
||||
}
|
||||
await getAgent().upsertProfile(async existing => {
|
||||
await agent.upsertProfile(async existing => {
|
||||
existing = existing || {}
|
||||
if (typeof updates === 'function') {
|
||||
existing = updates(existing)
|
||||
|
@ -169,7 +169,7 @@ export function useProfileUpdateMutation() {
|
|||
return existing
|
||||
})
|
||||
await whenAppViewReady(
|
||||
getAgent,
|
||||
agent,
|
||||
profile.did,
|
||||
checkCommitted ||
|
||||
(res => {
|
||||
|
@ -271,7 +271,7 @@ function useProfileFollowMutation(
|
|||
profile: Shadow<AppBskyActorDefs.ProfileViewDetailed>,
|
||||
) {
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation<{uri: string; cid: string}, Error, {did: string}>({
|
||||
mutationFn: async ({did}) => {
|
||||
|
@ -287,7 +287,7 @@ function useProfileFollowMutation(
|
|||
followeeClout: toClout(profile.followersCount),
|
||||
followerClout: toClout(ownProfile?.followersCount),
|
||||
})
|
||||
return await getAgent().follow(did)
|
||||
return await agent.follow(did)
|
||||
},
|
||||
onSuccess(data, variables) {
|
||||
track('Profile:Follow', {username: variables.did})
|
||||
|
@ -298,12 +298,12 @@ function useProfileFollowMutation(
|
|||
function useProfileUnfollowMutation(
|
||||
logContext: LogEvents['profile:unfollow']['logContext'],
|
||||
) {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useMutation<void, Error, {did: string; followUri: string}>({
|
||||
mutationFn: async ({followUri}) => {
|
||||
logEvent('profile:unfollow', {logContext})
|
||||
track('Profile:Unfollow', {username: followUri})
|
||||
return await getAgent().deleteFollow(followUri)
|
||||
return await agent.deleteFollow(followUri)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -359,10 +359,10 @@ export function useProfileMuteMutationQueue(
|
|||
|
||||
function useProfileMuteMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useMutation<void, Error, {did: string}>({
|
||||
mutationFn: async ({did}) => {
|
||||
await getAgent().mute(did)
|
||||
await agent.mute(did)
|
||||
},
|
||||
onSuccess() {
|
||||
queryClient.invalidateQueries({queryKey: RQKEY_MY_MUTED()})
|
||||
|
@ -372,10 +372,10 @@ function useProfileMuteMutation() {
|
|||
|
||||
function useProfileUnmuteMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useMutation<void, Error, {did: string}>({
|
||||
mutationFn: async ({did}) => {
|
||||
await getAgent().unmute(did)
|
||||
await agent.unmute(did)
|
||||
},
|
||||
onSuccess() {
|
||||
queryClient.invalidateQueries({queryKey: RQKEY_MY_MUTED()})
|
||||
|
@ -440,14 +440,14 @@ export function useProfileBlockMutationQueue(
|
|||
|
||||
function useProfileBlockMutation() {
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation<{uri: string; cid: string}, Error, {did: string}>({
|
||||
mutationFn: async ({did}) => {
|
||||
if (!currentAccount) {
|
||||
throw new Error('Not signed in')
|
||||
}
|
||||
return await getAgent().app.bsky.graph.block.create(
|
||||
return await agent.app.bsky.graph.block.create(
|
||||
{repo: currentAccount.did},
|
||||
{subject: did, createdAt: new Date().toISOString()},
|
||||
)
|
||||
|
@ -461,7 +461,7 @@ function useProfileBlockMutation() {
|
|||
|
||||
function useProfileUnblockMutation() {
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation<void, Error, {did: string; blockUri: string}>({
|
||||
mutationFn: async ({blockUri}) => {
|
||||
|
@ -469,7 +469,7 @@ function useProfileUnblockMutation() {
|
|||
throw new Error('Not signed in')
|
||||
}
|
||||
const {rkey} = new AtUri(blockUri)
|
||||
await getAgent().app.bsky.graph.block.delete({
|
||||
await agent.app.bsky.graph.block.delete({
|
||||
repo: currentAccount.did,
|
||||
rkey,
|
||||
})
|
||||
|
@ -489,7 +489,7 @@ export function precacheProfile(
|
|||
}
|
||||
|
||||
async function whenAppViewReady(
|
||||
getAgent: () => BskyAgent,
|
||||
agent: BskyAgent,
|
||||
actor: string,
|
||||
fn: (res: AppBskyActorGetProfile.Response) => boolean,
|
||||
) {
|
||||
|
@ -497,7 +497,7 @@ async function whenAppViewReady(
|
|||
5, // 5 tries
|
||||
1e3, // 1s delay between tries
|
||||
fn,
|
||||
() => getAgent().app.bsky.actor.getProfile({actor}),
|
||||
() => agent.app.bsky.actor.getProfile({actor}),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ export function useResolveUriQuery(uri: string | undefined): UriUseQueryResult {
|
|||
|
||||
export function useResolveDidQuery(didOrHandle: string | undefined) {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
return useQuery<string, Error>({
|
||||
staleTime: STALE.HOURS.ONE,
|
||||
|
@ -34,7 +34,7 @@ export function useResolveDidQuery(didOrHandle: string | undefined) {
|
|||
// Just return the did if it's already one
|
||||
if (didOrHandle.startsWith('did:')) return didOrHandle
|
||||
|
||||
const res = await getAgent().resolveHandle({handle: didOrHandle})
|
||||
const res = await agent.resolveHandle({handle: didOrHandle})
|
||||
return res.data.did
|
||||
},
|
||||
initialData: () => {
|
||||
|
|
|
@ -25,7 +25,7 @@ export function useSearchPostsQuery({
|
|||
sort?: 'top' | 'latest'
|
||||
enabled?: boolean
|
||||
}) {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useInfiniteQuery<
|
||||
AppBskyFeedSearchPosts.OutputSchema,
|
||||
Error,
|
||||
|
@ -35,7 +35,7 @@ export function useSearchPostsQuery({
|
|||
>({
|
||||
queryKey: searchPostsQueryKey({query, sort}),
|
||||
queryFn: async ({pageParam}) => {
|
||||
const res = await getAgent().app.bsky.feed.searchPosts({
|
||||
const res = await agent.app.bsky.feed.searchPosts({
|
||||
q: query,
|
||||
limit: 25,
|
||||
cursor: pageParam,
|
||||
|
|
|
@ -8,7 +8,7 @@ const suggestedFeedsQueryKeyRoot = 'suggestedFeeds'
|
|||
export const suggestedFeedsQueryKey = [suggestedFeedsQueryKeyRoot]
|
||||
|
||||
export function useSuggestedFeedsQuery() {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useInfiniteQuery<
|
||||
AppBskyFeedGetSuggestedFeeds.OutputSchema,
|
||||
Error,
|
||||
|
@ -19,7 +19,7 @@ export function useSuggestedFeedsQuery() {
|
|||
staleTime: STALE.HOURS.ONE,
|
||||
queryKey: suggestedFeedsQueryKey,
|
||||
queryFn: async ({pageParam}) => {
|
||||
const res = await getAgent().app.bsky.feed.getSuggestedFeeds({
|
||||
const res = await agent.app.bsky.feed.getSuggestedFeeds({
|
||||
limit: 10,
|
||||
cursor: pageParam,
|
||||
})
|
||||
|
|
|
@ -33,7 +33,7 @@ const suggestedFollowsByActorQueryKey = (did: string) => [
|
|||
|
||||
export function useSuggestedFollowsQuery() {
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const moderationOpts = useModerationOpts()
|
||||
const {data: preferences} = usePreferencesQuery()
|
||||
|
||||
|
@ -49,7 +49,7 @@ export function useSuggestedFollowsQuery() {
|
|||
queryKey: suggestedFollowsQueryKey,
|
||||
queryFn: async ({pageParam}) => {
|
||||
const contentLangs = getContentLanguages().join(',')
|
||||
const res = await getAgent().app.bsky.actor.getSuggestions(
|
||||
const res = await agent.app.bsky.actor.getSuggestions(
|
||||
{
|
||||
limit: 25,
|
||||
cursor: pageParam,
|
||||
|
@ -94,11 +94,11 @@ export function useSuggestedFollowsQuery() {
|
|||
}
|
||||
|
||||
export function useSuggestedFollowsByActorQuery({did}: {did: string}) {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
return useQuery<AppBskyGraphGetSuggestedFollowsByActor.OutputSchema, Error>({
|
||||
queryKey: suggestedFollowsByActorQueryKey(did),
|
||||
queryFn: async () => {
|
||||
const res = await getAgent().app.bsky.graph.getSuggestedFollowsByActor({
|
||||
const res = await agent.app.bsky.graph.getSuggestedFollowsByActor({
|
||||
actor: did,
|
||||
})
|
||||
return res.data
|
||||
|
|
|
@ -268,17 +268,10 @@ export function useRequireAuth() {
|
|||
)
|
||||
}
|
||||
|
||||
export function useAgent(): {getAgent: () => BskyAgent} {
|
||||
export function useAgent(): BskyAgent {
|
||||
const agent = React.useContext(AgentContext)
|
||||
if (!agent) {
|
||||
throw Error('useAgent() must be below <SessionProvider>.')
|
||||
}
|
||||
return React.useMemo(
|
||||
() => ({
|
||||
getAgent() {
|
||||
return agent
|
||||
},
|
||||
}),
|
||||
[agent],
|
||||
)
|
||||
return agent
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue