Replace getAgent() with reading agent (#4243)
* Replace getAgent() with agent * Replace {agent} with agent
This commit is contained in:
parent
8a2f43c218
commit
9bd411c151
74 changed files with 400 additions and 438 deletions
|
@ -24,7 +24,7 @@ export function Deactivated() {
|
|||
const {gtMobile} = useBreakpoints()
|
||||
const onboardingDispatch = useOnboardingDispatch()
|
||||
const {logout} = useSessionApi()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
const [isProcessing, setProcessing] = React.useState(false)
|
||||
const [estimatedTime, setEstimatedTime] = React.useState<string | undefined>(
|
||||
|
@ -37,11 +37,11 @@ export function Deactivated() {
|
|||
const checkStatus = React.useCallback(async () => {
|
||||
setProcessing(true)
|
||||
try {
|
||||
const res = await getAgent().com.atproto.temp.checkSignupQueue()
|
||||
const res = await agent.com.atproto.temp.checkSignupQueue()
|
||||
if (res.data.activated) {
|
||||
// ready to go, exchange the access token for a usable one and kick off onboarding
|
||||
await getAgent().refreshSession()
|
||||
if (!isSessionDeactivated(getAgent().session?.accessJwt)) {
|
||||
await agent.refreshSession()
|
||||
if (!isSessionDeactivated(agent.session?.accessJwt)) {
|
||||
onboardingDispatch({type: 'start'})
|
||||
}
|
||||
} else {
|
||||
|
@ -61,7 +61,7 @@ export function Deactivated() {
|
|||
setEstimatedTime,
|
||||
setPlaceInQueue,
|
||||
onboardingDispatch,
|
||||
getAgent,
|
||||
agent,
|
||||
])
|
||||
|
||||
React.useEffect(() => {
|
||||
|
|
|
@ -66,14 +66,14 @@ function DialogInner() {
|
|||
const control = Dialog.useDialogContext()
|
||||
const [details, setDetails] = useState('')
|
||||
const {gtMobile} = useBreakpoints()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const {currentAccount} = useSession()
|
||||
|
||||
const {mutate, isPending} = useMutation({
|
||||
mutationFn: async () => {
|
||||
if (!currentAccount)
|
||||
throw new Error('No current account, should be unreachable')
|
||||
await getAgent().createModerationReport({
|
||||
await agent.createModerationReport({
|
||||
reasonType: ComAtprotoModerationDefs.REASONAPPEAL,
|
||||
subject: {
|
||||
$type: 'com.atproto.admin.defs#repoRef',
|
||||
|
|
|
@ -79,7 +79,7 @@ export function MessagesList({
|
|||
footer?: React.ReactNode
|
||||
}) {
|
||||
const convoState = useConvoActive()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
const flatListRef = useAnimatedRef<FlatList>()
|
||||
|
||||
|
@ -265,7 +265,7 @@ export function MessagesList({
|
|||
const onSendMessage = useCallback(
|
||||
async (text: string) => {
|
||||
let rt = new RichText({text}, {cleanNewlines: true})
|
||||
await rt.detectFacets(getAgent())
|
||||
await rt.detectFacets(agent)
|
||||
rt = shortenLinks(rt)
|
||||
|
||||
// filter out any mention facets that didn't map to a user
|
||||
|
@ -288,7 +288,7 @@ export function MessagesList({
|
|||
facets: rt.facets,
|
||||
})
|
||||
},
|
||||
[convoState, getAgent, hasScrolled, setHasScrolled],
|
||||
[convoState, agent, hasScrolled, setHasScrolled],
|
||||
)
|
||||
|
||||
// -- List layout changes (opening emoji keyboard, etc.)
|
||||
|
|
|
@ -47,7 +47,7 @@ export function StepFinished() {
|
|||
const [saving, setSaving] = React.useState(false)
|
||||
const {mutateAsync: overwriteSavedFeeds} = useOverwriteSavedFeedsMutation()
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const gate = useGate()
|
||||
|
||||
const finishOnboarding = React.useCallback(async () => {
|
||||
|
@ -70,12 +70,12 @@ export function StepFinished() {
|
|||
try {
|
||||
await Promise.all([
|
||||
bulkWriteFollows(
|
||||
getAgent,
|
||||
agent,
|
||||
suggestedAccountsStepResults.accountDids.concat(BSKY_APP_ACCOUNT_DID),
|
||||
),
|
||||
// these must be serial
|
||||
(async () => {
|
||||
await getAgent().setInterestsPref({tags: selectedInterests})
|
||||
await agent.setInterestsPref({tags: selectedInterests})
|
||||
|
||||
/*
|
||||
* In the reduced onboading experiment, we'll rely on the default
|
||||
|
@ -98,7 +98,7 @@ export function StepFinished() {
|
|||
* (mimics old behavior)
|
||||
*/
|
||||
if (
|
||||
IS_PROD_SERVICE(getAgent().service.toString()) &&
|
||||
IS_PROD_SERVICE(agent.service.toString()) &&
|
||||
!otherFeeds.length
|
||||
) {
|
||||
otherFeeds.push({
|
||||
|
@ -124,8 +124,8 @@ export function StepFinished() {
|
|||
|
||||
const {imageUri, imageMime} = profileStepResults
|
||||
if (imageUri && imageMime) {
|
||||
const blobPromise = uploadBlob(getAgent(), imageUri, imageMime)
|
||||
await getAgent().upsertProfile(async existing => {
|
||||
const blobPromise = uploadBlob(agent, imageUri, imageMime)
|
||||
await agent.upsertProfile(async existing => {
|
||||
existing = existing ?? {}
|
||||
const res = await blobPromise
|
||||
if (res.data.blob) {
|
||||
|
@ -156,7 +156,7 @@ export function StepFinished() {
|
|||
queryKey: preferencesQueryKey,
|
||||
}),
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: profileRQKey(getAgent().session?.did ?? ''),
|
||||
queryKey: profileRQKey(agent.session?.did ?? ''),
|
||||
}),
|
||||
]).catch(e => {
|
||||
logger.error(e)
|
||||
|
@ -176,7 +176,7 @@ export function StepFinished() {
|
|||
setSaving,
|
||||
overwriteSavedFeeds,
|
||||
track,
|
||||
getAgent,
|
||||
agent,
|
||||
gate,
|
||||
queryClient,
|
||||
])
|
||||
|
|
|
@ -43,13 +43,12 @@ export function StepInterests() {
|
|||
state.interestsStepResults.selectedInterests.map(i => i),
|
||||
)
|
||||
const onboardDispatch = useOnboardingDispatch()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const {isLoading, isError, error, data, refetch, isFetching} = useQuery({
|
||||
queryKey: ['interests'],
|
||||
queryFn: async () => {
|
||||
try {
|
||||
const {data} =
|
||||
await getAgent().app.bsky.unspecced.getTaggedSuggestions()
|
||||
const {data} = await agent.app.bsky.unspecced.getTaggedSuggestions()
|
||||
return data.suggestions.reduce(
|
||||
(agg, s) => {
|
||||
const {tag, subject, subjectType} = s
|
||||
|
|
|
@ -66,11 +66,8 @@ export function aggregateInterestItems(
|
|||
return Array.from(new Set(results)).slice(0, 20)
|
||||
}
|
||||
|
||||
export async function bulkWriteFollows(
|
||||
getAgent: () => BskyAgent,
|
||||
dids: string[],
|
||||
) {
|
||||
const session = getAgent().session
|
||||
export async function bulkWriteFollows(agent: BskyAgent, dids: string[]) {
|
||||
const session = agent.session
|
||||
|
||||
if (!session) {
|
||||
throw new Error(`bulkWriteFollows failed: no session`)
|
||||
|
@ -89,19 +86,15 @@ export async function bulkWriteFollows(
|
|||
value: r,
|
||||
}))
|
||||
|
||||
await getAgent().com.atproto.repo.applyWrites({
|
||||
await agent.com.atproto.repo.applyWrites({
|
||||
repo: session.did,
|
||||
writes: followWrites,
|
||||
})
|
||||
await whenFollowsIndexed(
|
||||
getAgent,
|
||||
session.did,
|
||||
res => !!res.data.follows.length,
|
||||
)
|
||||
await whenFollowsIndexed(agent, session.did, res => !!res.data.follows.length)
|
||||
}
|
||||
|
||||
async function whenFollowsIndexed(
|
||||
getAgent: () => BskyAgent,
|
||||
agent: BskyAgent,
|
||||
actor: string,
|
||||
fn: (res: AppBskyGraphGetFollows.Response) => boolean,
|
||||
) {
|
||||
|
@ -110,7 +103,7 @@ async function whenFollowsIndexed(
|
|||
1e3, // 1s delay between tries
|
||||
fn,
|
||||
() =>
|
||||
getAgent().app.bsky.graph.getFollows({
|
||||
agent.app.bsky.graph.getFollows({
|
||||
actor,
|
||||
limit: 1,
|
||||
}),
|
||||
|
|
|
@ -36,7 +36,7 @@ export function Signup({onPressBack}: {onPressBack: () => void}) {
|
|||
const [state, dispatch] = React.useReducer(reducer, initialState)
|
||||
const submit = useSubmitSignup({state, dispatch})
|
||||
const {gtMobile} = useBreakpoints()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
const {
|
||||
data: serviceInfo,
|
||||
|
@ -77,7 +77,7 @@ export function Signup({onPressBack}: {onPressBack: () => void}) {
|
|||
try {
|
||||
dispatch({type: 'setIsLoading', value: true})
|
||||
|
||||
const res = await getAgent().resolveHandle({
|
||||
const res = await agent.resolveHandle({
|
||||
handle: createFullHandle(state.handle, state.userDomain),
|
||||
})
|
||||
|
||||
|
@ -115,7 +115,7 @@ export function Signup({onPressBack}: {onPressBack: () => void}) {
|
|||
state.serviceDescription?.phoneVerificationRequired,
|
||||
state.userDomain,
|
||||
submit,
|
||||
getAgent,
|
||||
agent,
|
||||
])
|
||||
|
||||
const onBackPress = React.useCallback(() => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue