Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Move the current agent to a global and reset RQ queries on agent change (#1946)

authored by

Paul Frazee and committed by
GitHub
357c752a 3043b324

+218 -260
+4 -6
src/state/queries/actor-autocomplete.ts
··· 3 3 import {useQuery, useQueryClient} from '@tanstack/react-query' 4 4 5 5 import {logger} from '#/logger' 6 - import {useSession} from '#/state/session' 6 + import {getAgent} from '#/state/session' 7 7 import {useMyFollowsQuery} from '#/state/queries/my-follows' 8 8 import {STALE} from '#/state/queries' 9 9 10 10 export const RQKEY = (prefix: string) => ['actor-autocomplete', prefix] 11 11 12 12 export function useActorAutocompleteQuery(prefix: string) { 13 - const {agent} = useSession() 14 13 const {data: follows, isFetching} = useMyFollowsQuery() 15 14 16 15 return useQuery<AppBskyActorDefs.ProfileViewBasic[]>({ ··· 18 17 queryKey: RQKEY(prefix || ''), 19 18 async queryFn() { 20 19 const res = prefix 21 - ? await agent.searchActorsTypeahead({ 20 + ? await getAgent().searchActorsTypeahead({ 22 21 term: prefix, 23 22 limit: 8, 24 23 }) ··· 32 31 export type ActorAutocompleteFn = ReturnType<typeof useActorAutocompleteFn> 33 32 export function useActorAutocompleteFn() { 34 33 const queryClient = useQueryClient() 35 - const {agent} = useSession() 36 34 const {data: follows} = useMyFollowsQuery() 37 35 38 36 return React.useCallback( ··· 44 42 staleTime: STALE.MINUTES.ONE, 45 43 queryKey: RQKEY(query || ''), 46 44 queryFn: () => 47 - agent.searchActorsTypeahead({ 45 + getAgent().searchActorsTypeahead({ 48 46 term: query, 49 47 limit, 50 48 }), ··· 58 56 59 57 return computeSuggestions(query, follows, res?.data.actors) 60 58 }, 61 - [agent, follows, queryClient], 59 + [follows, queryClient], 62 60 ) 63 61 } 64 62
+4 -7
src/state/queries/app-passwords.ts
··· 1 1 import {ComAtprotoServerCreateAppPassword} from '@atproto/api' 2 2 import {useQuery, useQueryClient, useMutation} from '@tanstack/react-query' 3 3 4 - import {useSession} from '#/state/session' 5 4 import {STALE} from '#/state/queries' 5 + import {getAgent} from '../session' 6 6 7 7 export const RQKEY = () => ['app-passwords'] 8 8 9 9 export function useAppPasswordsQuery() { 10 - const {agent} = useSession() 11 10 return useQuery({ 12 11 staleTime: STALE.MINUTES.ONE, 13 12 queryKey: RQKEY(), 14 13 queryFn: async () => { 15 - const res = await agent.com.atproto.server.listAppPasswords({}) 14 + const res = await getAgent().com.atproto.server.listAppPasswords({}) 16 15 return res.data.passwords 17 16 }, 18 17 }) 19 18 } 20 19 21 20 export function useAppPasswordCreateMutation() { 22 - const {agent} = useSession() 23 21 const queryClient = useQueryClient() 24 22 return useMutation< 25 23 ComAtprotoServerCreateAppPassword.OutputSchema, ··· 28 26 >({ 29 27 mutationFn: async ({name}) => { 30 28 return ( 31 - await agent.com.atproto.server.createAppPassword({ 29 + await getAgent().com.atproto.server.createAppPassword({ 32 30 name, 33 31 }) 34 32 ).data ··· 42 40 } 43 41 44 42 export function useAppPasswordDeleteMutation() { 45 - const {agent} = useSession() 46 43 const queryClient = useQueryClient() 47 44 return useMutation<void, Error, {name: string}>({ 48 45 mutationFn: async ({name}) => { 49 - await agent.com.atproto.server.revokeAppPassword({ 46 + await getAgent().com.atproto.server.revokeAppPassword({ 50 47 name, 51 48 }) 52 49 },
+7 -14
src/state/queries/feed.ts
··· 18 18 import {router} from '#/routes' 19 19 import {sanitizeDisplayName} from '#/lib/strings/display-names' 20 20 import {sanitizeHandle} from '#/lib/strings/handles' 21 - import {useSession} from '#/state/session' 21 + import {getAgent} from '#/state/session' 22 22 import {usePreferencesQuery} from '#/state/queries/preferences' 23 23 import {STALE} from '#/state/queries' 24 24 ··· 136 136 } 137 137 138 138 export function useFeedSourceInfoQuery({uri}: {uri: string}) { 139 - const {agent} = useSession() 140 139 const type = getFeedTypeFromUri(uri) 141 140 142 141 return useQuery({ ··· 146 145 let view: FeedSourceInfo 147 146 148 147 if (type === 'feed') { 149 - const res = await agent.app.bsky.feed.getFeedGenerator({feed: uri}) 148 + const res = await getAgent().app.bsky.feed.getFeedGenerator({feed: uri}) 150 149 view = hydrateFeedGenerator(res.data.view) 151 150 } else { 152 - const res = await agent.app.bsky.graph.getList({ 151 + const res = await getAgent().app.bsky.graph.getList({ 153 152 list: uri, 154 153 limit: 1, 155 154 }) ··· 164 163 export const useGetPopularFeedsQueryKey = ['getPopularFeeds'] 165 164 166 165 export function useGetPopularFeedsQuery() { 167 - const {agent} = useSession() 168 - 169 166 return useInfiniteQuery< 170 167 AppBskyUnspeccedGetPopularFeedGenerators.OutputSchema, 171 168 Error, ··· 175 172 >({ 176 173 queryKey: useGetPopularFeedsQueryKey, 177 174 queryFn: async ({pageParam}) => { 178 - const res = await agent.app.bsky.unspecced.getPopularFeedGenerators({ 175 + const res = await getAgent().app.bsky.unspecced.getPopularFeedGenerators({ 179 176 limit: 10, 180 177 cursor: pageParam, 181 178 }) ··· 187 184 } 188 185 189 186 export function useSearchPopularFeedsMutation() { 190 - const {agent} = useSession() 191 - 192 187 return useMutation({ 193 188 mutationFn: async (query: string) => { 194 - const res = await agent.app.bsky.unspecced.getPopularFeedGenerators({ 189 + const res = await getAgent().app.bsky.unspecced.getPopularFeedGenerators({ 195 190 limit: 10, 196 191 query: query, 197 192 }) ··· 220 215 } 221 216 222 217 export function usePinnedFeedsInfos(): FeedSourceInfo[] { 223 - const {agent} = useSession() 224 218 const queryClient = useQueryClient() 225 219 const [tabs, setTabs] = React.useState<FeedSourceInfo[]>([ 226 220 FOLLOWING_FEED_STUB, ··· 250 244 const type = getFeedTypeFromUri(uri) 251 245 252 246 if (type === 'feed') { 253 - const res = await agent.app.bsky.feed.getFeedGenerator({ 247 + const res = await getAgent().app.bsky.feed.getFeedGenerator({ 254 248 feed: uri, 255 249 }) 256 250 return hydrateFeedGenerator(res.data.view) 257 251 } else { 258 - const res = await agent.app.bsky.graph.getList({ 252 + const res = await getAgent().app.bsky.graph.getList({ 259 253 list: uri, 260 254 limit: 1, 261 255 }) ··· 274 268 275 269 fetchFeedInfo() 276 270 }, [ 277 - agent, 278 271 queryClient, 279 272 setTabs, 280 273 preferences?.feeds?.pinned,
+6 -9
src/state/queries/handle.ts
··· 1 1 import React from 'react' 2 2 import {useQueryClient, useMutation} from '@tanstack/react-query' 3 3 4 - import {useSession} from '#/state/session' 4 + import {getAgent} from '#/state/session' 5 5 import {STALE} from '#/state/queries' 6 6 7 7 const fetchHandleQueryKey = (handleOrDid: string) => ['handle', handleOrDid] 8 8 const fetchDidQueryKey = (handleOrDid: string) => ['did', handleOrDid] 9 9 10 10 export function useFetchHandle() { 11 - const {agent} = useSession() 12 11 const queryClient = useQueryClient() 13 12 14 13 return React.useCallback( ··· 17 16 const res = await queryClient.fetchQuery({ 18 17 staleTime: STALE.MINUTES.FIVE, 19 18 queryKey: fetchHandleQueryKey(handleOrDid), 20 - queryFn: () => agent.getProfile({actor: handleOrDid}), 19 + queryFn: () => getAgent().getProfile({actor: handleOrDid}), 21 20 }) 22 21 return res.data.handle 23 22 } 24 23 return handleOrDid 25 24 }, 26 - [agent, queryClient], 25 + [queryClient], 27 26 ) 28 27 } 29 28 30 29 export function useUpdateHandleMutation() { 31 - const {agent} = useSession() 32 30 const queryClient = useQueryClient() 33 31 34 32 return useMutation({ 35 33 mutationFn: async ({handle}: {handle: string}) => { 36 - await agent.updateHandle({handle}) 34 + await getAgent().updateHandle({handle}) 37 35 }, 38 36 onSuccess(_data, variables) { 39 37 queryClient.invalidateQueries({ ··· 44 42 } 45 43 46 44 export function useFetchDid() { 47 - const {agent} = useSession() 48 45 const queryClient = useQueryClient() 49 46 50 47 return React.useCallback( ··· 55 52 queryFn: async () => { 56 53 let identifier = handleOrDid 57 54 if (!identifier.startsWith('did:')) { 58 - const res = await agent.resolveHandle({handle: identifier}) 55 + const res = await getAgent().resolveHandle({handle: identifier}) 59 56 identifier = res.data.did 60 57 } 61 58 return identifier 62 59 }, 63 60 }) 64 61 }, 65 - [agent, queryClient], 62 + [queryClient], 66 63 ) 67 64 }
+2 -4
src/state/queries/invites.ts
··· 1 1 import {ComAtprotoServerDefs} from '@atproto/api' 2 2 import {useQuery} from '@tanstack/react-query' 3 3 4 - import {useSession} from '#/state/session' 4 + import {getAgent} from '#/state/session' 5 5 import {STALE} from '#/state/queries' 6 6 7 7 function isInviteAvailable(invite: ComAtprotoServerDefs.InviteCode): boolean { ··· 13 13 undefined 14 14 > 15 15 export function useInviteCodesQuery() { 16 - const {agent} = useSession() 17 - 18 16 return useQuery({ 19 17 staleTime: STALE.HOURS.ONE, 20 18 queryKey: ['inviteCodes'], 21 19 queryFn: async () => { 22 - const res = await agent.com.atproto.server.getAccountInviteCodes({}) 20 + const res = await getAgent().com.atproto.server.getAccountInviteCodes({}) 23 21 24 22 if (!res.data?.codes) { 25 23 throw new Error(`useInviteCodesQuery: no codes returned`)
+3 -7
src/state/queries/like.ts
··· 1 1 import {useMutation} from '@tanstack/react-query' 2 2 3 - import {useSession} from '#/state/session' 3 + import {getAgent} from '#/state/session' 4 4 5 5 export function useLikeMutation() { 6 - const {agent} = useSession() 7 - 8 6 return useMutation({ 9 7 mutationFn: async ({uri, cid}: {uri: string; cid: string}) => { 10 - const res = await agent.like(uri, cid) 8 + const res = await getAgent().like(uri, cid) 11 9 return {uri: res.uri} 12 10 }, 13 11 }) 14 12 } 15 13 16 14 export function useUnlikeMutation() { 17 - const {agent} = useSession() 18 - 19 15 return useMutation({ 20 16 mutationFn: async ({uri}: {uri: string}) => { 21 - await agent.deleteLike(uri) 17 + await getAgent().deleteLike(uri) 22 18 }, 23 19 }) 24 20 }
+2 -3
src/state/queries/list-members.ts
··· 1 1 import {AppBskyGraphGetList} from '@atproto/api' 2 2 import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query' 3 3 4 - import {useSession} from '#/state/session' 4 + import {getAgent} from '#/state/session' 5 5 import {STALE} from '#/state/queries' 6 6 7 7 const PAGE_SIZE = 30 ··· 10 10 export const RQKEY = (uri: string) => ['list-members', uri] 11 11 12 12 export function useListMembersQuery(uri: string) { 13 - const {agent} = useSession() 14 13 return useInfiniteQuery< 15 14 AppBskyGraphGetList.OutputSchema, 16 15 Error, ··· 21 20 staleTime: STALE.MINUTES.ONE, 22 21 queryKey: RQKEY(uri), 23 22 async queryFn({pageParam}: {pageParam: RQPageParam}) { 24 - const res = await agent.app.bsky.graph.getList({ 23 + const res = await getAgent().app.bsky.graph.getList({ 25 24 list: uri, 26 25 limit: PAGE_SIZE, 27 26 cursor: pageParam,
+7 -7
src/state/queries/list-memberships.ts
··· 17 17 import {AtUri} from '@atproto/api' 18 18 import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query' 19 19 20 - import {useSession} from '#/state/session' 20 + import {useSession, getAgent} from '#/state/session' 21 21 import {RQKEY as LIST_MEMBERS_RQKEY} from '#/state/queries/list-members' 22 22 import {STALE} from '#/state/queries' 23 23 ··· 38 38 * This API is dangerous! Read the note above! 39 39 */ 40 40 export function useDangerousListMembershipsQuery() { 41 - const {agent, currentAccount} = useSession() 41 + const {currentAccount} = useSession() 42 42 return useQuery<ListMembersip[]>({ 43 43 staleTime: STALE.MINUTES.FIVE, 44 44 queryKey: RQKEY(), ··· 49 49 let cursor 50 50 let arr: ListMembersip[] = [] 51 51 for (let i = 0; i < SANITY_PAGE_LIMIT; i++) { 52 - const res = await agent.app.bsky.graph.listitem.list({ 52 + const res = await getAgent().app.bsky.graph.listitem.list({ 53 53 repo: currentAccount.did, 54 54 limit: PAGE_SIZE, 55 55 cursor, ··· 89 89 } 90 90 91 91 export function useListMembershipAddMutation() { 92 - const {agent, currentAccount} = useSession() 92 + const {currentAccount} = useSession() 93 93 const queryClient = useQueryClient() 94 94 return useMutation< 95 95 {uri: string; cid: string}, ··· 100 100 if (!currentAccount) { 101 101 throw new Error('Not logged in') 102 102 } 103 - const res = await agent.app.bsky.graph.listitem.create( 103 + const res = await getAgent().app.bsky.graph.listitem.create( 104 104 {repo: currentAccount.did}, 105 105 { 106 106 subject: actorDid, ··· 147 147 } 148 148 149 149 export function useListMembershipRemoveMutation() { 150 - const {agent, currentAccount} = useSession() 150 + const {currentAccount} = useSession() 151 151 const queryClient = useQueryClient() 152 152 return useMutation< 153 153 void, ··· 159 159 throw new Error('Not logged in') 160 160 } 161 161 const membershipUrip = new AtUri(membershipUri) 162 - await agent.app.bsky.graph.listitem.delete({ 162 + await getAgent().app.bsky.graph.listitem.delete({ 163 163 repo: currentAccount.did, 164 164 rkey: membershipUrip.rkey, 165 165 })
+25 -24
src/state/queries/list.ts
··· 8 8 import {Image as RNImage} from 'react-native-image-crop-picker' 9 9 import {useQuery, useMutation, useQueryClient} from '@tanstack/react-query' 10 10 import chunk from 'lodash.chunk' 11 - import {useSession} from '../session' 11 + import {useSession, getAgent} from '../session' 12 12 import {invalidate as invalidateMyLists} from './my-lists' 13 13 import {RQKEY as PROFILE_LISTS_RQKEY} from './profile-lists' 14 14 import {uploadBlob} from '#/lib/api' ··· 18 18 export const RQKEY = (uri: string) => ['list', uri] 19 19 20 20 export function useListQuery(uri?: string) { 21 - const {agent} = useSession() 22 21 return useQuery<AppBskyGraphDefs.ListView, Error>({ 23 22 staleTime: STALE.MINUTES.ONE, 24 23 queryKey: RQKEY(uri || ''), ··· 26 25 if (!uri) { 27 26 throw new Error('URI not provided') 28 27 } 29 - const res = await agent.app.bsky.graph.getList({ 28 + const res = await getAgent().app.bsky.graph.getList({ 30 29 list: uri, 31 30 limit: 1, 32 31 }) ··· 43 42 avatar: RNImage | null | undefined 44 43 } 45 44 export function useListCreateMutation() { 46 - const {agent, currentAccount} = useSession() 45 + const {currentAccount} = useSession() 47 46 const queryClient = useQueryClient() 48 47 return useMutation<{uri: string; cid: string}, Error, ListCreateMutateParams>( 49 48 { ··· 65 64 createdAt: new Date().toISOString(), 66 65 } 67 66 if (avatar) { 68 - const blobRes = await uploadBlob(agent, avatar.path, avatar.mime) 67 + const blobRes = await uploadBlob(getAgent(), avatar.path, avatar.mime) 69 68 record.avatar = blobRes.data.blob 70 69 } 71 - const res = await agent.app.bsky.graph.list.create( 70 + const res = await getAgent().app.bsky.graph.list.create( 72 71 { 73 72 repo: currentAccount.did, 74 73 }, ··· 77 76 78 77 // wait for the appview to update 79 78 await whenAppViewReady( 80 - agent, 79 + getAgent(), 81 80 res.uri, 82 81 (v: AppBskyGraphGetList.Response) => { 83 82 return typeof v?.data?.list.uri === 'string' ··· 102 101 avatar: RNImage | null | undefined 103 102 } 104 103 export function useListMetadataMutation() { 105 - const {agent, currentAccount} = useSession() 104 + const {currentAccount} = useSession() 106 105 const queryClient = useQueryClient() 107 106 return useMutation< 108 107 {uri: string; cid: string}, ··· 119 118 } 120 119 121 120 // get the current record 122 - const {value: record} = await agent.app.bsky.graph.list.get({ 121 + const {value: record} = await getAgent().app.bsky.graph.list.get({ 123 122 repo: currentAccount.did, 124 123 rkey, 125 124 }) ··· 128 127 record.name = name 129 128 record.description = description 130 129 if (avatar) { 131 - const blobRes = await uploadBlob(agent, avatar.path, avatar.mime) 130 + const blobRes = await uploadBlob(getAgent(), avatar.path, avatar.mime) 132 131 record.avatar = blobRes.data.blob 133 132 } else if (avatar === null) { 134 133 record.avatar = undefined 135 134 } 136 135 const res = ( 137 - await agent.com.atproto.repo.putRecord({ 136 + await getAgent().com.atproto.repo.putRecord({ 138 137 repo: currentAccount.did, 139 138 collection: 'app.bsky.graph.list', 140 139 rkey, ··· 144 143 145 144 // wait for the appview to update 146 145 await whenAppViewReady( 147 - agent, 146 + getAgent(), 148 147 res.uri, 149 148 (v: AppBskyGraphGetList.Response) => { 150 149 const list = v.data.list ··· 168 167 } 169 168 170 169 export function useListDeleteMutation() { 171 - const {agent, currentAccount} = useSession() 170 + const {currentAccount} = useSession() 172 171 const queryClient = useQueryClient() 173 172 return useMutation<void, Error, {uri: string}>({ 174 173 mutationFn: async ({uri}) => { ··· 179 178 let cursor 180 179 let listitemRecordUris: string[] = [] 181 180 for (let i = 0; i < 100; i++) { 182 - const res = await agent.app.bsky.graph.listitem.list({ 181 + const res = await getAgent().app.bsky.graph.listitem.list({ 183 182 repo: currentAccount.did, 184 183 cursor, 185 184 limit: 100, ··· 210 209 211 210 // apply in chunks 212 211 for (const writesChunk of chunk(writes, 10)) { 213 - await agent.com.atproto.repo.applyWrites({ 212 + await getAgent().com.atproto.repo.applyWrites({ 214 213 repo: currentAccount.did, 215 214 writes: writesChunk, 216 215 }) 217 216 } 218 217 219 218 // wait for the appview to update 220 - await whenAppViewReady(agent, uri, (v: AppBskyGraphGetList.Response) => { 221 - return !v?.success 222 - }) 219 + await whenAppViewReady( 220 + getAgent(), 221 + uri, 222 + (v: AppBskyGraphGetList.Response) => { 223 + return !v?.success 224 + }, 225 + ) 223 226 }, 224 227 onSuccess() { 225 228 invalidateMyLists(queryClient) ··· 232 235 } 233 236 234 237 export function useListMuteMutation() { 235 - const {agent} = useSession() 236 238 const queryClient = useQueryClient() 237 239 return useMutation<void, Error, {uri: string; mute: boolean}>({ 238 240 mutationFn: async ({uri, mute}) => { 239 241 if (mute) { 240 - await agent.muteModList(uri) 242 + await getAgent().muteModList(uri) 241 243 } else { 242 - await agent.unmuteModList(uri) 244 + await getAgent().unmuteModList(uri) 243 245 } 244 246 }, 245 247 onSuccess(data, variables) { ··· 251 253 } 252 254 253 255 export function useListBlockMutation() { 254 - const {agent} = useSession() 255 256 const queryClient = useQueryClient() 256 257 return useMutation<void, Error, {uri: string; block: boolean}>({ 257 258 mutationFn: async ({uri, block}) => { 258 259 if (block) { 259 - await agent.blockModList(uri) 260 + await getAgent().blockModList(uri) 260 261 } else { 261 - await agent.unblockModList(uri) 262 + await getAgent().unblockModList(uri) 262 263 } 263 264 }, 264 265 onSuccess(data, variables) {
+2 -3
src/state/queries/my-blocked-accounts.ts
··· 1 1 import {AppBskyGraphGetBlocks} from '@atproto/api' 2 2 import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query' 3 3 4 - import {useSession} from '#/state/session' 4 + import {getAgent} from '#/state/session' 5 5 import {STALE} from '#/state/queries' 6 6 7 7 export const RQKEY = () => ['my-blocked-accounts'] 8 8 type RQPageParam = string | undefined 9 9 10 10 export function useMyBlockedAccountsQuery() { 11 - const {agent} = useSession() 12 11 return useInfiniteQuery< 13 12 AppBskyGraphGetBlocks.OutputSchema, 14 13 Error, ··· 19 18 staleTime: STALE.MINUTES.ONE, 20 19 queryKey: RQKEY(), 21 20 async queryFn({pageParam}: {pageParam: RQPageParam}) { 22 - const res = await agent.app.bsky.graph.getBlocks({ 21 + const res = await getAgent().app.bsky.graph.getBlocks({ 23 22 limit: 30, 24 23 cursor: pageParam, 25 24 })
+3 -3
src/state/queries/my-follows.ts
··· 1 1 import {AppBskyActorDefs} from '@atproto/api' 2 2 import {useQuery} from '@tanstack/react-query' 3 - import {useSession} from '../session' 3 + import {useSession, getAgent} from '../session' 4 4 import {STALE} from '#/state/queries' 5 5 6 6 // sanity limit is SANITY_PAGE_LIMIT*PAGE_SIZE total records ··· 11 11 export const RQKEY = () => ['my-follows'] 12 12 13 13 export function useMyFollowsQuery() { 14 - const {agent, currentAccount} = useSession() 14 + const {currentAccount} = useSession() 15 15 return useQuery<AppBskyActorDefs.ProfileViewBasic[]>({ 16 16 staleTime: STALE.MINUTES.ONE, 17 17 queryKey: RQKEY(), ··· 22 22 let cursor 23 23 let arr: AppBskyActorDefs.ProfileViewBasic[] = [] 24 24 for (let i = 0; i < SANITY_PAGE_LIMIT; i++) { 25 - const res = await agent.getFollows({ 25 + const res = await getAgent().getFollows({ 26 26 actor: currentAccount.did, 27 27 cursor, 28 28 limit: PAGE_SIZE,
+8 -8
src/state/queries/my-lists.ts
··· 2 2 import {useQuery, QueryClient} from '@tanstack/react-query' 3 3 4 4 import {accumulate} from '#/lib/async/accumulate' 5 - import {useSession} from '#/state/session' 5 + import {useSession, getAgent} from '#/state/session' 6 6 import {STALE} from '#/state/queries' 7 7 8 8 export type MyListsFilter = 'all' | 'curate' | 'mod' 9 9 export const RQKEY = (filter: MyListsFilter) => ['my-lists', filter] 10 10 11 11 export function useMyListsQuery(filter: MyListsFilter) { 12 - const {agent, currentAccount} = useSession() 12 + const {currentAccount} = useSession() 13 13 return useQuery<AppBskyGraphDefs.ListView[]>({ 14 14 staleTime: STALE.MINUTES.ONE, 15 15 queryKey: RQKEY(filter), ··· 17 17 let lists: AppBskyGraphDefs.ListView[] = [] 18 18 const promises = [ 19 19 accumulate(cursor => 20 - agent.app.bsky.graph 21 - .getLists({ 20 + getAgent() 21 + .app.bsky.graph.getLists({ 22 22 actor: currentAccount!.did, 23 23 cursor, 24 24 limit: 50, ··· 32 32 if (filter === 'all' || filter === 'mod') { 33 33 promises.push( 34 34 accumulate(cursor => 35 - agent.app.bsky.graph 36 - .getListMutes({ 35 + getAgent() 36 + .app.bsky.graph.getListMutes({ 37 37 cursor, 38 38 limit: 50, 39 39 }) ··· 45 45 ) 46 46 promises.push( 47 47 accumulate(cursor => 48 - agent.app.bsky.graph 49 - .getListBlocks({ 48 + getAgent() 49 + .app.bsky.graph.getListBlocks({ 50 50 cursor, 51 51 limit: 50, 52 52 })
+2 -3
src/state/queries/my-muted-accounts.ts
··· 1 1 import {AppBskyGraphGetMutes} from '@atproto/api' 2 2 import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query' 3 3 4 - import {useSession} from '#/state/session' 4 + import {getAgent} from '#/state/session' 5 5 import {STALE} from '#/state/queries' 6 6 7 7 export const RQKEY = () => ['my-muted-accounts'] 8 8 type RQPageParam = string | undefined 9 9 10 10 export function useMyMutedAccountsQuery() { 11 - const {agent} = useSession() 12 11 return useInfiniteQuery< 13 12 AppBskyGraphGetMutes.OutputSchema, 14 13 Error, ··· 19 18 staleTime: STALE.MINUTES.ONE, 20 19 queryKey: RQKEY(), 21 20 async queryFn({pageParam}: {pageParam: RQPageParam}) { 22 - const res = await agent.app.bsky.graph.getMutes({ 21 + const res = await getAgent().app.bsky.graph.getMutes({ 23 22 limit: 30, 24 23 cursor: pageParam, 25 24 })
+3 -4
src/state/queries/notifications/feed.ts
··· 8 8 } from '@atproto/api' 9 9 import chunk from 'lodash.chunk' 10 10 import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query' 11 - import {useSession} from '../../session' 11 + import {getAgent} from '../../session' 12 12 import {useModerationOpts} from '../preferences' 13 13 import {shouldFilterNotif} from './util' 14 14 import {useMutedThreads} from '#/state/muted-threads' ··· 49 49 } 50 50 51 51 export function useNotificationFeedQuery(opts?: {enabled?: boolean}) { 52 - const {agent} = useSession() 53 52 const moderationOpts = useModerationOpts() 54 53 const threadMutes = useMutedThreads() 55 54 const enabled = opts?.enabled !== false ··· 64 63 staleTime: STALE.INFINITY, 65 64 queryKey: RQKEY(), 66 65 async queryFn({pageParam}: {pageParam: RQPageParam}) { 67 - const res = await agent.listNotifications({ 66 + const res = await getAgent().listNotifications({ 68 67 limit: PAGE_SIZE, 69 68 cursor: pageParam, 70 69 }) ··· 79 78 80 79 // we fetch subjects of notifications (usually posts) now instead of lazily 81 80 // in the UI to avoid relayouts 82 - const subjects = await fetchSubjects(agent, notifsGrouped) 81 + const subjects = await fetchSubjects(getAgent(), notifsGrouped) 83 82 for (const notif of notifsGrouped) { 84 83 if (notif.subjectUri) { 85 84 notif.subject = subjects.get(notif.subjectUri)
+7 -5
src/state/queries/notifications/unread.tsx
··· 1 1 import React from 'react' 2 2 import * as Notifications from 'expo-notifications' 3 3 import BroadcastChannel from '#/lib/broadcast' 4 - import {useSession} from '#/state/session' 4 + import {useSession, getAgent} from '#/state/session' 5 5 import {useModerationOpts} from '../preferences' 6 6 import {shouldFilterNotif} from './util' 7 7 import {isNative} from '#/platform/detection' ··· 25 25 }) 26 26 27 27 export function Provider({children}: React.PropsWithChildren<{}>) { 28 - const {hasSession, agent} = useSession() 28 + const {hasSession} = useSession() 29 29 const moderationOpts = useModerationOpts() 30 30 31 31 const [numUnread, setNumUnread] = React.useState('') ··· 60 60 return { 61 61 async markAllRead() { 62 62 // update server 63 - await agent.updateSeenNotifications(lastSyncRef.current.toISOString()) 63 + await getAgent().updateSeenNotifications( 64 + lastSyncRef.current.toISOString(), 65 + ) 64 66 65 67 // update & broadcast 66 68 setNumUnread('') ··· 69 71 70 72 async checkUnread() { 71 73 // count 72 - const res = await agent.listNotifications({limit: 40}) 74 + const res = await getAgent().listNotifications({limit: 40}) 73 75 const filtered = res.data.notifications.filter( 74 76 notif => !notif.isRead && !shouldFilterNotif(notif, moderationOpts), 75 77 ) ··· 94 96 broadcast.postMessage({event: num}) 95 97 }, 96 98 } 97 - }, [setNumUnread, agent, moderationOpts]) 99 + }, [setNumUnread, moderationOpts]) 98 100 checkUnreadRef.current = api.checkUnread 99 101 100 102 return (
+2 -2
src/state/queries/post-feed.ts
··· 1 1 import {useCallback, useMemo} from 'react' 2 2 import {AppBskyFeedDefs, AppBskyFeedPost, moderatePost} from '@atproto/api' 3 3 import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query' 4 - import {useSession} from '../session' 4 + import {getAgent} from '../session' 5 5 import {useFeedTuners} from '../preferences/feed-tuners' 6 6 import {FeedTuner, NoopFeedTuner} from 'lib/api/feed-manip' 7 7 import {FeedAPI, ReasonFeedSource} from 'lib/api/feed/types' ··· 66 66 params?: FeedParams, 67 67 opts?: {enabled?: boolean}, 68 68 ) { 69 - const {agent} = useSession() 70 69 const feedTuners = useFeedTuners(feedDesc) 71 70 const enabled = opts?.enabled !== false 72 71 const moderationOpts = useModerationOpts() 72 + const agent = getAgent() 73 73 74 74 const api: FeedAPI = useMemo(() => { 75 75 if (feedDesc === 'home') {
+2 -3
src/state/queries/post-liked-by.ts
··· 1 1 import {AppBskyFeedGetLikes} from '@atproto/api' 2 2 import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query' 3 3 4 - import {useSession} from '#/state/session' 4 + import {getAgent} from '#/state/session' 5 5 import {STALE} from '#/state/queries' 6 6 7 7 const PAGE_SIZE = 30 ··· 11 11 export const RQKEY = (resolvedUri: string) => ['post-liked-by', resolvedUri] 12 12 13 13 export function usePostLikedByQuery(resolvedUri: string | undefined) { 14 - const {agent} = useSession() 15 14 return useInfiniteQuery< 16 15 AppBskyFeedGetLikes.OutputSchema, 17 16 Error, ··· 22 21 staleTime: STALE.MINUTES.ONE, 23 22 queryKey: RQKEY(resolvedUri || ''), 24 23 async queryFn({pageParam}: {pageParam: RQPageParam}) { 25 - const res = await agent.getLikes({ 24 + const res = await getAgent().getLikes({ 26 25 uri: resolvedUri || '', 27 26 limit: PAGE_SIZE, 28 27 cursor: pageParam,
+2 -3
src/state/queries/post-reposted-by.ts
··· 1 1 import {AppBskyFeedGetRepostedBy} from '@atproto/api' 2 2 import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query' 3 3 4 - import {useSession} from '#/state/session' 4 + import {getAgent} from '#/state/session' 5 5 import {STALE} from '#/state/queries' 6 6 7 7 const PAGE_SIZE = 30 ··· 11 11 export const RQKEY = (resolvedUri: string) => ['post-reposted-by', resolvedUri] 12 12 13 13 export function usePostRepostedByQuery(resolvedUri: string | undefined) { 14 - const {agent} = useSession() 15 14 return useInfiniteQuery< 16 15 AppBskyFeedGetRepostedBy.OutputSchema, 17 16 Error, ··· 22 21 staleTime: STALE.MINUTES.ONE, 23 22 queryKey: RQKEY(resolvedUri || ''), 24 23 async queryFn({pageParam}: {pageParam: RQPageParam}) { 25 - const res = await agent.getRepostedBy({ 24 + const res = await getAgent().getRepostedBy({ 26 25 uri: resolvedUri || '', 27 26 limit: PAGE_SIZE, 28 27 cursor: pageParam,
+2 -3
src/state/queries/post-thread.ts
··· 5 5 } from '@atproto/api' 6 6 import {useQuery} from '@tanstack/react-query' 7 7 8 - import {useSession} from '#/state/session' 8 + import {getAgent} from '#/state/session' 9 9 import {UsePreferencesQueryResponse} from '#/state/queries/preferences/types' 10 10 import {STALE} from '#/state/queries' 11 11 ··· 58 58 | ThreadUnknown 59 59 60 60 export function usePostThreadQuery(uri: string | undefined) { 61 - const {agent} = useSession() 62 61 return useQuery<ThreadNode, Error>({ 63 62 staleTime: STALE.MINUTES.ONE, 64 63 queryKey: RQKEY(uri || ''), 65 64 async queryFn() { 66 - const res = await agent.getPostThread({uri: uri!}) 65 + const res = await getAgent().getPostThread({uri: uri!}) 67 66 if (res.success) { 68 67 return responseToThreadNodes(res.data.thread) 69 68 }
+10 -17
src/state/queries/post.ts
··· 2 2 import {AppBskyFeedDefs, AtUri} from '@atproto/api' 3 3 import {useQuery, useMutation, useQueryClient} from '@tanstack/react-query' 4 4 5 - import {useSession} from '#/state/session' 5 + import {getAgent} from '#/state/session' 6 6 import {updatePostShadow} from '#/state/cache/post-shadow' 7 7 import {STALE} from '#/state/queries' 8 8 9 9 export const RQKEY = (postUri: string) => ['post', postUri] 10 10 11 11 export function usePostQuery(uri: string | undefined) { 12 - const {agent} = useSession() 13 12 return useQuery<AppBskyFeedDefs.PostView>({ 14 13 staleTime: STALE.MINUTES.ONE, 15 14 queryKey: RQKEY(uri || ''), 16 15 async queryFn() { 17 - const res = await agent.getPosts({uris: [uri!]}) 16 + const res = await getAgent().getPosts({uris: [uri!]}) 18 17 if (res.success && res.data.posts[0]) { 19 18 return res.data.posts[0] 20 19 } ··· 27 26 28 27 export function useGetPost() { 29 28 const queryClient = useQueryClient() 30 - const {agent} = useSession() 31 29 return React.useCallback( 32 30 async ({uri}: {uri: string}) => { 33 31 return queryClient.fetchQuery({ ··· 37 35 const urip = new AtUri(uri) 38 36 39 37 if (!urip.host.startsWith('did:')) { 40 - const res = await agent.resolveHandle({ 38 + const res = await getAgent().resolveHandle({ 41 39 handle: urip.host, 42 40 }) 43 41 urip.host = res.data.did 44 42 } 45 43 46 - const res = await agent.getPosts({ 44 + const res = await getAgent().getPosts({ 47 45 uris: [urip.toString()!], 48 46 }) 49 47 ··· 55 53 }, 56 54 }) 57 55 }, 58 - [agent, queryClient], 56 + [queryClient], 59 57 ) 60 58 } 61 59 62 60 export function usePostLikeMutation() { 63 - const {agent} = useSession() 64 61 return useMutation< 65 62 {uri: string}, // responds with the uri of the like 66 63 Error, 67 64 {uri: string; cid: string; likeCount: number} // the post's uri, cid, and likes 68 65 >({ 69 - mutationFn: post => agent.like(post.uri, post.cid), 66 + mutationFn: post => getAgent().like(post.uri, post.cid), 70 67 onMutate(variables) { 71 68 // optimistically update the post-shadow 72 69 updatePostShadow(variables.uri, { ··· 91 88 } 92 89 93 90 export function usePostUnlikeMutation() { 94 - const {agent} = useSession() 95 91 return useMutation< 96 92 void, 97 93 Error, 98 94 {postUri: string; likeUri: string; likeCount: number} 99 95 >({ 100 96 mutationFn: async ({likeUri}) => { 101 - await agent.deleteLike(likeUri) 97 + await getAgent().deleteLike(likeUri) 102 98 }, 103 99 onMutate(variables) { 104 100 // optimistically update the post-shadow ··· 118 114 } 119 115 120 116 export function usePostRepostMutation() { 121 - const {agent} = useSession() 122 117 return useMutation< 123 118 {uri: string}, // responds with the uri of the repost 124 119 Error, 125 120 {uri: string; cid: string; repostCount: number} // the post's uri, cid, and reposts 126 121 >({ 127 - mutationFn: post => agent.repost(post.uri, post.cid), 122 + mutationFn: post => getAgent().repost(post.uri, post.cid), 128 123 onMutate(variables) { 129 124 // optimistically update the post-shadow 130 125 updatePostShadow(variables.uri, { ··· 149 144 } 150 145 151 146 export function usePostUnrepostMutation() { 152 - const {agent} = useSession() 153 147 return useMutation< 154 148 void, 155 149 Error, 156 150 {postUri: string; repostUri: string; repostCount: number} 157 151 >({ 158 152 mutationFn: async ({repostUri}) => { 159 - await agent.deleteRepost(repostUri) 153 + await getAgent().deleteRepost(repostUri) 160 154 }, 161 155 onMutate(variables) { 162 156 // optimistically update the post-shadow ··· 176 170 } 177 171 178 172 export function usePostDeleteMutation() { 179 - const {agent} = useSession() 180 173 return useMutation<void, Error, {uri: string}>({ 181 174 mutationFn: async ({uri}) => { 182 - await agent.deletePost(uri) 175 + await getAgent().deletePost(uri) 183 176 }, 184 177 onSuccess(data, variables) { 185 178 updatePostShadow(variables.uri, {isDeleted: true})
+14 -25
src/state/queries/preferences/index.ts
··· 9 9 10 10 import {track} from '#/lib/analytics/analytics' 11 11 import {getAge} from '#/lib/strings/time' 12 - import {useSession} from '#/state/session' 12 + import {useSession, getAgent} from '#/state/session' 13 13 import {DEFAULT_LABEL_PREFERENCES} from '#/state/queries/preferences/moderation' 14 14 import { 15 15 ConfigurableLabelGroup, ··· 31 31 export const usePreferencesQueryKey = ['getPreferences'] 32 32 33 33 export function usePreferencesQuery() { 34 - const {agent, hasSession} = useSession() 34 + const {hasSession} = useSession() 35 35 return useQuery({ 36 36 enabled: hasSession, 37 37 staleTime: STALE.MINUTES.ONE, 38 38 queryKey: usePreferencesQueryKey, 39 39 queryFn: async () => { 40 - const res = await agent.getPreferences() 40 + const res = await getAgent().getPreferences() 41 41 const preferences: UsePreferencesQueryResponse = { 42 42 ...res, 43 43 feeds: { ··· 110 110 } 111 111 112 112 export function useClearPreferencesMutation() { 113 - const {agent} = useSession() 114 113 const queryClient = useQueryClient() 115 114 116 115 return useMutation({ 117 116 mutationFn: async () => { 118 - await agent.app.bsky.actor.putPreferences({preferences: []}) 117 + await getAgent().app.bsky.actor.putPreferences({preferences: []}) 119 118 // triggers a refetch 120 119 await queryClient.invalidateQueries({ 121 120 queryKey: usePreferencesQueryKey, ··· 125 124 } 126 125 127 126 export function usePreferencesSetContentLabelMutation() { 128 - const {agent} = useSession() 129 127 const queryClient = useQueryClient() 130 128 131 129 return useMutation< ··· 134 132 {labelGroup: ConfigurableLabelGroup; visibility: LabelPreference} 135 133 >({ 136 134 mutationFn: async ({labelGroup, visibility}) => { 137 - await agent.setContentLabelPref(labelGroup, visibility) 135 + await getAgent().setContentLabelPref(labelGroup, visibility) 138 136 // triggers a refetch 139 137 await queryClient.invalidateQueries({ 140 138 queryKey: usePreferencesQueryKey, ··· 144 142 } 145 143 146 144 export function usePreferencesSetAdultContentMutation() { 147 - const {agent} = useSession() 148 145 const queryClient = useQueryClient() 149 146 150 147 return useMutation<void, unknown, {enabled: boolean}>({ 151 148 mutationFn: async ({enabled}) => { 152 - await agent.setAdultContentEnabled(enabled) 149 + await getAgent().setAdultContentEnabled(enabled) 153 150 // triggers a refetch 154 151 await queryClient.invalidateQueries({ 155 152 queryKey: usePreferencesQueryKey, ··· 159 156 } 160 157 161 158 export function usePreferencesSetBirthDateMutation() { 162 - const {agent} = useSession() 163 159 const queryClient = useQueryClient() 164 160 165 161 return useMutation<void, unknown, {birthDate: Date}>({ 166 162 mutationFn: async ({birthDate}: {birthDate: Date}) => { 167 - await agent.setPersonalDetails({birthDate}) 163 + await getAgent().setPersonalDetails({birthDate}) 168 164 // triggers a refetch 169 165 await queryClient.invalidateQueries({ 170 166 queryKey: usePreferencesQueryKey, ··· 174 170 } 175 171 176 172 export function useSetFeedViewPreferencesMutation() { 177 - const {agent} = useSession() 178 173 const queryClient = useQueryClient() 179 174 180 175 return useMutation<void, unknown, Partial<BskyFeedViewPreference>>({ 181 176 mutationFn: async prefs => { 182 - await agent.setFeedViewPrefs('home', prefs) 177 + await getAgent().setFeedViewPrefs('home', prefs) 183 178 // triggers a refetch 184 179 await queryClient.invalidateQueries({ 185 180 queryKey: usePreferencesQueryKey, ··· 189 184 } 190 185 191 186 export function useSetThreadViewPreferencesMutation() { 192 - const {agent} = useSession() 193 187 const queryClient = useQueryClient() 194 188 195 189 return useMutation<void, unknown, Partial<ThreadViewPreferences>>({ 196 190 mutationFn: async prefs => { 197 - await agent.setThreadViewPrefs(prefs) 191 + await getAgent().setThreadViewPrefs(prefs) 198 192 // triggers a refetch 199 193 await queryClient.invalidateQueries({ 200 194 queryKey: usePreferencesQueryKey, ··· 204 198 } 205 199 206 200 export function useSetSaveFeedsMutation() { 207 - const {agent} = useSession() 208 201 const queryClient = useQueryClient() 209 202 210 203 return useMutation< ··· 213 206 Pick<UsePreferencesQueryResponse['feeds'], 'saved' | 'pinned'> 214 207 >({ 215 208 mutationFn: async ({saved, pinned}) => { 216 - await agent.setSavedFeeds(saved, pinned) 209 + await getAgent().setSavedFeeds(saved, pinned) 217 210 // triggers a refetch 218 211 await queryClient.invalidateQueries({ 219 212 queryKey: usePreferencesQueryKey, ··· 223 216 } 224 217 225 218 export function useSaveFeedMutation() { 226 - const {agent} = useSession() 227 219 const queryClient = useQueryClient() 228 220 229 221 return useMutation<void, unknown, {uri: string}>({ 230 222 mutationFn: async ({uri}) => { 231 - await agent.addSavedFeed(uri) 223 + await getAgent().addSavedFeed(uri) 232 224 track('CustomFeed:Save') 233 225 // triggers a refetch 234 226 await queryClient.invalidateQueries({ ··· 239 231 } 240 232 241 233 export function useRemoveFeedMutation() { 242 - const {agent} = useSession() 243 234 const queryClient = useQueryClient() 244 235 245 236 return useMutation<void, unknown, {uri: string}>({ 246 237 mutationFn: async ({uri}) => { 247 - await agent.removeSavedFeed(uri) 238 + await getAgent().removeSavedFeed(uri) 248 239 track('CustomFeed:Unsave') 249 240 // triggers a refetch 250 241 await queryClient.invalidateQueries({ ··· 255 246 } 256 247 257 248 export function usePinFeedMutation() { 258 - const {agent} = useSession() 259 249 const queryClient = useQueryClient() 260 250 261 251 return useMutation<void, unknown, {uri: string}>({ 262 252 mutationFn: async ({uri}) => { 263 - await agent.addPinnedFeed(uri) 253 + await getAgent().addPinnedFeed(uri) 264 254 track('CustomFeed:Pin', {uri}) 265 255 // triggers a refetch 266 256 await queryClient.invalidateQueries({ ··· 271 261 } 272 262 273 263 export function useUnpinFeedMutation() { 274 - const {agent} = useSession() 275 264 const queryClient = useQueryClient() 276 265 277 266 return useMutation<void, unknown, {uri: string}>({ 278 267 mutationFn: async ({uri}) => { 279 - await agent.removePinnedFeed(uri) 268 + await getAgent().removePinnedFeed(uri) 280 269 track('CustomFeed:Unpin', {uri}) 281 270 // triggers a refetch 282 271 await queryClient.invalidateQueries({
+3 -4
src/state/queries/profile-extra-info.ts
··· 1 1 import {useQuery} from '@tanstack/react-query' 2 2 3 - import {useSession} from '#/state/session' 3 + import {getAgent} from '#/state/session' 4 4 import {STALE} from '#/state/queries' 5 5 6 6 // TODO refactor invalidate on mutate? ··· 11 11 * is not available in the API's ProfileView 12 12 */ 13 13 export function useProfileExtraInfoQuery(did: string) { 14 - const {agent} = useSession() 15 14 return useQuery({ 16 15 staleTime: STALE.MINUTES.ONE, 17 16 queryKey: RQKEY(did), 18 17 async queryFn() { 19 18 const [listsRes, feedsRes] = await Promise.all([ 20 - agent.app.bsky.graph.getLists({ 19 + getAgent().app.bsky.graph.getLists({ 21 20 actor: did, 22 21 limit: 1, 23 22 }), 24 - agent.app.bsky.feed.getActorFeeds({ 23 + getAgent().app.bsky.feed.getActorFeeds({ 25 24 actor: did, 26 25 limit: 1, 27 26 }),
+2 -3
src/state/queries/profile-feedgens.ts
··· 1 1 import {AppBskyFeedGetActorFeeds} from '@atproto/api' 2 2 import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query' 3 3 4 - import {useSession} from '#/state/session' 4 + import {getAgent} from '#/state/session' 5 5 import {STALE} from '#/state/queries' 6 6 7 7 const PAGE_SIZE = 30 ··· 14 14 did: string, 15 15 opts?: {enabled?: boolean}, 16 16 ) { 17 - const {agent} = useSession() 18 17 const enabled = opts?.enabled !== false 19 18 return useInfiniteQuery< 20 19 AppBskyFeedGetActorFeeds.OutputSchema, ··· 26 25 staleTime: STALE.MINUTES.ONE, 27 26 queryKey: RQKEY(did), 28 27 async queryFn({pageParam}: {pageParam: RQPageParam}) { 29 - const res = await agent.app.bsky.feed.getActorFeeds({ 28 + const res = await getAgent().app.bsky.feed.getActorFeeds({ 30 29 actor: did, 31 30 limit: PAGE_SIZE, 32 31 cursor: pageParam,
+2 -3
src/state/queries/profile-followers.ts
··· 1 1 import {AppBskyGraphGetFollowers} from '@atproto/api' 2 2 import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query' 3 3 4 - import {useSession} from '#/state/session' 4 + import {getAgent} from '#/state/session' 5 5 import {STALE} from '#/state/queries' 6 6 7 7 const PAGE_SIZE = 30 ··· 10 10 export const RQKEY = (did: string) => ['profile-followers', did] 11 11 12 12 export function useProfileFollowersQuery(did: string | undefined) { 13 - const {agent} = useSession() 14 13 return useInfiniteQuery< 15 14 AppBskyGraphGetFollowers.OutputSchema, 16 15 Error, ··· 21 20 staleTime: STALE.MINUTES.FIVE, 22 21 queryKey: RQKEY(did || ''), 23 22 async queryFn({pageParam}: {pageParam: RQPageParam}) { 24 - const res = await agent.app.bsky.graph.getFollowers({ 23 + const res = await getAgent().app.bsky.graph.getFollowers({ 25 24 actor: did || '', 26 25 limit: PAGE_SIZE, 27 26 cursor: pageParam,
+2 -3
src/state/queries/profile-follows.ts
··· 1 1 import {AppBskyGraphGetFollows} from '@atproto/api' 2 2 import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query' 3 3 4 - import {useSession} from '#/state/session' 4 + import {getAgent} from '#/state/session' 5 5 import {STALE} from '#/state/queries' 6 6 7 7 const PAGE_SIZE = 30 ··· 11 11 export const RQKEY = (did: string) => ['profile-follows', did] 12 12 13 13 export function useProfileFollowsQuery(did: string | undefined) { 14 - const {agent} = useSession() 15 14 return useInfiniteQuery< 16 15 AppBskyGraphGetFollows.OutputSchema, 17 16 Error, ··· 22 21 staleTime: STALE.MINUTES.ONE, 23 22 queryKey: RQKEY(did || ''), 24 23 async queryFn({pageParam}: {pageParam: RQPageParam}) { 25 - const res = await agent.app.bsky.graph.getFollows({ 24 + const res = await getAgent().app.bsky.graph.getFollows({ 26 25 actor: did || '', 27 26 limit: PAGE_SIZE, 28 27 cursor: pageParam,
+2 -3
src/state/queries/profile-lists.ts
··· 1 1 import {AppBskyGraphGetLists} from '@atproto/api' 2 2 import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query' 3 3 4 - import {useSession} from '#/state/session' 4 + import {getAgent} from '#/state/session' 5 5 import {STALE} from '#/state/queries' 6 6 7 7 const PAGE_SIZE = 30 ··· 10 10 export const RQKEY = (did: string) => ['profile-lists', did] 11 11 12 12 export function useProfileListsQuery(did: string, opts?: {enabled?: boolean}) { 13 - const {agent} = useSession() 14 13 const enabled = opts?.enabled !== false 15 14 return useInfiniteQuery< 16 15 AppBskyGraphGetLists.OutputSchema, ··· 22 21 staleTime: STALE.MINUTES.ONE, 23 22 queryKey: RQKEY(did), 24 23 async queryFn({pageParam}: {pageParam: RQPageParam}) { 25 - const res = await agent.app.bsky.graph.getLists({ 24 + const res = await getAgent().app.bsky.graph.getLists({ 26 25 actor: did, 27 26 limit: PAGE_SIZE, 28 27 cursor: pageParam,
+14 -20
src/state/queries/profile.ts
··· 8 8 } from '@atproto/api' 9 9 import {useQuery, useQueryClient, useMutation} from '@tanstack/react-query' 10 10 import {Image as RNImage} from 'react-native-image-crop-picker' 11 - import {useSession} from '../session' 11 + import {useSession, getAgent} from '../session' 12 12 import {updateProfileShadow} from '../cache/profile-shadow' 13 13 import {uploadBlob} from '#/lib/api' 14 14 import {until} from '#/lib/async/until' ··· 21 21 export const RQKEY = (did: string) => ['profile', did] 22 22 23 23 export function useProfileQuery({did}: {did: string | undefined}) { 24 - const {agent} = useSession() 25 24 return useQuery({ 26 25 staleTime: STALE.MINUTES.FIVE, 27 26 queryKey: RQKEY(did || ''), 28 27 queryFn: async () => { 29 - const res = await agent.getProfile({actor: did || ''}) 28 + const res = await getAgent().getProfile({actor: did || ''}) 30 29 return res.data 31 30 }, 32 31 enabled: !!did, ··· 40 39 newUserBanner: RNImage | undefined | null 41 40 } 42 41 export function useProfileUpdateMutation() { 43 - const {agent} = useSession() 44 42 const queryClient = useQueryClient() 45 43 return useMutation<void, Error, ProfileUpdateParams>({ 46 44 mutationFn: async ({profile, updates, newUserAvatar, newUserBanner}) => { 47 - await agent.upsertProfile(async existing => { 45 + await getAgent().upsertProfile(async existing => { 48 46 existing = existing || {} 49 47 existing.displayName = updates.displayName 50 48 existing.description = updates.description 51 49 if (newUserAvatar) { 52 50 const res = await uploadBlob( 53 - agent, 51 + getAgent(), 54 52 newUserAvatar.path, 55 53 newUserAvatar.mime, 56 54 ) ··· 60 58 } 61 59 if (newUserBanner) { 62 60 const res = await uploadBlob( 63 - agent, 61 + getAgent(), 64 62 newUserBanner.path, 65 63 newUserBanner.mime, 66 64 ) ··· 70 68 } 71 69 return existing 72 70 }) 73 - await whenAppViewReady(agent, profile.did, res => { 71 + await whenAppViewReady(getAgent(), profile.did, res => { 74 72 if (typeof newUserAvatar !== 'undefined') { 75 73 if (newUserAvatar === null && res.data.avatar) { 76 74 // url hasnt cleared yet ··· 160 158 } 161 159 162 160 function useProfileFollowMutation() { 163 - const {agent} = useSession() 164 161 return useMutation< 165 162 {uri: string; cid: string}, 166 163 Error, 167 164 {did: string; skipOptimistic?: boolean} 168 165 >({ 169 166 mutationFn: async ({did}) => { 170 - return await agent.follow(did) 167 + return await getAgent().follow(did) 171 168 }, 172 169 onMutate(variables) { 173 170 if (!variables.skipOptimistic) { ··· 197 194 } 198 195 199 196 function useProfileUnfollowMutation() { 200 - const {agent} = useSession() 201 197 return useMutation< 202 198 void, 203 199 Error, 204 200 {did: string; followUri: string; skipOptimistic?: boolean} 205 201 >({ 206 202 mutationFn: async ({followUri}) => { 207 - return await agent.deleteFollow(followUri) 203 + return await getAgent().deleteFollow(followUri) 208 204 }, 209 205 onMutate(variables) { 210 206 if (!variables.skipOptimistic) { ··· 276 272 } 277 273 278 274 function useProfileMuteMutation() { 279 - const {agent} = useSession() 280 275 const queryClient = useQueryClient() 281 276 return useMutation<void, Error, {did: string; skipOptimistic?: boolean}>({ 282 277 mutationFn: async ({did}) => { 283 - await agent.mute(did) 278 + await getAgent().mute(did) 284 279 }, 285 280 onMutate(variables) { 286 281 if (!variables.skipOptimistic) { ··· 305 300 } 306 301 307 302 function useProfileUnmuteMutation() { 308 - const {agent} = useSession() 309 303 const queryClient = useQueryClient() 310 304 return useMutation<void, Error, {did: string; skipOptimistic?: boolean}>({ 311 305 mutationFn: async ({did}) => { 312 - await agent.unmute(did) 306 + await getAgent().unmute(did) 313 307 }, 314 308 onMutate(variables) { 315 309 if (!variables.skipOptimistic) { ··· 389 383 } 390 384 391 385 function useProfileBlockMutation() { 392 - const {agent, currentAccount} = useSession() 386 + const {currentAccount} = useSession() 393 387 const queryClient = useQueryClient() 394 388 return useMutation< 395 389 {uri: string; cid: string}, ··· 400 394 if (!currentAccount) { 401 395 throw new Error('Not signed in') 402 396 } 403 - return await agent.app.bsky.graph.block.create( 397 + return await getAgent().app.bsky.graph.block.create( 404 398 {repo: currentAccount.did}, 405 399 {subject: did, createdAt: new Date().toISOString()}, 406 400 ) ··· 434 428 } 435 429 436 430 function useProfileUnblockMutation() { 437 - const {agent, currentAccount} = useSession() 431 + const {currentAccount} = useSession() 438 432 return useMutation< 439 433 void, 440 434 Error, ··· 445 439 throw new Error('Not signed in') 446 440 } 447 441 const {rkey} = new AtUri(blockUri) 448 - await agent.app.bsky.graph.block.delete({ 442 + await getAgent().app.bsky.graph.block.delete({ 449 443 repo: currentAccount.did, 450 444 rkey, 451 445 })
+2 -3
src/state/queries/resolve-uri.ts
··· 1 1 import {useQuery} from '@tanstack/react-query' 2 2 import {AtUri} from '@atproto/api' 3 3 4 - import {useSession} from '#/state/session' 4 + import {getAgent} from '#/state/session' 5 5 import {STALE} from '#/state/queries' 6 6 7 7 export const RQKEY = (uri: string) => ['resolved-uri', uri] 8 8 9 9 export function useResolveUriQuery(uri: string | undefined) { 10 - const {agent} = useSession() 11 10 return useQuery<{uri: string; did: string}, Error>({ 12 11 staleTime: STALE.INFINITY, 13 12 queryKey: RQKEY(uri || ''), 14 13 async queryFn() { 15 14 const urip = new AtUri(uri || '') 16 15 if (!urip.host.startsWith('did:')) { 17 - const res = await agent.resolveHandle({handle: urip.host}) 16 + const res = await getAgent().resolveHandle({handle: urip.host}) 18 17 urip.host = res.data.did 19 18 } 20 19 return {did: urip.host, uri: urip.toString()}
+2 -4
src/state/queries/search-posts.ts
··· 1 1 import {AppBskyFeedSearchPosts} from '@atproto/api' 2 2 import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query' 3 3 4 - import {useSession} from '#/state/session' 4 + import {getAgent} from '#/state/session' 5 5 6 6 const searchPostsQueryKey = ({query}: {query: string}) => [ 7 7 'search-posts', ··· 9 9 ] 10 10 11 11 export function useSearchPostsQuery({query}: {query: string}) { 12 - const {agent} = useSession() 13 - 14 12 return useInfiniteQuery< 15 13 AppBskyFeedSearchPosts.OutputSchema, 16 14 Error, ··· 20 18 >({ 21 19 queryKey: searchPostsQueryKey({query}), 22 20 queryFn: async () => { 23 - const res = await agent.app.bsky.feed.searchPosts({ 21 + const res = await getAgent().app.bsky.feed.searchPosts({ 24 22 q: query, 25 23 limit: 25, 26 24 })
+2 -4
src/state/queries/suggested-feeds.ts
··· 1 1 import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query' 2 2 import {AppBskyFeedGetSuggestedFeeds} from '@atproto/api' 3 3 4 - import {useSession} from '#/state/session' 4 + import {getAgent} from '#/state/session' 5 5 import {STALE} from '#/state/queries' 6 6 7 7 export const suggestedFeedsQueryKey = ['suggestedFeeds'] 8 8 9 9 export function useSuggestedFeedsQuery() { 10 - const {agent} = useSession() 11 - 12 10 return useInfiniteQuery< 13 11 AppBskyFeedGetSuggestedFeeds.OutputSchema, 14 12 Error, ··· 19 17 staleTime: STALE.HOURS.ONE, 20 18 queryKey: suggestedFeedsQueryKey, 21 19 queryFn: async ({pageParam}) => { 22 - const res = await agent.app.bsky.feed.getSuggestedFeeds({ 20 + const res = await getAgent().app.bsky.feed.getSuggestedFeeds({ 23 21 limit: 10, 24 22 cursor: pageParam, 25 23 })
+9 -11
src/state/queries/suggested-follows.ts
··· 12 12 QueryKey, 13 13 } from '@tanstack/react-query' 14 14 15 - import {useSession} from '#/state/session' 15 + import {useSession, getAgent} from '#/state/session' 16 16 import {useModerationOpts} from '#/state/queries/preferences' 17 17 import {STALE} from '#/state/queries' 18 18 ··· 23 23 ] 24 24 25 25 export function useSuggestedFollowsQuery() { 26 - const {agent, currentAccount} = useSession() 26 + const {currentAccount} = useSession() 27 27 const moderationOpts = useModerationOpts() 28 28 29 29 return useInfiniteQuery< ··· 37 37 staleTime: STALE.HOURS.ONE, 38 38 queryKey: suggestedFollowsQueryKey, 39 39 queryFn: async ({pageParam}) => { 40 - const res = await agent.app.bsky.actor.getSuggestions({ 40 + const res = await getAgent().app.bsky.actor.getSuggestions({ 41 41 limit: 25, 42 42 cursor: pageParam, 43 43 }) ··· 73 73 } 74 74 75 75 export function useSuggestedFollowsByActorQuery({did}: {did: string}) { 76 - const {agent} = useSession() 77 - 78 76 return useQuery<AppBskyGraphGetSuggestedFollowsByActor.OutputSchema, Error>({ 79 77 queryKey: suggestedFollowsByActorQueryKey(did), 80 78 queryFn: async () => { 81 - const res = await agent.app.bsky.graph.getSuggestedFollowsByActor({ 79 + const res = await getAgent().app.bsky.graph.getSuggestedFollowsByActor({ 82 80 actor: did, 83 81 }) 84 82 return res.data ··· 87 85 } 88 86 89 87 export function useGetSuggestedFollowersByActor() { 90 - const {agent} = useSession() 91 88 const queryClient = useQueryClient() 92 89 93 90 return React.useCallback( ··· 96 93 staleTime: 60 * 1000, 97 94 queryKey: suggestedFollowsByActorQueryKey(actor), 98 95 queryFn: async () => { 99 - const res = await agent.app.bsky.graph.getSuggestedFollowsByActor({ 100 - actor: actor, 101 - }) 96 + const res = 97 + await getAgent().app.bsky.graph.getSuggestedFollowsByActor({ 98 + actor: actor, 99 + }) 102 100 return res.data 103 101 }, 104 102 }) 105 103 106 104 return res 107 105 }, 108 - [agent, queryClient], 106 + [queryClient], 109 107 ) 110 108 }
+20 -11
src/state/session/index.tsx
··· 1 1 import React from 'react' 2 2 import {BskyAgent, AtpPersistSessionHandler} from '@atproto/api' 3 + import {useQueryClient} from '@tanstack/react-query' 3 4 4 5 import {networkRetry} from '#/lib/async/retry' 5 6 import {logger} from '#/logger' ··· 8 9 import {IS_PROD} from '#/lib/constants' 9 10 import {emitSessionLoaded, emitSessionDropped} from '../events' 10 11 12 + let __globalAgent: BskyAgent = PUBLIC_BSKY_AGENT 13 + 14 + export function getAgent() { 15 + return __globalAgent 16 + } 17 + 11 18 export type SessionAccount = persisted.PersistedAccount 12 19 13 20 export type SessionState = { 14 - agent: BskyAgent 15 21 isInitialLoad: boolean 16 22 isSwitchingAccounts: boolean 17 23 accounts: SessionAccount[] ··· 48 54 } 49 55 50 56 const StateContext = React.createContext<StateContext>({ 51 - agent: PUBLIC_BSKY_AGENT, 52 57 isInitialLoad: true, 53 58 isSwitchingAccounts: false, 54 59 accounts: [], ··· 110 115 } 111 116 112 117 export function Provider({children}: React.PropsWithChildren<{}>) { 118 + const queryClient = useQueryClient() 113 119 const isDirty = React.useRef(false) 114 120 const [state, setState] = React.useState<SessionState>({ 115 - agent: PUBLIC_BSKY_AGENT, 116 121 isInitialLoad: true, // try to resume the session first 117 122 isSwitchingAccounts: false, 118 123 accounts: persisted.get('session').accounts, ··· 180 185 }), 181 186 ) 182 187 183 - setState(s => ({...s, agent})) 188 + __globalAgent = agent 189 + queryClient.clear() 184 190 upsertAccount(account) 185 191 emitSessionLoaded(account, agent) 186 192 ··· 193 199 logger.DebugContext.session, 194 200 ) 195 201 }, 196 - [upsertAccount], 202 + [upsertAccount, queryClient], 197 203 ) 198 204 199 205 const login = React.useCallback<ApiContext['login']>( ··· 231 237 }), 232 238 ) 233 239 234 - setState(s => ({...s, agent})) 240 + __globalAgent = agent 241 + queryClient.clear() 235 242 upsertAccount(account) 236 243 emitSessionLoaded(account, agent) 237 244 ··· 244 251 logger.DebugContext.session, 245 252 ) 246 253 }, 247 - [upsertAccount], 254 + [upsertAccount, queryClient], 248 255 ) 249 256 250 257 const logout = React.useCallback<ApiContext['logout']>(async () => { ··· 308 315 accessJwt: agent.session.accessJwt, 309 316 } 310 317 311 - setState(s => ({...s, agent})) 318 + __globalAgent = agent 319 + queryClient.clear() 312 320 upsertAccount(freshAccount) 313 321 emitSessionLoaded(freshAccount, agent) 314 322 }, 315 - [upsertAccount], 323 + [upsertAccount, queryClient], 316 324 ) 317 325 318 326 const resumeSession = React.useCallback<ApiContext['resumeSession']>( ··· 399 407 * back to the sign-in page. 400 408 */ 401 409 const clearCurrentAccount = React.useCallback(() => { 410 + __globalAgent = PUBLIC_BSKY_AGENT 411 + queryClient.clear() 402 412 setStateAndPersist(s => ({ 403 413 ...s, 404 - agent: PUBLIC_BSKY_AGENT, 405 414 currentAccount: undefined, 406 415 })) 407 - }, [setStateAndPersist]) 416 + }, [setStateAndPersist, queryClient]) 408 417 409 418 React.useEffect(() => { 410 419 if (isDirty.current) {
+3 -3
src/view/com/composer/Composer.tsx
··· 56 56 useLanguagePrefsApi, 57 57 toPostLanguages, 58 58 } from '#/state/preferences/languages' 59 - import {useSession} from '#/state/session' 59 + import {useSession, getAgent} from '#/state/session' 60 60 import {useProfileQuery} from '#/state/queries/profile' 61 61 import {useComposerControls} from '#/state/shell/composer' 62 62 ··· 67 67 quote: initQuote, 68 68 mention: initMention, 69 69 }: Props) { 70 - const {agent, currentAccount} = useSession() 70 + const {currentAccount} = useSession() 71 71 const {data: currentProfile} = useProfileQuery({did: currentAccount!.did}) 72 72 const {activeModals} = useModals() 73 73 const {openModal, closeModal} = useModalControls() ··· 209 209 setIsProcessing(true) 210 210 211 211 try { 212 - await apilib.post(agent, { 212 + await apilib.post(getAgent(), { 213 213 rawText: richtext.text, 214 214 replyTo: replyTo?.uri, 215 215 images: gallery.images,
+5 -6
src/view/com/composer/useExternalLinkFetch.ts
··· 16 16 import {ComposerOpts} from 'state/shell/composer' 17 17 import {POST_IMG_MAX} from 'lib/constants' 18 18 import {logger} from '#/logger' 19 - import {useSession} from '#/state/session' 19 + import {getAgent} from '#/state/session' 20 20 import {useGetPost} from '#/state/queries/post' 21 21 22 22 export function useExternalLinkFetch({ ··· 24 24 }: { 25 25 setQuote: (opts: ComposerOpts['quote']) => void 26 26 }) { 27 - const {agent} = useSession() 28 27 const [extLink, setExtLink] = useState<apilib.ExternalEmbedDraft | undefined>( 29 28 undefined, 30 29 ) ··· 56 55 }, 57 56 ) 58 57 } else if (isBskyCustomFeedUrl(extLink.uri)) { 59 - getFeedAsEmbed(agent, extLink.uri).then( 58 + getFeedAsEmbed(getAgent(), extLink.uri).then( 60 59 ({embed, meta}) => { 61 60 if (aborted) { 62 61 return ··· 74 73 }, 75 74 ) 76 75 } else if (isBskyListUrl(extLink.uri)) { 77 - getListAsEmbed(agent, extLink.uri).then( 76 + getListAsEmbed(getAgent(), extLink.uri).then( 78 77 ({embed, meta}) => { 79 78 if (aborted) { 80 79 return ··· 92 91 }, 93 92 ) 94 93 } else { 95 - getLinkMeta(agent, extLink.uri).then(meta => { 94 + getLinkMeta(getAgent(), extLink.uri).then(meta => { 96 95 if (aborted) { 97 96 return 98 97 } ··· 134 133 }) 135 134 } 136 135 return cleanup 137 - }, [agent, extLink, setQuote, getPost]) 136 + }, [extLink, setQuote, getPost]) 138 137 139 138 return {extLink, setExtLink} 140 139 }
+5 -5
src/view/com/modals/ChangeEmail.tsx
··· 13 13 import {Trans, msg} from '@lingui/macro' 14 14 import {useLingui} from '@lingui/react' 15 15 import {useModalControls} from '#/state/modals' 16 - import {useSession, useSessionApi} from '#/state/session' 16 + import {useSession, useSessionApi, getAgent} from '#/state/session' 17 17 18 18 enum Stages { 19 19 InputEmail, ··· 25 25 26 26 export function Component() { 27 27 const pal = usePalette('default') 28 - const {agent, currentAccount} = useSession() 28 + const {currentAccount} = useSession() 29 29 const {updateCurrentAccount} = useSessionApi() 30 30 const {_} = useLingui() 31 31 const [stage, setStage] = useState<Stages>(Stages.InputEmail) ··· 44 44 setError('') 45 45 setIsProcessing(true) 46 46 try { 47 - const res = await agent.com.atproto.server.requestEmailUpdate() 47 + const res = await getAgent().com.atproto.server.requestEmailUpdate() 48 48 if (res.data.tokenRequired) { 49 49 setStage(Stages.ConfirmCode) 50 50 } else { 51 - await agent.com.atproto.server.updateEmail({email: email.trim()}) 51 + await getAgent().com.atproto.server.updateEmail({email: email.trim()}) 52 52 updateCurrentAccount({ 53 53 email: email.trim(), 54 54 emailConfirmed: false, ··· 77 77 setError('') 78 78 setIsProcessing(true) 79 79 try { 80 - await agent.com.atproto.server.updateEmail({ 80 + await getAgent().com.atproto.server.updateEmail({ 81 81 email: email.trim(), 82 82 token: confirmationCode.trim(), 83 83 })
+8 -3
src/view/com/modals/ChangeHandle.tsx
··· 26 26 import {useModalControls} from '#/state/modals' 27 27 import {useServiceQuery} from '#/state/queries/service' 28 28 import {useUpdateHandleMutation, useFetchDid} from '#/state/queries/handle' 29 - import {useSession, useSessionApi, SessionAccount} from '#/state/session' 29 + import { 30 + useSession, 31 + useSessionApi, 32 + SessionAccount, 33 + getAgent, 34 + } from '#/state/session' 30 35 31 36 export const snapPoints = ['100%'] 32 37 33 38 export type Props = {onChanged: () => void} 34 39 35 40 export function Component(props: Props) { 36 - const {agent, currentAccount} = useSession() 41 + const {currentAccount} = useSession() 37 42 const { 38 43 isLoading, 39 44 data: serviceInfo, 40 45 error: serviceInfoError, 41 - } = useServiceQuery(agent.service.toString()) 46 + } = useServiceQuery(getAgent().service.toString()) 42 47 43 48 return isLoading || !currentAccount ? ( 44 49 <View style={{padding: 18}}>
+4 -4
src/view/com/modals/DeleteAccount.tsx
··· 19 19 import {Trans, msg} from '@lingui/macro' 20 20 import {useLingui} from '@lingui/react' 21 21 import {useModalControls} from '#/state/modals' 22 - import {useSession, useSessionApi} from '#/state/session' 22 + import {useSession, useSessionApi, getAgent} from '#/state/session' 23 23 24 24 export const snapPoints = ['60%'] 25 25 26 26 export function Component({}: {}) { 27 27 const pal = usePalette('default') 28 28 const theme = useTheme() 29 - const {agent, currentAccount} = useSession() 29 + const {currentAccount} = useSession() 30 30 const {clearCurrentAccount, removeAccount} = useSessionApi() 31 31 const {_} = useLingui() 32 32 const {closeModal} = useModalControls() ··· 40 40 setError('') 41 41 setIsProcessing(true) 42 42 try { 43 - await agent.com.atproto.server.requestAccountDelete() 43 + await getAgent().com.atproto.server.requestAccountDelete() 44 44 setIsEmailSent(true) 45 45 } catch (e: any) { 46 46 setError(cleanError(e)) ··· 57 57 const token = confirmCode.replace(/\s/g, '') 58 58 59 59 try { 60 - await agent.com.atproto.server.deleteAccount({ 60 + await getAgent().com.atproto.server.deleteAccount({ 61 61 did: currentAccount.did, 62 62 password, 63 63 token,
+4 -4
src/view/com/modals/VerifyEmail.tsx
··· 21 21 import {Trans, msg} from '@lingui/macro' 22 22 import {useLingui} from '@lingui/react' 23 23 import {useModalControls} from '#/state/modals' 24 - import {useSession, useSessionApi} from '#/state/session' 24 + import {useSession, useSessionApi, getAgent} from '#/state/session' 25 25 26 26 export const snapPoints = ['90%'] 27 27 ··· 33 33 34 34 export function Component({showReminder}: {showReminder?: boolean}) { 35 35 const pal = usePalette('default') 36 - const {agent, currentAccount} = useSession() 36 + const {currentAccount} = useSession() 37 37 const {updateCurrentAccount} = useSessionApi() 38 38 const {_} = useLingui() 39 39 const [stage, setStage] = useState<Stages>( ··· 49 49 setError('') 50 50 setIsProcessing(true) 51 51 try { 52 - await agent.com.atproto.server.requestEmailConfirmation() 52 + await getAgent().com.atproto.server.requestEmailConfirmation() 53 53 setStage(Stages.ConfirmCode) 54 54 } catch (e) { 55 55 setError(cleanError(String(e))) ··· 62 62 setError('') 63 63 setIsProcessing(true) 64 64 try { 65 - await agent.com.atproto.server.confirmEmail({ 65 + await getAgent().com.atproto.server.confirmEmail({ 66 66 email: (currentAccount?.email || '').trim(), 67 67 token: confirmationCode.trim(), 68 68 })
+2 -3
src/view/com/modals/report/Modal.tsx
··· 16 16 import {Trans, msg} from '@lingui/macro' 17 17 import {useLingui} from '@lingui/react' 18 18 import {useModalControls} from '#/state/modals' 19 - import {useSession} from '#/state/session' 19 + import {getAgent} from '#/state/session' 20 20 21 21 const DMCA_LINK = 'https://blueskyweb.xyz/support/copyright' 22 22 ··· 39 39 } 40 40 41 41 export function Component(content: ReportComponentProps) { 42 - const {agent} = useSession() 43 42 const {closeModal} = useModalControls() 44 43 const pal = usePalette('default') 45 44 const {isMobile} = useWebMediaQueries() ··· 70 69 const $type = !isAccountReport 71 70 ? 'com.atproto.repo.strongRef' 72 71 : 'com.atproto.admin.defs#repoRef' 73 - await agent.createModerationReport({ 72 + await getAgent().createModerationReport({ 74 73 reasonType: issue, 75 74 subject: { 76 75 $type,
+10 -3
src/view/screens/Settings.tsx
··· 55 55 useRequireAltTextEnabled, 56 56 useSetRequireAltTextEnabled, 57 57 } from '#/state/preferences' 58 - import {useSession, useSessionApi, SessionAccount} from '#/state/session' 58 + import { 59 + useSession, 60 + useSessionApi, 61 + SessionAccount, 62 + getAgent, 63 + } from '#/state/session' 59 64 import {useProfileQuery} from '#/state/queries/profile' 60 65 import {useClearPreferencesMutation} from '#/state/queries/preferences' 61 66 import {useInviteCodesQuery} from '#/state/queries/invites' ··· 148 153 const {isMobile} = useWebMediaQueries() 149 154 const {screen, track} = useAnalytics() 150 155 const {openModal} = useModalControls() 151 - const {isSwitchingAccounts, accounts, currentAccount, agent} = useSession() 156 + const {isSwitchingAccounts, accounts, currentAccount} = useSession() 152 157 const {clearCurrentAccount} = useSessionApi() 153 - const [debugHeaderEnabled, toggleDebugHeader] = useDebugHeaderSetting(agent) 158 + const [debugHeaderEnabled, toggleDebugHeader] = useDebugHeaderSetting( 159 + getAgent(), 160 + ) 154 161 const {mutate: clearPreferences} = useClearPreferencesMutation() 155 162 const {data: invites} = useInviteCodesQuery() 156 163 const invitesAvailable = invites?.available?.length ?? 0