Bluesky app fork with some witchin' additions 💫

Replace getAgent() with reading agent (#4243)

* Replace getAgent() with agent

* Replace {agent} with agent

authored by danabra.mov and committed by

GitHub 9bd411c1 8a2f43c2

+400 -438
+3 -3
src/components/ReportDialog/SubmitView.tsx
··· 36 36 }) { 37 37 const t = useTheme() 38 38 const {_} = useLingui() 39 - const {getAgent} = useAgent() 39 + const agent = useAgent() 40 40 const [details, setDetails] = React.useState<string>('') 41 41 const [submitting, setSubmitting] = React.useState<boolean>(false) 42 42 const [selectedServices, setSelectedServices] = React.useState<string[]>([ ··· 62 62 } 63 63 const results = await Promise.all( 64 64 selectedServices.map(did => 65 - getAgent() 65 + agent 66 66 .withProxy('atproto_labeler', did) 67 67 .createModerationReport(report) 68 68 .then( ··· 92 92 selectedServices, 93 93 onSubmitComplete, 94 94 setError, 95 - getAgent, 95 + agent, 96 96 ]) 97 97 98 98 return (
+2 -2
src/components/dms/ReportDialog.tsx
··· 102 102 const t = useTheme() 103 103 const [details, setDetails] = useState('') 104 104 const control = Dialog.useDialogContext() 105 - const {getAgent} = useAgent() 105 + const agent = useAgent() 106 106 107 107 const { 108 108 mutate: submit, ··· 124 124 reason: details, 125 125 } satisfies ComAtprotoModerationCreateReport.InputSchema 126 126 127 - await getAgent().createModerationReport(report) 127 + await agent.createModerationReport(report) 128 128 } 129 129 }, 130 130 onSuccess: () => {
+3 -3
src/components/hooks/useRichText.ts
··· 7 7 const [prevText, setPrevText] = React.useState(text) 8 8 const [rawRT, setRawRT] = React.useState(() => new RichTextAPI({text})) 9 9 const [resolvedRT, setResolvedRT] = React.useState<RichTextAPI | null>(null) 10 - const {getAgent} = useAgent() 10 + const agent = useAgent() 11 11 if (text !== prevText) { 12 12 setPrevText(text) 13 13 setRawRT(new RichTextAPI({text})) ··· 19 19 async function resolveRTFacets() { 20 20 // new each time 21 21 const resolvedRT = new RichTextAPI({text}) 22 - await resolvedRT.detectFacets(getAgent()) 22 + await resolvedRT.detectFacets(agent) 23 23 if (!ignore) { 24 24 setResolvedRT(resolvedRT) 25 25 } ··· 28 28 return () => { 29 29 ignore = true 30 30 } 31 - }, [text, getAgent]) 31 + }, [text, agent]) 32 32 const isResolving = resolvedRT === null 33 33 return [resolvedRT ?? rawRT, isResolving] 34 34 }
+2 -2
src/components/moderation/LabelsOnMeDialog.tsx
··· 202 202 const {gtMobile} = useBreakpoints() 203 203 const [details, setDetails] = React.useState('') 204 204 const isAccountReport = 'did' in subject 205 - const {getAgent} = useAgent() 205 + const agent = useAgent() 206 206 207 207 const {mutate, isPending} = useMutation({ 208 208 mutationFn: async () => { 209 209 const $type = !isAccountReport 210 210 ? 'com.atproto.repo.strongRef' 211 211 : 'com.atproto.admin.defs#repoRef' 212 - await getAgent() 212 + await agent 213 213 .withProxy('atproto_labeler', label.src) 214 214 .createModerationReport({ 215 215 reasonType: ComAtprotoModerationDefs.REASONAPPEAL,
+6 -6
src/lib/api/feed/author.ts
··· 7 7 import {FeedAPI, FeedAPIResponse} from './types' 8 8 9 9 export class AuthorFeedAPI implements FeedAPI { 10 - getAgent: () => BskyAgent 10 + agent: BskyAgent 11 11 params: GetAuthorFeed.QueryParams 12 12 13 13 constructor({ 14 - getAgent, 14 + agent, 15 15 feedParams, 16 16 }: { 17 - getAgent: () => BskyAgent 17 + agent: BskyAgent 18 18 feedParams: GetAuthorFeed.QueryParams 19 19 }) { 20 - this.getAgent = getAgent 20 + this.agent = agent 21 21 this.params = feedParams 22 22 } 23 23 24 24 async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> { 25 - const res = await this.getAgent().getAuthorFeed({ 25 + const res = await this.agent.getAuthorFeed({ 26 26 ...this.params, 27 27 limit: 1, 28 28 }) ··· 36 36 cursor: string | undefined 37 37 limit: number 38 38 }): Promise<FeedAPIResponse> { 39 - const res = await this.getAgent().getAuthorFeed({ 39 + const res = await this.agent.getAuthorFeed({ 40 40 ...this.params, 41 41 cursor, 42 42 limit,
+7 -7
src/lib/api/feed/custom.ts
··· 10 10 import {createBskyTopicsHeader, isBlueskyOwnedFeed} from './utils' 11 11 12 12 export class CustomFeedAPI implements FeedAPI { 13 - getAgent: () => BskyAgent 13 + agent: BskyAgent 14 14 params: GetCustomFeed.QueryParams 15 15 userInterests?: string 16 16 17 17 constructor({ 18 - getAgent, 18 + agent, 19 19 feedParams, 20 20 userInterests, 21 21 }: { 22 - getAgent: () => BskyAgent 22 + agent: BskyAgent 23 23 feedParams: GetCustomFeed.QueryParams 24 24 userInterests?: string 25 25 }) { 26 - this.getAgent = getAgent 26 + this.agent = agent 27 27 this.params = feedParams 28 28 this.userInterests = userInterests 29 29 } 30 30 31 31 async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> { 32 32 const contentLangs = getContentLanguages().join(',') 33 - const res = await this.getAgent().app.bsky.feed.getFeed( 33 + const res = await this.agent.app.bsky.feed.getFeed( 34 34 { 35 35 ...this.params, 36 36 limit: 1, ··· 48 48 limit: number 49 49 }): Promise<FeedAPIResponse> { 50 50 const contentLangs = getContentLanguages().join(',') 51 - const agent = this.getAgent() 51 + const agent = this.agent 52 52 const isBlueskyOwned = isBlueskyOwnedFeed(this.params.feed) 53 53 54 54 const res = agent.session 55 - ? await this.getAgent().app.bsky.feed.getFeed( 55 + ? await this.agent.app.bsky.feed.getFeed( 56 56 { 57 57 ...this.params, 58 58 cursor,
+5 -5
src/lib/api/feed/following.ts
··· 3 3 import {FeedAPI, FeedAPIResponse} from './types' 4 4 5 5 export class FollowingFeedAPI implements FeedAPI { 6 - getAgent: () => BskyAgent 6 + agent: BskyAgent 7 7 8 - constructor({getAgent}: {getAgent: () => BskyAgent}) { 9 - this.getAgent = getAgent 8 + constructor({agent}: {agent: BskyAgent}) { 9 + this.agent = agent 10 10 } 11 11 12 12 async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> { 13 - const res = await this.getAgent().getTimeline({ 13 + const res = await this.agent.getTimeline({ 14 14 limit: 1, 15 15 }) 16 16 return res.data.feed[0] ··· 23 23 cursor: string | undefined 24 24 limit: number 25 25 }): Promise<FeedAPIResponse> { 26 - const res = await this.getAgent().getTimeline({ 26 + const res = await this.agent.getTimeline({ 27 27 cursor, 28 28 limit, 29 29 })
+8 -8
src/lib/api/feed/home.ts
··· 27 27 } 28 28 29 29 export class HomeFeedAPI implements FeedAPI { 30 - getAgent: () => BskyAgent 30 + agent: BskyAgent 31 31 following: FollowingFeedAPI 32 32 discover: CustomFeedAPI 33 33 usingDiscover = false ··· 36 36 37 37 constructor({ 38 38 userInterests, 39 - getAgent, 39 + agent, 40 40 }: { 41 41 userInterests?: string 42 - getAgent: () => BskyAgent 42 + agent: BskyAgent 43 43 }) { 44 - this.getAgent = getAgent 45 - this.following = new FollowingFeedAPI({getAgent}) 44 + this.agent = agent 45 + this.following = new FollowingFeedAPI({agent}) 46 46 this.discover = new CustomFeedAPI({ 47 - getAgent, 47 + agent, 48 48 feedParams: {feed: PROD_DEFAULT_FEED('whats-hot')}, 49 49 }) 50 50 this.userInterests = userInterests 51 51 } 52 52 53 53 reset() { 54 - this.following = new FollowingFeedAPI({getAgent: this.getAgent}) 54 + this.following = new FollowingFeedAPI({agent: this.agent}) 55 55 this.discover = new CustomFeedAPI({ 56 - getAgent: this.getAgent, 56 + agent: this.agent, 57 57 feedParams: {feed: PROD_DEFAULT_FEED('whats-hot')}, 58 58 userInterests: this.userInterests, 59 59 })
+6 -6
src/lib/api/feed/likes.ts
··· 7 7 import {FeedAPI, FeedAPIResponse} from './types' 8 8 9 9 export class LikesFeedAPI implements FeedAPI { 10 - getAgent: () => BskyAgent 10 + agent: BskyAgent 11 11 params: GetActorLikes.QueryParams 12 12 13 13 constructor({ 14 - getAgent, 14 + agent, 15 15 feedParams, 16 16 }: { 17 - getAgent: () => BskyAgent 17 + agent: BskyAgent 18 18 feedParams: GetActorLikes.QueryParams 19 19 }) { 20 - this.getAgent = getAgent 20 + this.agent = agent 21 21 this.params = feedParams 22 22 } 23 23 24 24 async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> { 25 - const res = await this.getAgent().getActorLikes({ 25 + const res = await this.agent.getActorLikes({ 26 26 ...this.params, 27 27 limit: 1, 28 28 }) ··· 36 36 cursor: string | undefined 37 37 limit: number 38 38 }): Promise<FeedAPIResponse> { 39 - const res = await this.getAgent().getActorLikes({ 39 + const res = await this.agent.getActorLikes({ 40 40 ...this.params, 41 41 cursor, 42 42 limit,
+6 -6
src/lib/api/feed/list.ts
··· 7 7 import {FeedAPI, FeedAPIResponse} from './types' 8 8 9 9 export class ListFeedAPI implements FeedAPI { 10 - getAgent: () => BskyAgent 10 + agent: BskyAgent 11 11 params: GetListFeed.QueryParams 12 12 13 13 constructor({ 14 - getAgent, 14 + agent, 15 15 feedParams, 16 16 }: { 17 - getAgent: () => BskyAgent 17 + agent: BskyAgent 18 18 feedParams: GetListFeed.QueryParams 19 19 }) { 20 - this.getAgent = getAgent 20 + this.agent = agent 21 21 this.params = feedParams 22 22 } 23 23 24 24 async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> { 25 - const res = await this.getAgent().app.bsky.feed.getListFeed({ 25 + const res = await this.agent.app.bsky.feed.getListFeed({ 26 26 ...this.params, 27 27 limit: 1, 28 28 }) ··· 36 36 cursor: string | undefined 37 37 limit: number 38 38 }): Promise<FeedAPIResponse> { 39 - const res = await this.getAgent().app.bsky.feed.getListFeed({ 39 + const res = await this.agent.app.bsky.feed.getListFeed({ 40 40 ...this.params, 41 41 cursor, 42 42 limit,
+19 -19
src/lib/api/feed/merge.ts
··· 16 16 17 17 export class MergeFeedAPI implements FeedAPI { 18 18 userInterests?: string 19 - getAgent: () => BskyAgent 19 + agent: BskyAgent 20 20 params: FeedParams 21 21 feedTuners: FeedTunerFn[] 22 22 following: MergeFeedSource_Following ··· 26 26 sampleCursor = 0 27 27 28 28 constructor({ 29 - getAgent, 29 + agent, 30 30 feedParams, 31 31 feedTuners, 32 32 userInterests, 33 33 }: { 34 - getAgent: () => BskyAgent 34 + agent: BskyAgent 35 35 feedParams: FeedParams 36 36 feedTuners: FeedTunerFn[] 37 37 userInterests?: string 38 38 }) { 39 - this.getAgent = getAgent 39 + this.agent = agent 40 40 this.params = feedParams 41 41 this.feedTuners = feedTuners 42 42 this.userInterests = userInterests 43 43 this.following = new MergeFeedSource_Following({ 44 - getAgent: this.getAgent, 44 + agent: this.agent, 45 45 feedTuners: this.feedTuners, 46 46 }) 47 47 } 48 48 49 49 reset() { 50 50 this.following = new MergeFeedSource_Following({ 51 - getAgent: this.getAgent, 51 + agent: this.agent, 52 52 feedTuners: this.feedTuners, 53 53 }) 54 54 this.customFeeds = [] ··· 60 60 this.params.mergeFeedSources.map( 61 61 feedUri => 62 62 new MergeFeedSource_Custom({ 63 - getAgent: this.getAgent, 63 + agent: this.agent, 64 64 feedUri, 65 65 feedTuners: this.feedTuners, 66 66 userInterests: this.userInterests, ··· 73 73 } 74 74 75 75 async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> { 76 - const res = await this.getAgent().getTimeline({ 76 + const res = await this.agent.getTimeline({ 77 77 limit: 1, 78 78 }) 79 79 return res.data.feed[0] ··· 167 167 } 168 168 169 169 class MergeFeedSource { 170 - getAgent: () => BskyAgent 170 + agent: BskyAgent 171 171 feedTuners: FeedTunerFn[] 172 172 sourceInfo: ReasonFeedSource | undefined 173 173 cursor: string | undefined = undefined ··· 175 175 hasMore = true 176 176 177 177 constructor({ 178 - getAgent, 178 + agent, 179 179 feedTuners, 180 180 }: { 181 - getAgent: () => BskyAgent 181 + agent: BskyAgent 182 182 feedTuners: FeedTunerFn[] 183 183 }) { 184 - this.getAgent = getAgent 184 + this.agent = agent 185 185 this.feedTuners = feedTuners 186 186 } 187 187 ··· 245 245 cursor: string | undefined, 246 246 limit: number, 247 247 ): Promise<AppBskyFeedGetTimeline.Response> { 248 - const res = await this.getAgent().getTimeline({cursor, limit}) 248 + const res = await this.agent.getTimeline({cursor, limit}) 249 249 // run the tuner pre-emptively to ensure better mixing 250 250 const slices = this.tuner.tune(res.data.feed, { 251 251 dryRun: false, ··· 257 257 } 258 258 259 259 class MergeFeedSource_Custom extends MergeFeedSource { 260 - getAgent: () => BskyAgent 260 + agent: BskyAgent 261 261 minDate: Date 262 262 feedUri: string 263 263 userInterests?: string 264 264 265 265 constructor({ 266 - getAgent, 266 + agent, 267 267 feedUri, 268 268 feedTuners, 269 269 userInterests, 270 270 }: { 271 - getAgent: () => BskyAgent 271 + agent: BskyAgent 272 272 feedUri: string 273 273 feedTuners: FeedTunerFn[] 274 274 userInterests?: string 275 275 }) { 276 276 super({ 277 - getAgent, 277 + agent, 278 278 feedTuners, 279 279 }) 280 - this.getAgent = getAgent 280 + this.agent = agent 281 281 this.feedUri = feedUri 282 282 this.userInterests = userInterests 283 283 this.sourceInfo = { ··· 295 295 try { 296 296 const contentLangs = getContentLanguages().join(',') 297 297 const isBlueskyOwned = isBlueskyOwnedFeed(this.feedUri) 298 - const res = await this.getAgent().app.bsky.feed.getFeed( 298 + const res = await this.agent.app.bsky.feed.getFeed( 299 299 { 300 300 cursor, 301 301 limit,
+5 -5
src/lib/notifications/notifications.ts
··· 14 14 : 'did:web:api.bsky.app' 15 15 16 16 async function registerPushToken( 17 - getAgent: () => BskyAgent, 17 + agent: BskyAgent, 18 18 account: SessionAccount, 19 19 token: Notifications.DevicePushToken, 20 20 ) { 21 21 try { 22 - await getAgent().api.app.bsky.notification.registerPush({ 22 + await agent.api.app.bsky.notification.registerPush({ 23 23 serviceDid: SERVICE_DID(account.service), 24 24 platform: devicePlatform, 25 25 token: token.data, ··· 47 47 } 48 48 49 49 export function useNotificationsRegistration() { 50 - const {getAgent} = useAgent() 50 + const agent = useAgent() 51 51 const {currentAccount} = useSession() 52 52 53 53 React.useEffect(() => { ··· 60 60 // According to the Expo docs, there is a chance that the token will change while the app is open in some rare 61 61 // cases. This will fire `registerPushToken` whenever that happens. 62 62 const subscription = Notifications.addPushTokenListener(async newToken => { 63 - registerPushToken(getAgent, currentAccount, newToken) 63 + registerPushToken(agent, currentAccount, newToken) 64 64 }) 65 65 66 66 return () => { 67 67 subscription.remove() 68 68 } 69 - }, [currentAccount, getAgent]) 69 + }, [currentAccount, agent]) 70 70 } 71 71 72 72 export function useRequestNotificationsPermission() {
+5 -5
src/screens/Deactivated.tsx
··· 24 24 const {gtMobile} = useBreakpoints() 25 25 const onboardingDispatch = useOnboardingDispatch() 26 26 const {logout} = useSessionApi() 27 - const {getAgent} = useAgent() 27 + const agent = useAgent() 28 28 29 29 const [isProcessing, setProcessing] = React.useState(false) 30 30 const [estimatedTime, setEstimatedTime] = React.useState<string | undefined>( ··· 37 37 const checkStatus = React.useCallback(async () => { 38 38 setProcessing(true) 39 39 try { 40 - const res = await getAgent().com.atproto.temp.checkSignupQueue() 40 + const res = await agent.com.atproto.temp.checkSignupQueue() 41 41 if (res.data.activated) { 42 42 // ready to go, exchange the access token for a usable one and kick off onboarding 43 - await getAgent().refreshSession() 44 - if (!isSessionDeactivated(getAgent().session?.accessJwt)) { 43 + await agent.refreshSession() 44 + if (!isSessionDeactivated(agent.session?.accessJwt)) { 45 45 onboardingDispatch({type: 'start'}) 46 46 } 47 47 } else { ··· 61 61 setEstimatedTime, 62 62 setPlaceInQueue, 63 63 onboardingDispatch, 64 - getAgent, 64 + agent, 65 65 ]) 66 66 67 67 React.useEffect(() => {
+2 -2
src/screens/Messages/Conversation/ChatDisabled.tsx
··· 66 66 const control = Dialog.useDialogContext() 67 67 const [details, setDetails] = useState('') 68 68 const {gtMobile} = useBreakpoints() 69 - const {getAgent} = useAgent() 69 + const agent = useAgent() 70 70 const {currentAccount} = useSession() 71 71 72 72 const {mutate, isPending} = useMutation({ 73 73 mutationFn: async () => { 74 74 if (!currentAccount) 75 75 throw new Error('No current account, should be unreachable') 76 - await getAgent().createModerationReport({ 76 + await agent.createModerationReport({ 77 77 reasonType: ComAtprotoModerationDefs.REASONAPPEAL, 78 78 subject: { 79 79 $type: 'com.atproto.admin.defs#repoRef',
+3 -3
src/screens/Messages/Conversation/MessagesList.tsx
··· 79 79 footer?: React.ReactNode 80 80 }) { 81 81 const convoState = useConvoActive() 82 - const {getAgent} = useAgent() 82 + const agent = useAgent() 83 83 84 84 const flatListRef = useAnimatedRef<FlatList>() 85 85 ··· 265 265 const onSendMessage = useCallback( 266 266 async (text: string) => { 267 267 let rt = new RichText({text}, {cleanNewlines: true}) 268 - await rt.detectFacets(getAgent()) 268 + await rt.detectFacets(agent) 269 269 rt = shortenLinks(rt) 270 270 271 271 // filter out any mention facets that didn't map to a user ··· 288 288 facets: rt.facets, 289 289 }) 290 290 }, 291 - [convoState, getAgent, hasScrolled, setHasScrolled], 291 + [convoState, agent, hasScrolled, setHasScrolled], 292 292 ) 293 293 294 294 // -- List layout changes (opening emoji keyboard, etc.)
+8 -8
src/screens/Onboarding/StepFinished.tsx
··· 47 47 const [saving, setSaving] = React.useState(false) 48 48 const {mutateAsync: overwriteSavedFeeds} = useOverwriteSavedFeedsMutation() 49 49 const queryClient = useQueryClient() 50 - const {getAgent} = useAgent() 50 + const agent = useAgent() 51 51 const gate = useGate() 52 52 53 53 const finishOnboarding = React.useCallback(async () => { ··· 70 70 try { 71 71 await Promise.all([ 72 72 bulkWriteFollows( 73 - getAgent, 73 + agent, 74 74 suggestedAccountsStepResults.accountDids.concat(BSKY_APP_ACCOUNT_DID), 75 75 ), 76 76 // these must be serial 77 77 (async () => { 78 - await getAgent().setInterestsPref({tags: selectedInterests}) 78 + await agent.setInterestsPref({tags: selectedInterests}) 79 79 80 80 /* 81 81 * In the reduced onboading experiment, we'll rely on the default ··· 98 98 * (mimics old behavior) 99 99 */ 100 100 if ( 101 - IS_PROD_SERVICE(getAgent().service.toString()) && 101 + IS_PROD_SERVICE(agent.service.toString()) && 102 102 !otherFeeds.length 103 103 ) { 104 104 otherFeeds.push({ ··· 124 124 125 125 const {imageUri, imageMime} = profileStepResults 126 126 if (imageUri && imageMime) { 127 - const blobPromise = uploadBlob(getAgent(), imageUri, imageMime) 128 - await getAgent().upsertProfile(async existing => { 127 + const blobPromise = uploadBlob(agent, imageUri, imageMime) 128 + await agent.upsertProfile(async existing => { 129 129 existing = existing ?? {} 130 130 const res = await blobPromise 131 131 if (res.data.blob) { ··· 156 156 queryKey: preferencesQueryKey, 157 157 }), 158 158 queryClient.invalidateQueries({ 159 - queryKey: profileRQKey(getAgent().session?.did ?? ''), 159 + queryKey: profileRQKey(agent.session?.did ?? ''), 160 160 }), 161 161 ]).catch(e => { 162 162 logger.error(e) ··· 176 176 setSaving, 177 177 overwriteSavedFeeds, 178 178 track, 179 - getAgent, 179 + agent, 180 180 gate, 181 181 queryClient, 182 182 ])
+2 -3
src/screens/Onboarding/StepInterests/index.tsx
··· 43 43 state.interestsStepResults.selectedInterests.map(i => i), 44 44 ) 45 45 const onboardDispatch = useOnboardingDispatch() 46 - const {getAgent} = useAgent() 46 + const agent = useAgent() 47 47 const {isLoading, isError, error, data, refetch, isFetching} = useQuery({ 48 48 queryKey: ['interests'], 49 49 queryFn: async () => { 50 50 try { 51 - const {data} = 52 - await getAgent().app.bsky.unspecced.getTaggedSuggestions() 51 + const {data} = await agent.app.bsky.unspecced.getTaggedSuggestions() 53 52 return data.suggestions.reduce( 54 53 (agg, s) => { 55 54 const {tag, subject, subjectType} = s
+6 -13
src/screens/Onboarding/util.ts
··· 66 66 return Array.from(new Set(results)).slice(0, 20) 67 67 } 68 68 69 - export async function bulkWriteFollows( 70 - getAgent: () => BskyAgent, 71 - dids: string[], 72 - ) { 73 - const session = getAgent().session 69 + export async function bulkWriteFollows(agent: BskyAgent, dids: string[]) { 70 + const session = agent.session 74 71 75 72 if (!session) { 76 73 throw new Error(`bulkWriteFollows failed: no session`) ··· 89 86 value: r, 90 87 })) 91 88 92 - await getAgent().com.atproto.repo.applyWrites({ 89 + await agent.com.atproto.repo.applyWrites({ 93 90 repo: session.did, 94 91 writes: followWrites, 95 92 }) 96 - await whenFollowsIndexed( 97 - getAgent, 98 - session.did, 99 - res => !!res.data.follows.length, 100 - ) 93 + await whenFollowsIndexed(agent, session.did, res => !!res.data.follows.length) 101 94 } 102 95 103 96 async function whenFollowsIndexed( 104 - getAgent: () => BskyAgent, 97 + agent: BskyAgent, 105 98 actor: string, 106 99 fn: (res: AppBskyGraphGetFollows.Response) => boolean, 107 100 ) { ··· 110 103 1e3, // 1s delay between tries 111 104 fn, 112 105 () => 113 - getAgent().app.bsky.graph.getFollows({ 106 + agent.app.bsky.graph.getFollows({ 114 107 actor, 115 108 limit: 1, 116 109 }),
+3 -3
src/screens/Signup/index.tsx
··· 36 36 const [state, dispatch] = React.useReducer(reducer, initialState) 37 37 const submit = useSubmitSignup({state, dispatch}) 38 38 const {gtMobile} = useBreakpoints() 39 - const {getAgent} = useAgent() 39 + const agent = useAgent() 40 40 41 41 const { 42 42 data: serviceInfo, ··· 77 77 try { 78 78 dispatch({type: 'setIsLoading', value: true}) 79 79 80 - const res = await getAgent().resolveHandle({ 80 + const res = await agent.resolveHandle({ 81 81 handle: createFullHandle(state.handle, state.userDomain), 82 82 }) 83 83 ··· 115 115 state.serviceDescription?.phoneVerificationRequired, 116 116 state.userDomain, 117 117 submit, 118 - getAgent, 118 + agent, 119 119 ]) 120 120 121 121 const onBackPress = React.useCallback(() => {
+3 -3
src/state/feed-feedback.tsx
··· 25 25 }) 26 26 27 27 export function useFeedFeedback(feed: FeedDescriptor, hasSession: boolean) { 28 - const {getAgent} = useAgent() 28 + const agent = useAgent() 29 29 const enabled = isDiscoverFeed(feed) && hasSession 30 30 const queue = React.useRef<Set<string>>(new Set()) 31 31 const history = React.useRef< ··· 35 35 >(new WeakSet()) 36 36 37 37 const sendToFeedNoDelay = React.useCallback(() => { 38 - const proxyAgent = getAgent().withProxy( 38 + const proxyAgent = agent.withProxy( 39 39 // @ts-ignore TODO need to update withProxy() to support this key -prf 40 40 'bsky_fg', 41 41 // TODO when we start sending to other feeds, we need to grab their DID -prf ··· 50 50 .catch((e: any) => { 51 51 logger.warn('Failed to send feed interactions', {error: e}) 52 52 }) 53 - }, [getAgent]) 53 + }, [agent]) 54 54 55 55 const sendToFeed = React.useMemo( 56 56 () =>
+2 -2
src/state/messages/convo/index.tsx
··· 58 58 convoId, 59 59 }: Pick<ConvoParams, 'convoId'> & {children: React.ReactNode}) { 60 60 const queryClient = useQueryClient() 61 - const {getAgent} = useAgent() 61 + const agent = useAgent() 62 62 const events = useMessagesEventBus() 63 63 const [convo] = useState( 64 64 () => 65 65 new Convo({ 66 66 convoId, 67 - agent: getAgent(), 67 + agent, 68 68 events, 69 69 }), 70 70 )
+2 -2
src/state/messages/events/index.tsx
··· 43 43 }: { 44 44 children: React.ReactNode 45 45 }) { 46 - const {getAgent} = useAgent() 46 + const agent = useAgent() 47 47 const [bus] = React.useState( 48 48 () => 49 49 new MessagesEventBus({ 50 - agent: getAgent(), 50 + agent, 51 51 }), 52 52 ) 53 53
+5 -5
src/state/queries/actor-autocomplete.ts
··· 23 23 limit?: number, 24 24 ) { 25 25 const moderationOpts = useModerationOpts() 26 - const {getAgent} = useAgent() 26 + const agent = useAgent() 27 27 28 28 prefix = prefix.toLowerCase().trim() 29 29 if (prefix.endsWith('.')) { ··· 36 36 queryKey: RQKEY(prefix || ''), 37 37 async queryFn() { 38 38 const res = prefix 39 - ? await getAgent().searchActorsTypeahead({ 39 + ? await agent.searchActorsTypeahead({ 40 40 q: prefix, 41 41 limit: limit || 8, 42 42 }) ··· 57 57 export function useActorAutocompleteFn() { 58 58 const queryClient = useQueryClient() 59 59 const moderationOpts = useModerationOpts() 60 - const {getAgent} = useAgent() 60 + const agent = useAgent() 61 61 62 62 return React.useCallback( 63 63 async ({query, limit = 8}: {query: string; limit?: number}) => { ··· 69 69 staleTime: STALE.MINUTES.ONE, 70 70 queryKey: RQKEY(query || ''), 71 71 queryFn: () => 72 - getAgent().searchActorsTypeahead({ 72 + agent.searchActorsTypeahead({ 73 73 q: query, 74 74 limit, 75 75 }), ··· 86 86 moderationOpts || DEFAULT_MOD_OPTS, 87 87 ) 88 88 }, 89 - [queryClient, moderationOpts, getAgent], 89 + [queryClient, moderationOpts, agent], 90 90 ) 91 91 } 92 92
+2 -2
src/state/queries/actor-search.ts
··· 14 14 query: string 15 15 enabled?: boolean 16 16 }) { 17 - const {getAgent} = useAgent() 17 + const agent = useAgent() 18 18 return useQuery<AppBskyActorDefs.ProfileView[]>({ 19 19 staleTime: STALE.MINUTES.ONE, 20 20 queryKey: RQKEY(query || ''), 21 21 async queryFn() { 22 - const res = await getAgent().searchActors({ 22 + const res = await agent.searchActors({ 23 23 q: query, 24 24 }) 25 25 return res.data.actors
+6 -6
src/state/queries/app-passwords.ts
··· 8 8 export const RQKEY = () => [RQKEY_ROOT] 9 9 10 10 export function useAppPasswordsQuery() { 11 - const {getAgent} = useAgent() 11 + const agent = useAgent() 12 12 return useQuery({ 13 13 staleTime: STALE.MINUTES.FIVE, 14 14 queryKey: RQKEY(), 15 15 queryFn: async () => { 16 - const res = await getAgent().com.atproto.server.listAppPasswords({}) 16 + const res = await agent.com.atproto.server.listAppPasswords({}) 17 17 return res.data.passwords 18 18 }, 19 19 }) ··· 21 21 22 22 export function useAppPasswordCreateMutation() { 23 23 const queryClient = useQueryClient() 24 - const {getAgent} = useAgent() 24 + const agent = useAgent() 25 25 return useMutation< 26 26 ComAtprotoServerCreateAppPassword.OutputSchema, 27 27 Error, ··· 29 29 >({ 30 30 mutationFn: async ({name, privileged}) => { 31 31 return ( 32 - await getAgent().com.atproto.server.createAppPassword({ 32 + await agent.com.atproto.server.createAppPassword({ 33 33 name, 34 34 privileged, 35 35 }) ··· 45 45 46 46 export function useAppPasswordDeleteMutation() { 47 47 const queryClient = useQueryClient() 48 - const {getAgent} = useAgent() 48 + const agent = useAgent() 49 49 return useMutation<void, Error, {name: string}>({ 50 50 mutationFn: async ({name}) => { 51 - await getAgent().com.atproto.server.revokeAppPassword({ 51 + await agent.com.atproto.server.revokeAppPassword({ 52 52 name, 53 53 }) 54 54 },
+12 -12
src/state/queries/feed.ts
··· 147 147 148 148 export function useFeedSourceInfoQuery({uri}: {uri: string}) { 149 149 const type = getFeedTypeFromUri(uri) 150 - const {getAgent} = useAgent() 150 + const agent = useAgent() 151 151 152 152 return useQuery({ 153 153 staleTime: STALE.INFINITY, ··· 156 156 let view: FeedSourceInfo 157 157 158 158 if (type === 'feed') { 159 - const res = await getAgent().app.bsky.feed.getFeedGenerator({feed: uri}) 159 + const res = await agent.app.bsky.feed.getFeedGenerator({feed: uri}) 160 160 view = hydrateFeedGenerator(res.data.view) 161 161 } else { 162 - const res = await getAgent().app.bsky.graph.getList({ 162 + const res = await agent.app.bsky.graph.getList({ 163 163 list: uri, 164 164 limit: 1, 165 165 }) ··· 174 174 export const useGetPopularFeedsQueryKey = ['getPopularFeeds'] 175 175 176 176 export function useGetPopularFeedsQuery() { 177 - const {getAgent} = useAgent() 177 + const agent = useAgent() 178 178 return useInfiniteQuery< 179 179 AppBskyUnspeccedGetPopularFeedGenerators.OutputSchema, 180 180 Error, ··· 184 184 >({ 185 185 queryKey: useGetPopularFeedsQueryKey, 186 186 queryFn: async ({pageParam}) => { 187 - const res = await getAgent().app.bsky.unspecced.getPopularFeedGenerators({ 187 + const res = await agent.app.bsky.unspecced.getPopularFeedGenerators({ 188 188 limit: 10, 189 189 cursor: pageParam, 190 190 }) ··· 196 196 } 197 197 198 198 export function useSearchPopularFeedsMutation() { 199 - const {getAgent} = useAgent() 199 + const agent = useAgent() 200 200 return useMutation({ 201 201 mutationFn: async (query: string) => { 202 - const res = await getAgent().app.bsky.unspecced.getPopularFeedGenerators({ 202 + const res = await agent.app.bsky.unspecced.getPopularFeedGenerators({ 203 203 limit: 10, 204 204 query: query, 205 205 }) ··· 241 241 242 242 export function usePinnedFeedsInfos() { 243 243 const {hasSession} = useSession() 244 - const {getAgent} = useAgent() 244 + const agent = useAgent() 245 245 const {data: preferences, isLoading: isLoadingPrefs} = usePreferencesQuery() 246 246 const pinnedItems = preferences?.savedFeeds.filter(feed => feed.pinned) ?? [] 247 247 ··· 264 264 const pinnedFeeds = pinnedItems.filter(feed => feed.type === 'feed') 265 265 let feedsPromise = Promise.resolve() 266 266 if (pinnedFeeds.length > 0) { 267 - feedsPromise = getAgent() 268 - .app.bsky.feed.getFeedGenerators({ 267 + feedsPromise = agent.app.bsky.feed 268 + .getFeedGenerators({ 269 269 feeds: pinnedFeeds.map(f => f.value), 270 270 }) 271 271 .then(res => { ··· 279 279 // Get all lists. This currently has to be done individually. 280 280 const pinnedLists = pinnedItems.filter(feed => feed.type === 'list') 281 281 const listsPromises = pinnedLists.map(list => 282 - getAgent() 283 - .app.bsky.graph.getList({ 282 + agent.app.bsky.graph 283 + .getList({ 284 284 list: list.value, 285 285 limit: 1, 286 286 })
+8 -8
src/state/queries/handle.ts
··· 14 14 15 15 export function useFetchHandle() { 16 16 const queryClient = useQueryClient() 17 - const {getAgent} = useAgent() 17 + const agent = useAgent() 18 18 19 19 return React.useCallback( 20 20 async (handleOrDid: string) => { ··· 22 22 const res = await queryClient.fetchQuery({ 23 23 staleTime: STALE.MINUTES.FIVE, 24 24 queryKey: fetchHandleQueryKey(handleOrDid), 25 - queryFn: () => getAgent().getProfile({actor: handleOrDid}), 25 + queryFn: () => agent.getProfile({actor: handleOrDid}), 26 26 }) 27 27 return res.data.handle 28 28 } 29 29 return handleOrDid 30 30 }, 31 - [queryClient, getAgent], 31 + [queryClient, agent], 32 32 ) 33 33 } 34 34 35 35 export function useUpdateHandleMutation() { 36 36 const queryClient = useQueryClient() 37 - const {getAgent} = useAgent() 37 + const agent = useAgent() 38 38 39 39 return useMutation({ 40 40 mutationFn: async ({handle}: {handle: string}) => { 41 - await getAgent().updateHandle({handle}) 41 + await agent.updateHandle({handle}) 42 42 }, 43 43 onSuccess(_data, variables) { 44 44 queryClient.invalidateQueries({ ··· 50 50 51 51 export function useFetchDid() { 52 52 const queryClient = useQueryClient() 53 - const {getAgent} = useAgent() 53 + const agent = useAgent() 54 54 55 55 return React.useCallback( 56 56 async (handleOrDid: string) => { ··· 60 60 queryFn: async () => { 61 61 let identifier = handleOrDid 62 62 if (!identifier.startsWith('did:')) { 63 - const res = await getAgent().resolveHandle({handle: identifier}) 63 + const res = await agent.resolveHandle({handle: identifier}) 64 64 identifier = res.data.did 65 65 } 66 66 return identifier 67 67 }, 68 68 }) 69 69 }, 70 - [queryClient, getAgent], 70 + [queryClient, agent], 71 71 ) 72 72 }
+3 -3
src/state/queries/invites.ts
··· 16 16 undefined 17 17 > 18 18 export function useInviteCodesQuery() { 19 - const {getAgent} = useAgent() 19 + const agent = useAgent() 20 20 return useQuery({ 21 21 staleTime: STALE.MINUTES.FIVE, 22 22 queryKey: [inviteCodesQueryKeyRoot], 23 23 queryFn: async () => { 24 - const res = await getAgent() 25 - .com.atproto.server.getAccountInviteCodes({}) 24 + const res = await agent.com.atproto.server 25 + .getAccountInviteCodes({}) 26 26 .catch(e => { 27 27 if (cleanError(e) === 'Bad token scope') { 28 28 return null
+9 -9
src/state/queries/labeler.ts
··· 31 31 did?: string 32 32 enabled?: boolean 33 33 }) { 34 - const {getAgent} = useAgent() 34 + const agent = useAgent() 35 35 return useQuery({ 36 36 enabled: !!did && enabled !== false, 37 37 queryKey: labelerInfoQueryKey(did as string), 38 38 queryFn: async () => { 39 - const res = await getAgent().app.bsky.labeler.getServices({ 39 + const res = await agent.app.bsky.labeler.getServices({ 40 40 dids: [did as string], 41 41 detailed: true, 42 42 }) ··· 46 46 } 47 47 48 48 export function useLabelersInfoQuery({dids}: {dids: string[]}) { 49 - const {getAgent} = useAgent() 49 + const agent = useAgent() 50 50 return useQuery({ 51 51 enabled: !!dids.length, 52 52 queryKey: labelersInfoQueryKey(dids), 53 53 queryFn: async () => { 54 - const res = await getAgent().app.bsky.labeler.getServices({dids}) 54 + const res = await agent.app.bsky.labeler.getServices({dids}) 55 55 return res.data.views as AppBskyLabelerDefs.LabelerView[] 56 56 }, 57 57 }) 58 58 } 59 59 60 60 export function useLabelersDetailedInfoQuery({dids}: {dids: string[]}) { 61 - const {getAgent} = useAgent() 61 + const agent = useAgent() 62 62 return useQuery({ 63 63 enabled: !!dids.length, 64 64 queryKey: labelersDetailedInfoQueryKey(dids), 65 65 gcTime: 1000 * 60 * 60 * 6, // 6 hours 66 66 staleTime: STALE.MINUTES.ONE, 67 67 queryFn: async () => { 68 - const res = await getAgent().app.bsky.labeler.getServices({ 68 + const res = await agent.app.bsky.labeler.getServices({ 69 69 dids, 70 70 detailed: true, 71 71 }) ··· 76 76 77 77 export function useLabelerSubscriptionMutation() { 78 78 const queryClient = useQueryClient() 79 - const {getAgent} = useAgent() 79 + const agent = useAgent() 80 80 81 81 return useMutation({ 82 82 async mutationFn({did, subscribe}: {did: string; subscribe: boolean}) { ··· 87 87 }).parse({did, subscribe}) 88 88 89 89 if (subscribe) { 90 - await getAgent().addLabeler(did) 90 + await agent.addLabeler(did) 91 91 } else { 92 - await getAgent().removeLabeler(did) 92 + await agent.removeLabeler(did) 93 93 } 94 94 }, 95 95 onSuccess() {
+4 -4
src/state/queries/like.ts
··· 3 3 import {useAgent} from '#/state/session' 4 4 5 5 export function useLikeMutation() { 6 - const {getAgent} = useAgent() 6 + const agent = useAgent() 7 7 return useMutation({ 8 8 mutationFn: async ({uri, cid}: {uri: string; cid: string}) => { 9 - const res = await getAgent().like(uri, cid) 9 + const res = await agent.like(uri, cid) 10 10 return {uri: res.uri} 11 11 }, 12 12 }) 13 13 } 14 14 15 15 export function useUnlikeMutation() { 16 - const {getAgent} = useAgent() 16 + const agent = useAgent() 17 17 return useMutation({ 18 18 mutationFn: async ({uri}: {uri: string}) => { 19 - await getAgent().deleteLike(uri) 19 + await agent.deleteLike(uri) 20 20 }, 21 21 }) 22 22 }
+2 -2
src/state/queries/list-members.ts
··· 16 16 export const RQKEY = (uri: string) => [RQKEY_ROOT, uri] 17 17 18 18 export function useListMembersQuery(uri: string) { 19 - const {getAgent} = useAgent() 19 + const agent = useAgent() 20 20 return useInfiniteQuery< 21 21 AppBskyGraphGetList.OutputSchema, 22 22 Error, ··· 27 27 staleTime: STALE.MINUTES.ONE, 28 28 queryKey: RQKEY(uri), 29 29 async queryFn({pageParam}: {pageParam: RQPageParam}) { 30 - const res = await getAgent().app.bsky.graph.getList({ 30 + const res = await agent.app.bsky.graph.getList({ 31 31 list: uri, 32 32 limit: PAGE_SIZE, 33 33 cursor: pageParam,
+6 -6
src/state/queries/list-memberships.ts
··· 40 40 */ 41 41 export function useDangerousListMembershipsQuery() { 42 42 const {currentAccount} = useSession() 43 - const {getAgent} = useAgent() 43 + const agent = useAgent() 44 44 return useQuery<ListMembersip[]>({ 45 45 staleTime: STALE.MINUTES.FIVE, 46 46 queryKey: RQKEY(), ··· 51 51 let cursor 52 52 let arr: ListMembersip[] = [] 53 53 for (let i = 0; i < SANITY_PAGE_LIMIT; i++) { 54 - const res = await getAgent().app.bsky.graph.listitem.list({ 54 + const res = await agent.app.bsky.graph.listitem.list({ 55 55 repo: currentAccount.did, 56 56 limit: PAGE_SIZE, 57 57 cursor, ··· 92 92 93 93 export function useListMembershipAddMutation() { 94 94 const {currentAccount} = useSession() 95 - const {getAgent} = useAgent() 95 + const agent = useAgent() 96 96 const queryClient = useQueryClient() 97 97 return useMutation< 98 98 {uri: string; cid: string}, ··· 103 103 if (!currentAccount) { 104 104 throw new Error('Not logged in') 105 105 } 106 - const res = await getAgent().app.bsky.graph.listitem.create( 106 + const res = await agent.app.bsky.graph.listitem.create( 107 107 {repo: currentAccount.did}, 108 108 { 109 109 subject: actorDid, ··· 151 151 152 152 export function useListMembershipRemoveMutation() { 153 153 const {currentAccount} = useSession() 154 - const {getAgent} = useAgent() 154 + const agent = useAgent() 155 155 const queryClient = useQueryClient() 156 156 return useMutation< 157 157 void, ··· 163 163 throw new Error('Not logged in') 164 164 } 165 165 const membershipUrip = new AtUri(membershipUri) 166 - await getAgent().app.bsky.graph.listitem.delete({ 166 + await agent.app.bsky.graph.listitem.delete({ 167 167 repo: currentAccount.did, 168 168 rkey: membershipUrip.rkey, 169 169 })
+33 -45
src/state/queries/list.ts
··· 21 21 export const RQKEY = (uri: string) => [RQKEY_ROOT, uri] 22 22 23 23 export function useListQuery(uri?: string) { 24 - const {getAgent} = useAgent() 24 + const agent = useAgent() 25 25 return useQuery<AppBskyGraphDefs.ListView, Error>({ 26 26 staleTime: STALE.MINUTES.ONE, 27 27 queryKey: RQKEY(uri || ''), ··· 29 29 if (!uri) { 30 30 throw new Error('URI not provided') 31 31 } 32 - const res = await getAgent().app.bsky.graph.getList({ 32 + const res = await agent.app.bsky.graph.getList({ 33 33 list: uri, 34 34 limit: 1, 35 35 }) ··· 49 49 export function useListCreateMutation() { 50 50 const {currentAccount} = useSession() 51 51 const queryClient = useQueryClient() 52 - const {getAgent} = useAgent() 52 + const agent = useAgent() 53 53 return useMutation<{uri: string; cid: string}, Error, ListCreateMutateParams>( 54 54 { 55 55 async mutationFn({ ··· 77 77 createdAt: new Date().toISOString(), 78 78 } 79 79 if (avatar) { 80 - const blobRes = await uploadBlob(getAgent(), avatar.path, avatar.mime) 80 + const blobRes = await uploadBlob(agent, avatar.path, avatar.mime) 81 81 record.avatar = blobRes.data.blob 82 82 } 83 - const res = await getAgent().app.bsky.graph.list.create( 83 + const res = await agent.app.bsky.graph.list.create( 84 84 { 85 85 repo: currentAccount.did, 86 86 }, ··· 89 89 90 90 // wait for the appview to update 91 91 await whenAppViewReady( 92 - getAgent, 92 + agent, 93 93 res.uri, 94 94 (v: AppBskyGraphGetList.Response) => { 95 95 return typeof v?.data?.list.uri === 'string' ··· 116 116 } 117 117 export function useListMetadataMutation() { 118 118 const {currentAccount} = useSession() 119 - const {getAgent} = useAgent() 119 + const agent = useAgent() 120 120 const queryClient = useQueryClient() 121 121 return useMutation< 122 122 {uri: string; cid: string}, ··· 133 133 } 134 134 135 135 // get the current record 136 - const {value: record} = await getAgent().app.bsky.graph.list.get({ 136 + const {value: record} = await agent.app.bsky.graph.list.get({ 137 137 repo: currentAccount.did, 138 138 rkey, 139 139 }) ··· 143 143 record.description = description 144 144 record.descriptionFacets = descriptionFacets 145 145 if (avatar) { 146 - const blobRes = await uploadBlob(getAgent(), avatar.path, avatar.mime) 146 + const blobRes = await uploadBlob(agent, avatar.path, avatar.mime) 147 147 record.avatar = blobRes.data.blob 148 148 } else if (avatar === null) { 149 149 record.avatar = undefined 150 150 } 151 151 const res = ( 152 - await getAgent().com.atproto.repo.putRecord({ 152 + await agent.com.atproto.repo.putRecord({ 153 153 repo: currentAccount.did, 154 154 collection: 'app.bsky.graph.list', 155 155 rkey, ··· 159 159 160 160 // wait for the appview to update 161 161 await whenAppViewReady( 162 - getAgent, 162 + agent, 163 163 res.uri, 164 164 (v: AppBskyGraphGetList.Response) => { 165 165 const list = v.data.list ··· 184 184 185 185 export function useListDeleteMutation() { 186 186 const {currentAccount} = useSession() 187 - const {getAgent} = useAgent() 187 + const agent = useAgent() 188 188 const queryClient = useQueryClient() 189 189 return useMutation<void, Error, {uri: string}>({ 190 190 mutationFn: async ({uri}) => { ··· 195 195 let cursor 196 196 let listitemRecordUris: string[] = [] 197 197 for (let i = 0; i < 100; i++) { 198 - const res = await getAgent().app.bsky.graph.listitem.list({ 198 + const res = await agent.app.bsky.graph.listitem.list({ 199 199 repo: currentAccount.did, 200 200 cursor, 201 201 limit: 100, ··· 226 226 227 227 // apply in chunks 228 228 for (const writesChunk of chunk(writes, 10)) { 229 - await getAgent().com.atproto.repo.applyWrites({ 229 + await agent.com.atproto.repo.applyWrites({ 230 230 repo: currentAccount.did, 231 231 writes: writesChunk, 232 232 }) 233 233 } 234 234 235 235 // wait for the appview to update 236 - await whenAppViewReady( 237 - getAgent, 238 - uri, 239 - (v: AppBskyGraphGetList.Response) => { 240 - return !v?.success 241 - }, 242 - ) 236 + await whenAppViewReady(agent, uri, (v: AppBskyGraphGetList.Response) => { 237 + return !v?.success 238 + }) 243 239 }, 244 240 onSuccess() { 245 241 invalidateMyLists(queryClient) ··· 253 249 254 250 export function useListMuteMutation() { 255 251 const queryClient = useQueryClient() 256 - const {getAgent} = useAgent() 252 + const agent = useAgent() 257 253 return useMutation<void, Error, {uri: string; mute: boolean}>({ 258 254 mutationFn: async ({uri, mute}) => { 259 255 if (mute) { 260 - await getAgent().muteModList(uri) 256 + await agent.muteModList(uri) 261 257 } else { 262 - await getAgent().unmuteModList(uri) 258 + await agent.unmuteModList(uri) 263 259 } 264 260 265 - await whenAppViewReady( 266 - getAgent, 267 - uri, 268 - (v: AppBskyGraphGetList.Response) => { 269 - return Boolean(v?.data.list.viewer?.muted) === mute 270 - }, 271 - ) 261 + await whenAppViewReady(agent, uri, (v: AppBskyGraphGetList.Response) => { 262 + return Boolean(v?.data.list.viewer?.muted) === mute 263 + }) 272 264 }, 273 265 onSuccess(data, variables) { 274 266 queryClient.invalidateQueries({ ··· 280 272 281 273 export function useListBlockMutation() { 282 274 const queryClient = useQueryClient() 283 - const {getAgent} = useAgent() 275 + const agent = useAgent() 284 276 return useMutation<void, Error, {uri: string; block: boolean}>({ 285 277 mutationFn: async ({uri, block}) => { 286 278 if (block) { 287 - await getAgent().blockModList(uri) 279 + await agent.blockModList(uri) 288 280 } else { 289 - await getAgent().unblockModList(uri) 281 + await agent.unblockModList(uri) 290 282 } 291 283 292 - await whenAppViewReady( 293 - getAgent, 294 - uri, 295 - (v: AppBskyGraphGetList.Response) => { 296 - return block 297 - ? typeof v?.data.list.viewer?.blocked === 'string' 298 - : !v?.data.list.viewer?.blocked 299 - }, 300 - ) 284 + await whenAppViewReady(agent, uri, (v: AppBskyGraphGetList.Response) => { 285 + return block 286 + ? typeof v?.data.list.viewer?.blocked === 'string' 287 + : !v?.data.list.viewer?.blocked 288 + }) 301 289 }, 302 290 onSuccess(data, variables) { 303 291 queryClient.invalidateQueries({ ··· 308 296 } 309 297 310 298 async function whenAppViewReady( 311 - getAgent: () => BskyAgent, 299 + agent: BskyAgent, 312 300 uri: string, 313 301 fn: (res: AppBskyGraphGetList.Response) => boolean, 314 302 ) { ··· 317 305 1e3, // 1s delay between tries 318 306 fn, 319 307 () => 320 - getAgent().app.bsky.graph.getList({ 308 + agent.app.bsky.graph.getList({ 321 309 list: uri, 322 310 limit: 1, 323 311 }),
+4 -4
src/state/queries/messages/actor-declaration.ts
··· 14 14 }) { 15 15 const queryClient = useQueryClient() 16 16 const {currentAccount} = useSession() 17 - const {getAgent} = useAgent() 17 + const agent = useAgent() 18 18 19 19 return useMutation({ 20 20 mutationFn: async (allowIncoming: 'all' | 'none' | 'following') => { 21 21 if (!currentAccount) throw new Error('Not logged in') 22 - const result = await getAgent().api.com.atproto.repo.putRecord({ 22 + const result = await agent.api.com.atproto.repo.putRecord({ 23 23 repo: currentAccount.did, 24 24 collection: 'chat.bsky.actor.declaration', 25 25 rkey: 'self', ··· 64 64 // for use in the settings screen for testing 65 65 export function useDeleteActorDeclaration() { 66 66 const {currentAccount} = useSession() 67 - const {getAgent} = useAgent() 67 + const agent = useAgent() 68 68 69 69 return useMutation({ 70 70 mutationFn: async () => { 71 71 if (!currentAccount) throw new Error('Not logged in') 72 72 // TODO(sam): remove validate: false once PDSes have the new lexicon 73 - const result = await getAgent().api.com.atproto.repo.deleteRecord({ 73 + const result = await agent.api.com.atproto.repo.deleteRecord({ 74 74 repo: currentAccount.did, 75 75 collection: 'chat.bsky.actor.declaration', 76 76 rkey: 'self',
+4 -4
src/state/queries/messages/conversation.ts
··· 11 11 export const RQKEY = (convoId: string) => [RQKEY_ROOT, convoId] 12 12 13 13 export function useConvoQuery(convo: ChatBskyConvoDefs.ConvoView) { 14 - const {getAgent} = useAgent() 14 + const agent = useAgent() 15 15 16 16 return useQuery({ 17 17 queryKey: RQKEY(convo.id), 18 18 queryFn: async () => { 19 - const {data} = await getAgent().api.chat.bsky.convo.getConvo( 19 + const {data} = await agent.api.chat.bsky.convo.getConvo( 20 20 {convoId: convo.id}, 21 21 {headers: DM_SERVICE_HEADERS}, 22 22 ) ··· 30 30 export function useMarkAsReadMutation() { 31 31 const optimisticUpdate = useOnMarkAsRead() 32 32 const queryClient = useQueryClient() 33 - const {getAgent} = useAgent() 33 + const agent = useAgent() 34 34 35 35 return useMutation({ 36 36 mutationFn: async ({ ··· 42 42 }) => { 43 43 if (!convoId) throw new Error('No convoId provided') 44 44 45 - await getAgent().api.chat.bsky.convo.updateRead( 45 + await agent.api.chat.bsky.convo.updateRead( 46 46 { 47 47 convoId, 48 48 messageId,
+5 -8
src/state/queries/messages/get-convo-for-members.ts
··· 18 18 onError?: (error: Error) => void 19 19 }) { 20 20 const queryClient = useQueryClient() 21 - const {getAgent} = useAgent() 21 + const agent = useAgent() 22 22 23 23 return useMutation({ 24 24 mutationFn: async (members: string[]) => { 25 - const {data} = await getAgent().api.chat.bsky.convo.getConvoForMembers( 25 + const {data} = await agent.api.chat.bsky.convo.getConvoForMembers( 26 26 {members: members}, 27 27 {headers: DM_SERVICE_HEADERS}, 28 28 ) ··· 44 44 * Gets the conversation ID for a given DID. Returns null if it's not possible to message them. 45 45 */ 46 46 export function useMaybeConvoForUser(did: string) { 47 - const {getAgent} = useAgent() 47 + const agent = useAgent() 48 48 49 49 return useQuery({ 50 50 queryKey: RQKEY(did), 51 51 queryFn: async () => { 52 - const convo = await getAgent() 53 - .api.chat.bsky.convo.getConvoForMembers( 54 - {members: [did]}, 55 - {headers: DM_SERVICE_HEADERS}, 56 - ) 52 + const convo = await agent.api.chat.bsky.convo 53 + .getConvoForMembers({members: [did]}, {headers: DM_SERVICE_HEADERS}) 57 54 .catch(() => ({success: null})) 58 55 59 56 if (convo.success) {
+2 -2
src/state/queries/messages/leave-conversation.ts
··· 17 17 }, 18 18 ) { 19 19 const queryClient = useQueryClient() 20 - const {getAgent} = useAgent() 20 + const agent = useAgent() 21 21 22 22 return useMutation({ 23 23 mutationFn: async () => { 24 24 if (!convoId) throw new Error('No convoId provided') 25 25 26 - const {data} = await getAgent().api.chat.bsky.convo.leaveConvo( 26 + const {data} = await agent.api.chat.bsky.convo.leaveConvo( 27 27 {convoId}, 28 28 {headers: DM_SERVICE_HEADERS, encoding: 'application/json'}, 29 29 )
+2 -2
src/state/queries/messages/list-converations.tsx
··· 27 27 type RQPageParam = string | undefined 28 28 29 29 export function useListConvosQuery() { 30 - const {getAgent} = useAgent() 30 + const agent = useAgent() 31 31 32 32 return useInfiniteQuery({ 33 33 queryKey: RQKEY, 34 34 queryFn: async ({pageParam}) => { 35 - const {data} = await getAgent().api.chat.bsky.convo.listConvos( 35 + const {data} = await agent.api.chat.bsky.convo.listConvos( 36 36 {cursor: pageParam}, 37 37 {headers: DM_SERVICE_HEADERS}, 38 38 )
+1 -3
src/state/queries/messages/mute-conversation.ts
··· 21 21 }, 22 22 ) { 23 23 const queryClient = useQueryClient() 24 - const {getAgent} = useAgent() 24 + const agent = useAgent() 25 25 26 26 return useMutation({ 27 27 mutationFn: async ({mute}: {mute: boolean}) => { 28 28 if (!convoId) throw new Error('No convoId provided') 29 - 30 - const agent = getAgent() 31 29 if (mute) { 32 30 const {data} = await agent.api.chat.bsky.convo.muteConvo( 33 31 {convoId},
+2 -2
src/state/queries/my-blocked-accounts.ts
··· 13 13 type RQPageParam = string | undefined 14 14 15 15 export function useMyBlockedAccountsQuery() { 16 - const {getAgent} = useAgent() 16 + const agent = useAgent() 17 17 return useInfiniteQuery< 18 18 AppBskyGraphGetBlocks.OutputSchema, 19 19 Error, ··· 23 23 >({ 24 24 queryKey: RQKEY(), 25 25 async queryFn({pageParam}: {pageParam: RQPageParam}) { 26 - const res = await getAgent().app.bsky.graph.getBlocks({ 26 + const res = await agent.app.bsky.graph.getBlocks({ 27 27 limit: 30, 28 28 cursor: pageParam, 29 29 })
+7 -7
src/state/queries/my-lists.ts
··· 16 16 17 17 export function useMyListsQuery(filter: MyListsFilter) { 18 18 const {currentAccount} = useSession() 19 - const {getAgent} = useAgent() 19 + const agent = useAgent() 20 20 return useQuery<AppBskyGraphDefs.ListView[]>({ 21 21 staleTime: STALE.MINUTES.ONE, 22 22 queryKey: RQKEY(filter), ··· 24 24 let lists: AppBskyGraphDefs.ListView[] = [] 25 25 const promises = [ 26 26 accumulate(cursor => 27 - getAgent() 28 - .app.bsky.graph.getLists({ 27 + agent.app.bsky.graph 28 + .getLists({ 29 29 actor: currentAccount!.did, 30 30 cursor, 31 31 limit: 50, ··· 39 39 if (filter === 'all-including-subscribed' || filter === 'mod') { 40 40 promises.push( 41 41 accumulate(cursor => 42 - getAgent() 43 - .app.bsky.graph.getListMutes({ 42 + agent.app.bsky.graph 43 + .getListMutes({ 44 44 cursor, 45 45 limit: 50, 46 46 }) ··· 52 52 ) 53 53 promises.push( 54 54 accumulate(cursor => 55 - getAgent() 56 - .app.bsky.graph.getListBlocks({ 55 + agent.app.bsky.graph 56 + .getListBlocks({ 57 57 cursor, 58 58 limit: 50, 59 59 })
+2 -2
src/state/queries/my-muted-accounts.ts
··· 13 13 type RQPageParam = string | undefined 14 14 15 15 export function useMyMutedAccountsQuery() { 16 - const {getAgent} = useAgent() 16 + const agent = useAgent() 17 17 return useInfiniteQuery< 18 18 AppBskyGraphGetMutes.OutputSchema, 19 19 Error, ··· 23 23 >({ 24 24 queryKey: RQKEY(), 25 25 async queryFn({pageParam}: {pageParam: RQPageParam}) { 26 - const res = await getAgent().app.bsky.graph.getMutes({ 26 + const res = await agent.app.bsky.graph.getMutes({ 27 27 limit: 30, 28 28 cursor: pageParam, 29 29 })
+2 -2
src/state/queries/notifications/feed.ts
··· 47 47 } 48 48 49 49 export function useNotificationFeedQuery(opts?: {enabled?: boolean}) { 50 - const {getAgent} = useAgent() 50 + const agent = useAgent() 51 51 const queryClient = useQueryClient() 52 52 const moderationOpts = useModerationOpts() 53 53 const threadMutes = useMutedThreads() ··· 73 73 if (!page) { 74 74 page = ( 75 75 await fetchPage({ 76 - getAgent, 76 + agent, 77 77 limit: PAGE_SIZE, 78 78 cursor: pageParam, 79 79 queryClient,
+5 -5
src/state/queries/notifications/unread.tsx
··· 45 45 46 46 export function Provider({children}: React.PropsWithChildren<{}>) { 47 47 const {hasSession} = useSession() 48 - const {getAgent} = useAgent() 48 + const agent = useAgent() 49 49 const queryClient = useQueryClient() 50 50 const moderationOpts = useModerationOpts() 51 51 const threadMutes = useMutedThreads() ··· 112 112 return { 113 113 async markAllRead() { 114 114 // update server 115 - await getAgent().updateSeenNotifications( 115 + await agent.updateSeenNotifications( 116 116 cacheRef.current.syncedAt.toISOString(), 117 117 ) 118 118 ··· 127 127 isPoll, 128 128 }: {invalidate?: boolean; isPoll?: boolean} = {}) { 129 129 try { 130 - if (!getAgent().session) return 130 + if (!agent.session) return 131 131 if (AppState.currentState !== 'active') { 132 132 return 133 133 } ··· 142 142 143 143 // count 144 144 const {page, indexedAt: lastIndexed} = await fetchPage({ 145 - getAgent, 145 + agent, 146 146 cursor: undefined, 147 147 limit: 40, 148 148 queryClient, ··· 192 192 } 193 193 }, 194 194 } 195 - }, [setNumUnread, queryClient, moderationOpts, threadMutes, getAgent]) 195 + }, [setNumUnread, queryClient, moderationOpts, threadMutes, agent]) 196 196 checkUnreadRef.current = api.checkUnread 197 197 198 198 return (
+6 -8
src/state/queries/notifications/util.ts
··· 23 23 // = 24 24 25 25 export async function fetchPage({ 26 - getAgent, 26 + agent, 27 27 cursor, 28 28 limit, 29 29 queryClient, ··· 31 31 threadMutes, 32 32 fetchAdditionalData, 33 33 }: { 34 - getAgent: () => BskyAgent 34 + agent: BskyAgent 35 35 cursor: string | undefined 36 36 limit: number 37 37 queryClient: QueryClient ··· 39 39 threadMutes: string[] 40 40 fetchAdditionalData: boolean 41 41 }): Promise<{page: FeedPage; indexedAt: string | undefined}> { 42 - const res = await getAgent().listNotifications({ 42 + const res = await agent.listNotifications({ 43 43 limit, 44 44 cursor, 45 45 }) ··· 56 56 // we fetch subjects of notifications (usually posts) now instead of lazily 57 57 // in the UI to avoid relayouts 58 58 if (fetchAdditionalData) { 59 - const subjects = await fetchSubjects(getAgent, notifsGrouped) 59 + const subjects = await fetchSubjects(agent, notifsGrouped) 60 60 for (const notif of notifsGrouped) { 61 61 if (notif.subjectUri) { 62 62 notif.subject = subjects.get(notif.subjectUri) ··· 140 140 } 141 141 142 142 async function fetchSubjects( 143 - getAgent: () => BskyAgent, 143 + agent: BskyAgent, 144 144 groupedNotifs: FeedNotification[], 145 145 ): Promise<Map<string, AppBskyFeedDefs.PostView>> { 146 146 const uris = new Set<string>() ··· 152 152 const uriChunks = chunk(Array.from(uris), 25) 153 153 const postsChunks = await Promise.all( 154 154 uriChunks.map(uris => 155 - getAgent() 156 - .app.bsky.feed.getPosts({uris}) 157 - .then(res => res.data.posts), 155 + agent.app.bsky.feed.getPosts({uris}).then(res => res.data.posts), 158 156 ), 159 157 ) 160 158 const map = new Map<string, AppBskyFeedDefs.PostView>()
+13 -13
src/state/queries/post-feed.ts
··· 117 117 f => f.pinned && f.value === 'following', 118 118 ) ?? -1 119 119 const enableFollowingToDiscoverFallback = followingPinnedIndex === 0 120 - const {getAgent} = useAgent() 120 + const agent = useAgent() 121 121 const lastRun = useRef<{ 122 122 data: InfiniteData<FeedPageUnselected> 123 123 args: typeof selectArgs ··· 155 155 feedDesc, 156 156 feedParams: params || {}, 157 157 feedTuners, 158 - getAgent, 158 + agent, 159 159 // Not in the query key because they don't change: 160 160 userInterests, 161 161 // Not in the query key. Reacting to it switching isn't important: ··· 173 173 * moderations happen later, which results in some posts being shown and 174 174 * some not. 175 175 */ 176 - if (!getAgent().session) { 176 + if (!agent.session) { 177 177 assertSomePostsPassModeration(res.feed) 178 178 } 179 179 ··· 397 397 feedParams, 398 398 feedTuners, 399 399 userInterests, 400 - getAgent, 400 + agent, 401 401 enableFollowingToDiscoverFallback, 402 402 }: { 403 403 feedDesc: FeedDescriptor 404 404 feedParams: FeedParams 405 405 feedTuners: FeedTunerFn[] 406 406 userInterests?: string 407 - getAgent: () => BskyAgent 407 + agent: BskyAgent 408 408 enableFollowingToDiscoverFallback: boolean 409 409 }) { 410 410 if (feedDesc === 'following') { 411 411 if (feedParams.mergeFeedEnabled) { 412 412 return new MergeFeedAPI({ 413 - getAgent, 413 + agent, 414 414 feedParams, 415 415 feedTuners, 416 416 userInterests, 417 417 }) 418 418 } else { 419 419 if (enableFollowingToDiscoverFallback) { 420 - return new HomeFeedAPI({getAgent, userInterests}) 420 + return new HomeFeedAPI({agent, userInterests}) 421 421 } else { 422 - return new FollowingFeedAPI({getAgent}) 422 + return new FollowingFeedAPI({agent}) 423 423 } 424 424 } 425 425 } else if (feedDesc.startsWith('author')) { 426 426 const [_, actor, filter] = feedDesc.split('|') 427 - return new AuthorFeedAPI({getAgent, feedParams: {actor, filter}}) 427 + return new AuthorFeedAPI({agent, feedParams: {actor, filter}}) 428 428 } else if (feedDesc.startsWith('likes')) { 429 429 const [_, actor] = feedDesc.split('|') 430 - return new LikesFeedAPI({getAgent, feedParams: {actor}}) 430 + return new LikesFeedAPI({agent, feedParams: {actor}}) 431 431 } else if (feedDesc.startsWith('feedgen')) { 432 432 const [_, feed] = feedDesc.split('|') 433 433 return new CustomFeedAPI({ 434 - getAgent, 434 + agent, 435 435 feedParams: {feed}, 436 436 userInterests, 437 437 }) 438 438 } else if (feedDesc.startsWith('list')) { 439 439 const [_, list] = feedDesc.split('|') 440 - return new ListFeedAPI({getAgent, feedParams: {list}}) 440 + return new ListFeedAPI({agent, feedParams: {list}}) 441 441 } else { 442 442 // shouldnt happen 443 - return new FollowingFeedAPI({getAgent}) 443 + return new FollowingFeedAPI({agent}) 444 444 } 445 445 } 446 446
+2 -2
src/state/queries/post-liked-by.ts
··· 16 16 export const RQKEY = (resolvedUri: string) => [RQKEY_ROOT, resolvedUri] 17 17 18 18 export function useLikedByQuery(resolvedUri: string | undefined) { 19 - const {getAgent} = useAgent() 19 + const agent = useAgent() 20 20 return useInfiniteQuery< 21 21 AppBskyFeedGetLikes.OutputSchema, 22 22 Error, ··· 26 26 >({ 27 27 queryKey: RQKEY(resolvedUri || ''), 28 28 async queryFn({pageParam}: {pageParam: RQPageParam}) { 29 - const res = await getAgent().getLikes({ 29 + const res = await agent.getLikes({ 30 30 uri: resolvedUri || '', 31 31 limit: PAGE_SIZE, 32 32 cursor: pageParam,
+2 -2
src/state/queries/post-reposted-by.ts
··· 16 16 export const RQKEY = (resolvedUri: string) => [RQKEY_ROOT, resolvedUri] 17 17 18 18 export function usePostRepostedByQuery(resolvedUri: string | undefined) { 19 - const {getAgent} = useAgent() 19 + const agent = useAgent() 20 20 return useInfiniteQuery< 21 21 AppBskyFeedGetRepostedBy.OutputSchema, 22 22 Error, ··· 26 26 >({ 27 27 queryKey: RQKEY(resolvedUri || ''), 28 28 async queryFn({pageParam}: {pageParam: RQPageParam}) { 29 - const res = await getAgent().getRepostedBy({ 29 + const res = await agent.getRepostedBy({ 30 30 uri: resolvedUri || '', 31 31 limit: PAGE_SIZE, 32 32 cursor: pageParam,
+2 -2
src/state/queries/post-thread.ts
··· 68 68 69 69 export function usePostThreadQuery(uri: string | undefined) { 70 70 const queryClient = useQueryClient() 71 - const {getAgent} = useAgent() 71 + const agent = useAgent() 72 72 return useQuery<ThreadNode, Error>({ 73 73 gcTime: 0, 74 74 queryKey: RQKEY(uri || ''), 75 75 async queryFn() { 76 - const res = await getAgent().getPostThread({uri: uri!}) 76 + const res = await agent.getPostThread({uri: uri!}) 77 77 if (res.success) { 78 78 return responseToThreadNodes(res.data.thread) 79 79 }
+16 -16
src/state/queries/post.ts
··· 14 14 export const RQKEY = (postUri: string) => [RQKEY_ROOT, postUri] 15 15 16 16 export function usePostQuery(uri: string | undefined) { 17 - const {getAgent} = useAgent() 17 + const agent = useAgent() 18 18 return useQuery<AppBskyFeedDefs.PostView>({ 19 19 queryKey: RQKEY(uri || ''), 20 20 async queryFn() { 21 - const res = await getAgent().getPosts({uris: [uri!]}) 21 + const res = await agent.getPosts({uris: [uri!]}) 22 22 if (res.success && res.data.posts[0]) { 23 23 return res.data.posts[0] 24 24 } ··· 31 31 32 32 export function useGetPost() { 33 33 const queryClient = useQueryClient() 34 - const {getAgent} = useAgent() 34 + const agent = useAgent() 35 35 return useCallback( 36 36 async ({uri}: {uri: string}) => { 37 37 return queryClient.fetchQuery({ ··· 40 40 const urip = new AtUri(uri) 41 41 42 42 if (!urip.host.startsWith('did:')) { 43 - const res = await getAgent().resolveHandle({ 43 + const res = await agent.resolveHandle({ 44 44 handle: urip.host, 45 45 }) 46 46 urip.host = res.data.did 47 47 } 48 48 49 - const res = await getAgent().getPosts({ 49 + const res = await agent.getPosts({ 50 50 uris: [urip.toString()!], 51 51 }) 52 52 ··· 58 58 }, 59 59 }) 60 60 }, 61 - [queryClient, getAgent], 61 + [queryClient, agent], 62 62 ) 63 63 } 64 64 ··· 127 127 const {currentAccount} = useSession() 128 128 const queryClient = useQueryClient() 129 129 const postAuthor = post.author 130 - const {getAgent} = useAgent() 130 + const agent = useAgent() 131 131 return useMutation< 132 132 {uri: string}, // responds with the uri of the like 133 133 Error, ··· 154 154 ? toClout(post.likeCount + post.repostCount + post.replyCount) 155 155 : undefined, 156 156 }) 157 - return getAgent().like(uri, cid) 157 + return agent.like(uri, cid) 158 158 }, 159 159 onSuccess() { 160 160 track('Post:Like') ··· 165 165 function usePostUnlikeMutation( 166 166 logContext: LogEvents['post:unlike']['logContext'], 167 167 ) { 168 - const {getAgent} = useAgent() 168 + const agent = useAgent() 169 169 return useMutation<void, Error, {postUri: string; likeUri: string}>({ 170 170 mutationFn: ({likeUri}) => { 171 171 logEvent('post:unlike', {logContext}) 172 - return getAgent().deleteLike(likeUri) 172 + return agent.deleteLike(likeUri) 173 173 }, 174 174 onSuccess() { 175 175 track('Post:Unlike') ··· 238 238 function usePostRepostMutation( 239 239 logContext: LogEvents['post:repost']['logContext'], 240 240 ) { 241 - const {getAgent} = useAgent() 241 + const agent = useAgent() 242 242 return useMutation< 243 243 {uri: string}, // responds with the uri of the repost 244 244 Error, ··· 246 246 >({ 247 247 mutationFn: post => { 248 248 logEvent('post:repost', {logContext}) 249 - return getAgent().repost(post.uri, post.cid) 249 + return agent.repost(post.uri, post.cid) 250 250 }, 251 251 onSuccess() { 252 252 track('Post:Repost') ··· 257 257 function usePostUnrepostMutation( 258 258 logContext: LogEvents['post:unrepost']['logContext'], 259 259 ) { 260 - const {getAgent} = useAgent() 260 + const agent = useAgent() 261 261 return useMutation<void, Error, {postUri: string; repostUri: string}>({ 262 262 mutationFn: ({repostUri}) => { 263 263 logEvent('post:unrepost', {logContext}) 264 - return getAgent().deleteRepost(repostUri) 264 + return agent.deleteRepost(repostUri) 265 265 }, 266 266 onSuccess() { 267 267 track('Post:Unrepost') ··· 271 271 272 272 export function usePostDeleteMutation() { 273 273 const queryClient = useQueryClient() 274 - const {getAgent} = useAgent() 274 + const agent = useAgent() 275 275 return useMutation<void, Error, {uri: string}>({ 276 276 mutationFn: async ({uri}) => { 277 - await getAgent().deletePost(uri) 277 + await agent.deletePost(uri) 278 278 }, 279 279 onSuccess(data, variables) { 280 280 updatePostShadow(queryClient, variables.uri, {isDeleted: true})
+33 -35
src/state/queries/preferences/index.ts
··· 30 30 export const preferencesQueryKey = [preferencesQueryKeyRoot] 31 31 32 32 export function usePreferencesQuery() { 33 - const {getAgent} = useAgent() 33 + const agent = useAgent() 34 34 return useQuery({ 35 35 staleTime: STALE.SECONDS.FIFTEEN, 36 36 structuralSharing: replaceEqualDeep, 37 37 refetchOnWindowFocus: true, 38 38 queryKey: preferencesQueryKey, 39 39 queryFn: async () => { 40 - const agent = getAgent() 41 - 42 40 if (agent.session?.did === undefined) { 43 41 return DEFAULT_LOGGED_OUT_PREFERENCES 44 42 } else { ··· 75 73 76 74 export function useClearPreferencesMutation() { 77 75 const queryClient = useQueryClient() 78 - const {getAgent} = useAgent() 76 + const agent = useAgent() 79 77 80 78 return useMutation({ 81 79 mutationFn: async () => { 82 - await getAgent().app.bsky.actor.putPreferences({preferences: []}) 80 + await agent.app.bsky.actor.putPreferences({preferences: []}) 83 81 // triggers a refetch 84 82 await queryClient.invalidateQueries({ 85 83 queryKey: preferencesQueryKey, ··· 89 87 } 90 88 91 89 export function usePreferencesSetContentLabelMutation() { 92 - const {getAgent} = useAgent() 90 + const agent = useAgent() 93 91 const queryClient = useQueryClient() 94 92 95 93 return useMutation< ··· 98 96 {label: string; visibility: LabelPreference; labelerDid: string | undefined} 99 97 >({ 100 98 mutationFn: async ({label, visibility, labelerDid}) => { 101 - await getAgent().setContentLabelPref(label, visibility, labelerDid) 99 + await agent.setContentLabelPref(label, visibility, labelerDid) 102 100 // triggers a refetch 103 101 await queryClient.invalidateQueries({ 104 102 queryKey: preferencesQueryKey, ··· 109 107 110 108 export function useSetContentLabelMutation() { 111 109 const queryClient = useQueryClient() 112 - const {getAgent} = useAgent() 110 + const agent = useAgent() 113 111 114 112 return useMutation({ 115 113 mutationFn: async ({ ··· 121 119 visibility: LabelPreference 122 120 labelerDid?: string 123 121 }) => { 124 - await getAgent().setContentLabelPref(label, visibility, labelerDid) 122 + await agent.setContentLabelPref(label, visibility, labelerDid) 125 123 // triggers a refetch 126 124 await queryClient.invalidateQueries({ 127 125 queryKey: preferencesQueryKey, ··· 132 130 133 131 export function usePreferencesSetAdultContentMutation() { 134 132 const queryClient = useQueryClient() 135 - const {getAgent} = useAgent() 133 + const agent = useAgent() 136 134 137 135 return useMutation<void, unknown, {enabled: boolean}>({ 138 136 mutationFn: async ({enabled}) => { 139 - await getAgent().setAdultContentEnabled(enabled) 137 + await agent.setAdultContentEnabled(enabled) 140 138 // triggers a refetch 141 139 await queryClient.invalidateQueries({ 142 140 queryKey: preferencesQueryKey, ··· 147 145 148 146 export function usePreferencesSetBirthDateMutation() { 149 147 const queryClient = useQueryClient() 150 - const {getAgent} = useAgent() 148 + const agent = useAgent() 151 149 152 150 return useMutation<void, unknown, {birthDate: Date}>({ 153 151 mutationFn: async ({birthDate}: {birthDate: Date}) => { 154 - await getAgent().setPersonalDetails({birthDate: birthDate.toISOString()}) 152 + await agent.setPersonalDetails({birthDate: birthDate.toISOString()}) 155 153 // triggers a refetch 156 154 await queryClient.invalidateQueries({ 157 155 queryKey: preferencesQueryKey, ··· 162 160 163 161 export function useSetFeedViewPreferencesMutation() { 164 162 const queryClient = useQueryClient() 165 - const {getAgent} = useAgent() 163 + const agent = useAgent() 166 164 167 165 return useMutation<void, unknown, Partial<BskyFeedViewPreference>>({ 168 166 mutationFn: async prefs => { ··· 170 168 * special handling here, merged into `feedViewPrefs` above, since 171 169 * following was previously called `home` 172 170 */ 173 - await getAgent().setFeedViewPrefs('home', prefs) 171 + await agent.setFeedViewPrefs('home', prefs) 174 172 // triggers a refetch 175 173 await queryClient.invalidateQueries({ 176 174 queryKey: preferencesQueryKey, ··· 181 179 182 180 export function useSetThreadViewPreferencesMutation() { 183 181 const queryClient = useQueryClient() 184 - const {getAgent} = useAgent() 182 + const agent = useAgent() 185 183 186 184 return useMutation<void, unknown, Partial<ThreadViewPreferences>>({ 187 185 mutationFn: async prefs => { 188 - await getAgent().setThreadViewPrefs(prefs) 186 + await agent.setThreadViewPrefs(prefs) 189 187 // triggers a refetch 190 188 await queryClient.invalidateQueries({ 191 189 queryKey: preferencesQueryKey, ··· 196 194 197 195 export function useOverwriteSavedFeedsMutation() { 198 196 const queryClient = useQueryClient() 199 - const {getAgent} = useAgent() 197 + const agent = useAgent() 200 198 201 199 return useMutation<void, unknown, AppBskyActorDefs.SavedFeed[]>({ 202 200 mutationFn: async savedFeeds => { 203 - await getAgent().overwriteSavedFeeds(savedFeeds) 201 + await agent.overwriteSavedFeeds(savedFeeds) 204 202 // triggers a refetch 205 203 await queryClient.invalidateQueries({ 206 204 queryKey: preferencesQueryKey, ··· 211 209 212 210 export function useAddSavedFeedsMutation() { 213 211 const queryClient = useQueryClient() 214 - const {getAgent} = useAgent() 212 + const agent = useAgent() 215 213 216 214 return useMutation< 217 215 void, ··· 219 217 Pick<AppBskyActorDefs.SavedFeed, 'type' | 'value' | 'pinned'>[] 220 218 >({ 221 219 mutationFn: async savedFeeds => { 222 - await getAgent().addSavedFeeds(savedFeeds) 220 + await agent.addSavedFeeds(savedFeeds) 223 221 track('CustomFeed:Save') 224 222 // triggers a refetch 225 223 await queryClient.invalidateQueries({ ··· 231 229 232 230 export function useRemoveFeedMutation() { 233 231 const queryClient = useQueryClient() 234 - const {getAgent} = useAgent() 232 + const agent = useAgent() 235 233 236 234 return useMutation<void, unknown, Pick<AppBskyActorDefs.SavedFeed, 'id'>>({ 237 235 mutationFn: async savedFeed => { 238 - await getAgent().removeSavedFeeds([savedFeed.id]) 236 + await agent.removeSavedFeeds([savedFeed.id]) 239 237 track('CustomFeed:Unsave') 240 238 // triggers a refetch 241 239 await queryClient.invalidateQueries({ ··· 247 245 248 246 export function useReplaceForYouWithDiscoverFeedMutation() { 249 247 const queryClient = useQueryClient() 250 - const {getAgent} = useAgent() 248 + const agent = useAgent() 251 249 252 250 return useMutation({ 253 251 mutationFn: async ({ ··· 258 256 discoverFeedConfig: AppBskyActorDefs.SavedFeed | undefined 259 257 }) => { 260 258 if (forYouFeedConfig) { 261 - await getAgent().removeSavedFeeds([forYouFeedConfig.id]) 259 + await agent.removeSavedFeeds([forYouFeedConfig.id]) 262 260 } 263 261 if (!discoverFeedConfig) { 264 - await getAgent().addSavedFeeds([ 262 + await agent.addSavedFeeds([ 265 263 { 266 264 type: 'feed', 267 265 value: PROD_DEFAULT_FEED('whats-hot'), ··· 269 267 }, 270 268 ]) 271 269 } else { 272 - await getAgent().updateSavedFeeds([ 270 + await agent.updateSavedFeeds([ 273 271 { 274 272 ...discoverFeedConfig, 275 273 pinned: true, ··· 286 284 287 285 export function useUpdateSavedFeedsMutation() { 288 286 const queryClient = useQueryClient() 289 - const {getAgent} = useAgent() 287 + const agent = useAgent() 290 288 291 289 return useMutation<void, unknown, AppBskyActorDefs.SavedFeed[]>({ 292 290 mutationFn: async feeds => { 293 - await getAgent().updateSavedFeeds(feeds) 291 + await agent.updateSavedFeeds(feeds) 294 292 295 293 // triggers a refetch 296 294 await queryClient.invalidateQueries({ ··· 302 300 303 301 export function useUpsertMutedWordsMutation() { 304 302 const queryClient = useQueryClient() 305 - const {getAgent} = useAgent() 303 + const agent = useAgent() 306 304 307 305 return useMutation({ 308 306 mutationFn: async (mutedWords: AppBskyActorDefs.MutedWord[]) => { 309 - await getAgent().upsertMutedWords(mutedWords) 307 + await agent.upsertMutedWords(mutedWords) 310 308 // triggers a refetch 311 309 await queryClient.invalidateQueries({ 312 310 queryKey: preferencesQueryKey, ··· 317 315 318 316 export function useUpdateMutedWordMutation() { 319 317 const queryClient = useQueryClient() 320 - const {getAgent} = useAgent() 318 + const agent = useAgent() 321 319 322 320 return useMutation({ 323 321 mutationFn: async (mutedWord: AppBskyActorDefs.MutedWord) => { 324 - await getAgent().updateMutedWord(mutedWord) 322 + await agent.updateMutedWord(mutedWord) 325 323 // triggers a refetch 326 324 await queryClient.invalidateQueries({ 327 325 queryKey: preferencesQueryKey, ··· 332 330 333 331 export function useRemoveMutedWordMutation() { 334 332 const queryClient = useQueryClient() 335 - const {getAgent} = useAgent() 333 + const agent = useAgent() 336 334 337 335 return useMutation({ 338 336 mutationFn: async (mutedWord: AppBskyActorDefs.MutedWord) => { 339 - await getAgent().removeMutedWord(mutedWord) 337 + await agent.removeMutedWord(mutedWord) 340 338 // triggers a refetch 341 339 await queryClient.invalidateQueries({ 342 340 queryKey: preferencesQueryKey,
+2 -2
src/state/queries/profile-feedgens.ts
··· 15 15 opts?: {enabled?: boolean}, 16 16 ) { 17 17 const enabled = opts?.enabled !== false 18 - const {getAgent} = useAgent() 18 + const agent = useAgent() 19 19 return useInfiniteQuery< 20 20 AppBskyFeedGetActorFeeds.OutputSchema, 21 21 Error, ··· 25 25 >({ 26 26 queryKey: RQKEY(did), 27 27 async queryFn({pageParam}: {pageParam: RQPageParam}) { 28 - const res = await getAgent().app.bsky.feed.getActorFeeds({ 28 + const res = await agent.app.bsky.feed.getActorFeeds({ 29 29 actor: did, 30 30 limit: PAGE_SIZE, 31 31 cursor: pageParam,
+2 -2
src/state/queries/profile-followers.ts
··· 15 15 export const RQKEY = (did: string) => [RQKEY_ROOT, did] 16 16 17 17 export function useProfileFollowersQuery(did: string | undefined) { 18 - const {getAgent} = useAgent() 18 + const agent = useAgent() 19 19 return useInfiniteQuery< 20 20 AppBskyGraphGetFollowers.OutputSchema, 21 21 Error, ··· 25 25 >({ 26 26 queryKey: RQKEY(did || ''), 27 27 async queryFn({pageParam}: {pageParam: RQPageParam}) { 28 - const res = await getAgent().app.bsky.graph.getFollowers({ 28 + const res = await agent.app.bsky.graph.getFollowers({ 29 29 actor: did || '', 30 30 limit: PAGE_SIZE, 31 31 cursor: pageParam,
+2 -2
src/state/queries/profile-follows.ts
··· 26 26 limit: PAGE_SIZE, 27 27 }, 28 28 ) { 29 - const {getAgent} = useAgent() 29 + const agent = useAgent() 30 30 return useInfiniteQuery< 31 31 AppBskyGraphGetFollows.OutputSchema, 32 32 Error, ··· 37 37 staleTime: STALE.MINUTES.ONE, 38 38 queryKey: RQKEY(did || ''), 39 39 async queryFn({pageParam}: {pageParam: RQPageParam}) { 40 - const res = await getAgent().app.bsky.graph.getFollows({ 40 + const res = await agent.app.bsky.graph.getFollows({ 41 41 actor: did || '', 42 42 limit: limit || PAGE_SIZE, 43 43 cursor: pageParam,
+2 -2
src/state/queries/profile-lists.ts
··· 11 11 12 12 export function useProfileListsQuery(did: string, opts?: {enabled?: boolean}) { 13 13 const enabled = opts?.enabled !== false 14 - const {getAgent} = useAgent() 14 + const agent = useAgent() 15 15 return useInfiniteQuery< 16 16 AppBskyGraphGetLists.OutputSchema, 17 17 Error, ··· 21 21 >({ 22 22 queryKey: RQKEY(did), 23 23 async queryFn({pageParam}: {pageParam: RQPageParam}) { 24 - const res = await getAgent().app.bsky.graph.getLists({ 24 + const res = await agent.app.bsky.graph.getLists({ 25 25 actor: did, 26 26 limit: PAGE_SIZE, 27 27 cursor: pageParam,
+26 -26
src/state/queries/profile.ts
··· 52 52 staleTime?: number 53 53 }) { 54 54 const queryClient = useQueryClient() 55 - const {getAgent} = useAgent() 55 + const agent = useAgent() 56 56 return useQuery<AppBskyActorDefs.ProfileViewDetailed>({ 57 57 // WARNING 58 58 // this staleTime is load-bearing ··· 62 62 refetchOnWindowFocus: true, 63 63 queryKey: RQKEY(did ?? ''), 64 64 queryFn: async () => { 65 - const res = await getAgent().getProfile({actor: did ?? ''}) 65 + const res = await agent.getProfile({actor: did ?? ''}) 66 66 return res.data 67 67 }, 68 68 placeholderData: () => { ··· 77 77 } 78 78 79 79 export function useProfilesQuery({handles}: {handles: string[]}) { 80 - const {getAgent} = useAgent() 80 + const agent = useAgent() 81 81 return useQuery({ 82 82 staleTime: STALE.MINUTES.FIVE, 83 83 queryKey: profilesQueryKey(handles), 84 84 queryFn: async () => { 85 - const res = await getAgent().getProfiles({actors: handles}) 85 + const res = await agent.getProfiles({actors: handles}) 86 86 return res.data 87 87 }, 88 88 }) 89 89 } 90 90 91 91 export function usePrefetchProfileQuery() { 92 - const {getAgent} = useAgent() 92 + const agent = useAgent() 93 93 const queryClient = useQueryClient() 94 94 const prefetchProfileQuery = useCallback( 95 95 async (did: string) => { 96 96 await queryClient.prefetchQuery({ 97 97 queryKey: RQKEY(did), 98 98 queryFn: async () => { 99 - const res = await getAgent().getProfile({actor: did || ''}) 99 + const res = await agent.getProfile({actor: did || ''}) 100 100 return res.data 101 101 }, 102 102 }) 103 103 }, 104 - [queryClient, getAgent], 104 + [queryClient, agent], 105 105 ) 106 106 return prefetchProfileQuery 107 107 } ··· 117 117 } 118 118 export function useProfileUpdateMutation() { 119 119 const queryClient = useQueryClient() 120 - const {getAgent} = useAgent() 120 + const agent = useAgent() 121 121 return useMutation<void, Error, ProfileUpdateParams>({ 122 122 mutationFn: async ({ 123 123 profile, ··· 131 131 | undefined 132 132 if (newUserAvatar) { 133 133 newUserAvatarPromise = uploadBlob( 134 - getAgent(), 134 + agent, 135 135 newUserAvatar.path, 136 136 newUserAvatar.mime, 137 137 ) ··· 141 141 | undefined 142 142 if (newUserBanner) { 143 143 newUserBannerPromise = uploadBlob( 144 - getAgent(), 144 + agent, 145 145 newUserBanner.path, 146 146 newUserBanner.mime, 147 147 ) 148 148 } 149 - await getAgent().upsertProfile(async existing => { 149 + await agent.upsertProfile(async existing => { 150 150 existing = existing || {} 151 151 if (typeof updates === 'function') { 152 152 existing = updates(existing) ··· 169 169 return existing 170 170 }) 171 171 await whenAppViewReady( 172 - getAgent, 172 + agent, 173 173 profile.did, 174 174 checkCommitted || 175 175 (res => { ··· 271 271 profile: Shadow<AppBskyActorDefs.ProfileViewDetailed>, 272 272 ) { 273 273 const {currentAccount} = useSession() 274 - const {getAgent} = useAgent() 274 + const agent = useAgent() 275 275 const queryClient = useQueryClient() 276 276 return useMutation<{uri: string; cid: string}, Error, {did: string}>({ 277 277 mutationFn: async ({did}) => { ··· 287 287 followeeClout: toClout(profile.followersCount), 288 288 followerClout: toClout(ownProfile?.followersCount), 289 289 }) 290 - return await getAgent().follow(did) 290 + return await agent.follow(did) 291 291 }, 292 292 onSuccess(data, variables) { 293 293 track('Profile:Follow', {username: variables.did}) ··· 298 298 function useProfileUnfollowMutation( 299 299 logContext: LogEvents['profile:unfollow']['logContext'], 300 300 ) { 301 - const {getAgent} = useAgent() 301 + const agent = useAgent() 302 302 return useMutation<void, Error, {did: string; followUri: string}>({ 303 303 mutationFn: async ({followUri}) => { 304 304 logEvent('profile:unfollow', {logContext}) 305 305 track('Profile:Unfollow', {username: followUri}) 306 - return await getAgent().deleteFollow(followUri) 306 + return await agent.deleteFollow(followUri) 307 307 }, 308 308 }) 309 309 } ··· 359 359 360 360 function useProfileMuteMutation() { 361 361 const queryClient = useQueryClient() 362 - const {getAgent} = useAgent() 362 + const agent = useAgent() 363 363 return useMutation<void, Error, {did: string}>({ 364 364 mutationFn: async ({did}) => { 365 - await getAgent().mute(did) 365 + await agent.mute(did) 366 366 }, 367 367 onSuccess() { 368 368 queryClient.invalidateQueries({queryKey: RQKEY_MY_MUTED()}) ··· 372 372 373 373 function useProfileUnmuteMutation() { 374 374 const queryClient = useQueryClient() 375 - const {getAgent} = useAgent() 375 + const agent = useAgent() 376 376 return useMutation<void, Error, {did: string}>({ 377 377 mutationFn: async ({did}) => { 378 - await getAgent().unmute(did) 378 + await agent.unmute(did) 379 379 }, 380 380 onSuccess() { 381 381 queryClient.invalidateQueries({queryKey: RQKEY_MY_MUTED()}) ··· 440 440 441 441 function useProfileBlockMutation() { 442 442 const {currentAccount} = useSession() 443 - const {getAgent} = useAgent() 443 + const agent = useAgent() 444 444 const queryClient = useQueryClient() 445 445 return useMutation<{uri: string; cid: string}, Error, {did: string}>({ 446 446 mutationFn: async ({did}) => { 447 447 if (!currentAccount) { 448 448 throw new Error('Not signed in') 449 449 } 450 - return await getAgent().app.bsky.graph.block.create( 450 + return await agent.app.bsky.graph.block.create( 451 451 {repo: currentAccount.did}, 452 452 {subject: did, createdAt: new Date().toISOString()}, 453 453 ) ··· 461 461 462 462 function useProfileUnblockMutation() { 463 463 const {currentAccount} = useSession() 464 - const {getAgent} = useAgent() 464 + const agent = useAgent() 465 465 const queryClient = useQueryClient() 466 466 return useMutation<void, Error, {did: string; blockUri: string}>({ 467 467 mutationFn: async ({blockUri}) => { ··· 469 469 throw new Error('Not signed in') 470 470 } 471 471 const {rkey} = new AtUri(blockUri) 472 - await getAgent().app.bsky.graph.block.delete({ 472 + await agent.app.bsky.graph.block.delete({ 473 473 repo: currentAccount.did, 474 474 rkey, 475 475 }) ··· 489 489 } 490 490 491 491 async function whenAppViewReady( 492 - getAgent: () => BskyAgent, 492 + agent: BskyAgent, 493 493 actor: string, 494 494 fn: (res: AppBskyActorGetProfile.Response) => boolean, 495 495 ) { ··· 497 497 5, // 5 tries 498 498 1e3, // 1s delay between tries 499 499 fn, 500 - () => getAgent().app.bsky.actor.getProfile({actor}), 500 + () => agent.app.bsky.actor.getProfile({actor}), 501 501 ) 502 502 } 503 503
+2 -2
src/state/queries/resolve-uri.ts
··· 24 24 25 25 export function useResolveDidQuery(didOrHandle: string | undefined) { 26 26 const queryClient = useQueryClient() 27 - const {getAgent} = useAgent() 27 + const agent = useAgent() 28 28 29 29 return useQuery<string, Error>({ 30 30 staleTime: STALE.HOURS.ONE, ··· 34 34 // Just return the did if it's already one 35 35 if (didOrHandle.startsWith('did:')) return didOrHandle 36 36 37 - const res = await getAgent().resolveHandle({handle: didOrHandle}) 37 + const res = await agent.resolveHandle({handle: didOrHandle}) 38 38 return res.data.did 39 39 }, 40 40 initialData: () => {
+2 -2
src/state/queries/search-posts.ts
··· 25 25 sort?: 'top' | 'latest' 26 26 enabled?: boolean 27 27 }) { 28 - const {getAgent} = useAgent() 28 + const agent = useAgent() 29 29 return useInfiniteQuery< 30 30 AppBskyFeedSearchPosts.OutputSchema, 31 31 Error, ··· 35 35 >({ 36 36 queryKey: searchPostsQueryKey({query, sort}), 37 37 queryFn: async ({pageParam}) => { 38 - const res = await getAgent().app.bsky.feed.searchPosts({ 38 + const res = await agent.app.bsky.feed.searchPosts({ 39 39 q: query, 40 40 limit: 25, 41 41 cursor: pageParam,
+2 -2
src/state/queries/suggested-feeds.ts
··· 8 8 export const suggestedFeedsQueryKey = [suggestedFeedsQueryKeyRoot] 9 9 10 10 export function useSuggestedFeedsQuery() { 11 - const {getAgent} = useAgent() 11 + const agent = useAgent() 12 12 return useInfiniteQuery< 13 13 AppBskyFeedGetSuggestedFeeds.OutputSchema, 14 14 Error, ··· 19 19 staleTime: STALE.HOURS.ONE, 20 20 queryKey: suggestedFeedsQueryKey, 21 21 queryFn: async ({pageParam}) => { 22 - const res = await getAgent().app.bsky.feed.getSuggestedFeeds({ 22 + const res = await agent.app.bsky.feed.getSuggestedFeeds({ 23 23 limit: 10, 24 24 cursor: pageParam, 25 25 })
+4 -4
src/state/queries/suggested-follows.ts
··· 33 33 34 34 export function useSuggestedFollowsQuery() { 35 35 const {currentAccount} = useSession() 36 - const {getAgent} = useAgent() 36 + const agent = useAgent() 37 37 const moderationOpts = useModerationOpts() 38 38 const {data: preferences} = usePreferencesQuery() 39 39 ··· 49 49 queryKey: suggestedFollowsQueryKey, 50 50 queryFn: async ({pageParam}) => { 51 51 const contentLangs = getContentLanguages().join(',') 52 - const res = await getAgent().app.bsky.actor.getSuggestions( 52 + const res = await agent.app.bsky.actor.getSuggestions( 53 53 { 54 54 limit: 25, 55 55 cursor: pageParam, ··· 94 94 } 95 95 96 96 export function useSuggestedFollowsByActorQuery({did}: {did: string}) { 97 - const {getAgent} = useAgent() 97 + const agent = useAgent() 98 98 return useQuery<AppBskyGraphGetSuggestedFollowsByActor.OutputSchema, Error>({ 99 99 queryKey: suggestedFollowsByActorQueryKey(did), 100 100 queryFn: async () => { 101 - const res = await getAgent().app.bsky.graph.getSuggestedFollowsByActor({ 101 + const res = await agent.app.bsky.graph.getSuggestedFollowsByActor({ 102 102 actor: did, 103 103 }) 104 104 return res.data
+2 -9
src/state/session/index.tsx
··· 268 268 ) 269 269 } 270 270 271 - export function useAgent(): {getAgent: () => BskyAgent} { 271 + export function useAgent(): BskyAgent { 272 272 const agent = React.useContext(AgentContext) 273 273 if (!agent) { 274 274 throw Error('useAgent() must be below <SessionProvider>.') 275 275 } 276 - return React.useMemo( 277 - () => ({ 278 - getAgent() { 279 - return agent 280 - }, 281 - }), 282 - [agent], 283 - ) 276 + return agent 284 277 }
+2 -2
src/view/com/composer/Composer.tsx
··· 90 90 imageUris: initImageUris, 91 91 }: Props) { 92 92 const {currentAccount} = useSession() 93 - const {getAgent} = useAgent() 93 + const agent = useAgent() 94 94 const {data: currentProfile} = useProfileQuery({did: currentAccount!.did}) 95 95 const {isModalActive} = useModals() 96 96 const {closeComposer} = useComposerControls() ··· 260 260 let postUri 261 261 try { 262 262 postUri = ( 263 - await apilib.post(getAgent(), { 263 + await apilib.post(agent, { 264 264 rawText: richtext.text, 265 265 replyTo: replyTo?.uri, 266 266 images: gallery.images,
+3 -3
src/view/com/composer/useExternalLinkFetch.e2e.ts
··· 8 8 export function useExternalLinkFetch({}: { 9 9 setQuote: (opts: ComposerOpts['quote']) => void 10 10 }) { 11 - const {getAgent} = useAgent() 11 + const agent = useAgent() 12 12 const [extLink, setExtLink] = useState<apilib.ExternalEmbedDraft | undefined>( 13 13 undefined, 14 14 ) ··· 22 22 return cleanup 23 23 } 24 24 if (!extLink.meta) { 25 - getLinkMeta(getAgent(), extLink.uri).then(meta => { 25 + getLinkMeta(agent, extLink.uri).then(meta => { 26 26 if (aborted) { 27 27 return 28 28 } ··· 41 41 }) 42 42 } 43 43 return cleanup 44 - }, [extLink, getAgent]) 44 + }, [extLink, agent]) 45 45 46 46 return {extLink, setExtLink} 47 47 }
+5 -5
src/view/com/composer/useExternalLinkFetch.ts
··· 31 31 ) 32 32 const getPost = useGetPost() 33 33 const fetchDid = useFetchDid() 34 - const {getAgent} = useAgent() 34 + const agent = useAgent() 35 35 36 36 useEffect(() => { 37 37 let aborted = false ··· 59 59 }, 60 60 ) 61 61 } else if (isBskyCustomFeedUrl(extLink.uri)) { 62 - getFeedAsEmbed(getAgent(), fetchDid, extLink.uri).then( 62 + getFeedAsEmbed(agent, fetchDid, extLink.uri).then( 63 63 ({embed, meta}) => { 64 64 if (aborted) { 65 65 return ··· 77 77 }, 78 78 ) 79 79 } else if (isBskyListUrl(extLink.uri)) { 80 - getListAsEmbed(getAgent(), fetchDid, extLink.uri).then( 80 + getListAsEmbed(agent, fetchDid, extLink.uri).then( 81 81 ({embed, meta}) => { 82 82 if (aborted) { 83 83 return ··· 95 95 }, 96 96 ) 97 97 } else { 98 - getLinkMeta(getAgent(), extLink.uri).then(meta => { 98 + getLinkMeta(agent, extLink.uri).then(meta => { 99 99 if (aborted) { 100 100 return 101 101 } ··· 137 137 }) 138 138 } 139 139 return cleanup 140 - }, [extLink, setQuote, getPost, fetchDid, getAgent]) 140 + }, [extLink, setQuote, getPost, fetchDid, agent]) 141 141 142 142 return {extLink, setExtLink} 143 143 }
+6 -6
src/view/com/modals/ChangeEmail.tsx
··· 27 27 export function Component() { 28 28 const pal = usePalette('default') 29 29 const {currentAccount} = useSession() 30 - const {getAgent} = useAgent() 30 + const agent = useAgent() 31 31 const {_} = useLingui() 32 32 const [stage, setStage] = useState<Stages>(Stages.InputEmail) 33 33 const [email, setEmail] = useState<string>(currentAccount?.email || '') ··· 45 45 setError('') 46 46 setIsProcessing(true) 47 47 try { 48 - const res = await getAgent().com.atproto.server.requestEmailUpdate() 48 + const res = await agent.com.atproto.server.requestEmailUpdate() 49 49 if (res.data.tokenRequired) { 50 50 setStage(Stages.ConfirmCode) 51 51 } else { 52 - await getAgent().com.atproto.server.updateEmail({email: email.trim()}) 53 - await getAgent().resumeSession(getAgent().session!) 52 + await agent.com.atproto.server.updateEmail({email: email.trim()}) 53 + await agent.resumeSession(agent.session!) 54 54 Toast.show(_(msg`Email updated`)) 55 55 setStage(Stages.Done) 56 56 } ··· 75 75 setError('') 76 76 setIsProcessing(true) 77 77 try { 78 - await getAgent().com.atproto.server.updateEmail({ 78 + await agent.com.atproto.server.updateEmail({ 79 79 email: email.trim(), 80 80 token: confirmationCode.trim(), 81 81 }) 82 - await getAgent().resumeSession(getAgent().session!) 82 + await agent.resumeSession(agent.session!) 83 83 Toast.show(_(msg`Email updated`)) 84 84 setStage(Stages.Done) 85 85 } catch (e) {
+5 -5
src/view/com/modals/ChangeHandle.tsx
··· 35 35 36 36 export function Component(props: Props) { 37 37 const {currentAccount} = useSession() 38 - const {getAgent} = useAgent() 38 + const agent = useAgent() 39 39 const { 40 40 isLoading, 41 41 data: serviceInfo, 42 42 error: serviceInfoError, 43 - } = useServiceQuery(getAgent().service.toString()) 43 + } = useServiceQuery(agent.service.toString()) 44 44 45 45 return isLoading || !currentAccount ? ( 46 46 <View style={{padding: 18}}> ··· 71 71 const {closeModal} = useModalControls() 72 72 const {mutateAsync: updateHandle, isPending: isUpdateHandlePending} = 73 73 useUpdateHandleMutation() 74 - const {getAgent} = useAgent() 74 + const agent = useAgent() 75 75 76 76 const [error, setError] = useState<string>('') 77 77 ··· 111 111 await updateHandle({ 112 112 handle: newHandle, 113 113 }) 114 - await getAgent().resumeSession(getAgent().session!) 114 + await agent.resumeSession(agent.session!) 115 115 closeModal() 116 116 onChanged() 117 117 } catch (err: any) { ··· 129 129 closeModal, 130 130 updateHandle, 131 131 serviceInfo, 132 - getAgent, 132 + agent, 133 133 ]) 134 134 135 135 // rendering
+1 -2
src/view/com/modals/ChangePassword.tsx
··· 37 37 export function Component() { 38 38 const pal = usePalette('default') 39 39 const {currentAccount} = useSession() 40 - const {getAgent} = useAgent() 40 + const agent = useAgent() 41 41 const {_} = useLingui() 42 42 const [stage, setStage] = useState<Stages>(Stages.RequestCode) 43 43 const [isProcessing, setIsProcessing] = useState<boolean>(false) ··· 46 46 const [error, setError] = useState<string>('') 47 47 const {isMobile} = useWebMediaQueries() 48 48 const {closeModal} = useModalControls() 49 - const agent = getAgent() 50 49 51 50 const onRequestCode = async () => { 52 51 if (
+3 -3
src/view/com/modals/CreateOrEditList.tsx
··· 62 62 const {_} = useLingui() 63 63 const listCreateMutation = useListCreateMutation() 64 64 const listMetadataMutation = useListMetadataMutation() 65 - const {getAgent} = useAgent() 65 + const agent = useAgent() 66 66 67 67 const activePurpose = useMemo(() => { 68 68 if (list?.purpose) { ··· 157 157 {cleanNewlines: true}, 158 158 ) 159 159 160 - await richText.detectFacets(getAgent()) 160 + await richText.detectFacets(agent) 161 161 richText = shortenLinks(richText) 162 162 163 163 // filter out any mention facets that didn't map to a user ··· 229 229 listMetadataMutation, 230 230 listCreateMutation, 231 231 _, 232 - getAgent, 232 + agent, 233 233 ]) 234 234 235 235 return (
+4 -4
src/view/com/modals/DeleteAccount.tsx
··· 31 31 const pal = usePalette('default') 32 32 const theme = useTheme() 33 33 const {currentAccount} = useSession() 34 - const {getAgent} = useAgent() 34 + const agent = useAgent() 35 35 const {removeAccount} = useSessionApi() 36 36 const {_} = useLingui() 37 37 const {closeModal} = useModalControls() ··· 45 45 setError('') 46 46 setIsProcessing(true) 47 47 try { 48 - await getAgent().com.atproto.server.requestAccountDelete() 48 + await agent.com.atproto.server.requestAccountDelete() 49 49 setIsEmailSent(true) 50 50 } catch (e: any) { 51 51 setError(cleanError(e)) ··· 63 63 64 64 try { 65 65 // inform chat service of intent to delete account 66 - const {success} = await getAgent().api.chat.bsky.actor.deleteAccount( 66 + const {success} = await agent.api.chat.bsky.actor.deleteAccount( 67 67 undefined, 68 68 { 69 69 headers: DM_SERVICE_HEADERS, ··· 72 72 if (!success) { 73 73 throw new Error('Failed to inform chat service of account deletion') 74 74 } 75 - await getAgent().com.atproto.server.deleteAccount({ 75 + await agent.com.atproto.server.deleteAccount({ 76 76 did: currentAccount.did, 77 77 password, 78 78 token,
+4 -4
src/view/com/modals/VerifyEmail.tsx
··· 41 41 onSuccess?: () => void 42 42 }) { 43 43 const pal = usePalette('default') 44 - const {getAgent} = useAgent() 44 + const agent = useAgent() 45 45 const {currentAccount} = useSession() 46 46 const {_} = useLingui() 47 47 const [stage, setStage] = useState<Stages>( ··· 64 64 setError('') 65 65 setIsProcessing(true) 66 66 try { 67 - await getAgent().com.atproto.server.requestEmailConfirmation() 67 + await agent.com.atproto.server.requestEmailConfirmation() 68 68 setStage(Stages.ConfirmCode) 69 69 } catch (e) { 70 70 setError(cleanError(String(e))) ··· 77 77 setError('') 78 78 setIsProcessing(true) 79 79 try { 80 - await getAgent().com.atproto.server.confirmEmail({ 80 + await agent.com.atproto.server.confirmEmail({ 81 81 email: (currentAccount?.email || '').trim(), 82 82 token: confirmationCode.trim(), 83 83 }) 84 - await getAgent().resumeSession(getAgent().session!) 84 + await agent.resumeSession(agent.session!) 85 85 Toast.show(_(msg`Email verified`)) 86 86 closeModal() 87 87 onSuccess?.()
+3 -3
src/view/screens/Profile.tsx
··· 470 470 } 471 471 472 472 function useRichText(text: string): [RichTextAPI, boolean] { 473 - const {getAgent} = useAgent() 473 + const agent = useAgent() 474 474 const [prevText, setPrevText] = React.useState(text) 475 475 const [rawRT, setRawRT] = React.useState(() => new RichTextAPI({text})) 476 476 const [resolvedRT, setResolvedRT] = React.useState<RichTextAPI | null>(null) ··· 485 485 async function resolveRTFacets() { 486 486 // new each time 487 487 const resolvedRT = new RichTextAPI({text}) 488 - await resolvedRT.detectFacets(getAgent()) 488 + await resolvedRT.detectFacets(agent) 489 489 if (!ignore) { 490 490 setResolvedRT(resolvedRT) 491 491 } ··· 494 494 return () => { 495 495 ignore = true 496 496 } 497 - }, [text, getAgent]) 497 + }, [text, agent]) 498 498 const isResolving = resolvedRT === null 499 499 return [resolvedRT ?? rawRT, isResolving] 500 500 }
+4 -4
src/view/screens/Settings/DisableEmail2FADialog.tsx
··· 30 30 const t = useTheme() 31 31 const {gtMobile} = useBreakpoints() 32 32 const {currentAccount} = useSession() 33 - const {getAgent} = useAgent() 33 + const agent = useAgent() 34 34 35 35 const [stage, setStage] = useState<Stages>(Stages.Email) 36 36 const [confirmationCode, setConfirmationCode] = useState<string>('') ··· 41 41 setError('') 42 42 setIsProcessing(true) 43 43 try { 44 - await getAgent().com.atproto.server.requestEmailUpdate() 44 + await agent.com.atproto.server.requestEmailUpdate() 45 45 setStage(Stages.ConfirmCode) 46 46 } catch (e) { 47 47 setError(cleanError(String(e))) ··· 55 55 setIsProcessing(true) 56 56 try { 57 57 if (currentAccount?.email) { 58 - await getAgent().com.atproto.server.updateEmail({ 58 + await agent.com.atproto.server.updateEmail({ 59 59 email: currentAccount!.email, 60 60 token: confirmationCode.trim(), 61 61 emailAuthFactor: false, 62 62 }) 63 - await getAgent().resumeSession(getAgent().session!) 63 + await agent.resumeSession(agent.session!) 64 64 Toast.show(_(msg`Email 2FA disabled`)) 65 65 } 66 66 control.close()
+4 -4
src/view/screens/Settings/Email2FAToggle.tsx
··· 13 13 const {currentAccount} = useSession() 14 14 const {openModal} = useModalControls() 15 15 const disableDialogCtrl = useDialogControl() 16 - const {getAgent} = useAgent() 16 + const agent = useAgent() 17 17 18 18 const enableEmailAuthFactor = React.useCallback(async () => { 19 19 if (currentAccount?.email) { 20 - await getAgent().com.atproto.server.updateEmail({ 20 + await agent.com.atproto.server.updateEmail({ 21 21 email: currentAccount.email, 22 22 emailAuthFactor: true, 23 23 }) 24 - await getAgent().resumeSession(getAgent().session!) 24 + await agent.resumeSession(agent.session!) 25 25 } 26 - }, [currentAccount, getAgent]) 26 + }, [currentAccount, agent]) 27 27 28 28 const onToggle = React.useCallback(() => { 29 29 if (!currentAccount) {
+2 -3
src/view/screens/Settings/ExportCarDialog.tsx
··· 21 21 }) { 22 22 const {_} = useLingui() 23 23 const t = useTheme() 24 - const {getAgent} = useAgent() 24 + const agent = useAgent() 25 25 const [loading, setLoading] = React.useState(false) 26 26 27 27 const download = React.useCallback(async () => { 28 - const agent = getAgent() 29 28 if (!agent.session) { 30 29 return // shouldnt ever happen 31 30 } ··· 49 48 setLoading(false) 50 49 control.close() 51 50 } 52 - }, [_, control, getAgent]) 51 + }, [_, control, agent]) 53 52 54 53 return ( 55 54 <Dialog.Outer control={control}>