migrate the signup and onboarding profile writes to sdk actions
The post-signup and onboarding writes (setPersonalDetails, upsertProfile, overwriteSavedFeeds, setInterestsPref) move onto sdk actions over the pds client, and the starter-pack and contact-import reads move to the lex clients. Every upsertProfile call now writes a lex blob directly, so the toLegacyBlobRef bridge has no remaining callers and is deleted.
This commit is contained in:
@@ -1,21 +1,19 @@
|
||||
import {useCallback, useState} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {
|
||||
type AppBskyActorDefs,
|
||||
type AppBskyActorProfile,
|
||||
type AppBskyGraphDefs,
|
||||
AppBskyGraphStarterpack,
|
||||
type Un$Typed,
|
||||
} from '@atproto/api'
|
||||
import {TID} from '@atproto/common-web'
|
||||
import {type AtUriString} from '@atproto/syntax'
|
||||
import {type Un$Typed} from '@atproto/lex'
|
||||
import {type AtUriString, toDatetimeString} from '@atproto/syntax'
|
||||
import {
|
||||
overwriteSavedFeeds,
|
||||
setInterestsPref,
|
||||
upsertProfile,
|
||||
} from '@bsky.app/sdk'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
import {useQueryClient} from '@tanstack/react-query'
|
||||
|
||||
import {uploadBlob} from '#/lib/api'
|
||||
import {toLegacyBlobRef} from '#/lib/api/legacy-blob'
|
||||
import {
|
||||
BSKY_APP_ACCOUNT_DID,
|
||||
DISCOVER_SAVED_FEED,
|
||||
@@ -28,7 +26,7 @@ import {useSetHasCheckedForStarterPack} from '#/state/preferences/used-starter-p
|
||||
import {getAllListMembers} from '#/state/queries/list-members'
|
||||
import {preferencesQueryKey} from '#/state/queries/preferences'
|
||||
import {RQKEY as profileRQKey} from '#/state/queries/profile'
|
||||
import {useAgent, useAppviewClient, usePdsClient} from '#/state/session'
|
||||
import {useAppviewClient, usePdsClient} from '#/state/session'
|
||||
import {useOnboardingDispatch} from '#/state/shell'
|
||||
import {
|
||||
useActiveStarterPack,
|
||||
@@ -50,6 +48,7 @@ import {ArrowRight_Stroke2_Corner0_Rounded as ArrowRight} from '#/components/ico
|
||||
import {Loader} from '#/components/Loader'
|
||||
import {useAnalytics} from '#/analytics'
|
||||
import {IS_WEB} from '#/env'
|
||||
import {app} from '#/lexicons'
|
||||
import * as bsky from '#/types/bsky'
|
||||
import {ValuePropositionPager} from './ValuePropositionPager'
|
||||
|
||||
@@ -59,9 +58,8 @@ export function StepFinished() {
|
||||
const onboardDispatch = useOnboardingDispatch()
|
||||
const [saving, setSaving] = useState(false)
|
||||
const queryClient = useQueryClient()
|
||||
const agent = useAgent()
|
||||
const appviewClient = useAppviewClient()
|
||||
const pdsClient = usePdsClient()
|
||||
const appviewClient = useAppviewClient()
|
||||
const requestNotificationsPermission = useRequestNotificationsPermission()
|
||||
const activeStarterPack = useActiveStarterPack()
|
||||
const setActiveStarterPack = useSetActiveStarterPack()
|
||||
@@ -71,15 +69,15 @@ export function StepFinished() {
|
||||
const finishOnboarding = useCallback(async () => {
|
||||
setSaving(true)
|
||||
|
||||
let starterPack: AppBskyGraphDefs.StarterPackView | undefined
|
||||
let listItems: AppBskyGraphDefs.ListItemView[] | undefined
|
||||
let starterPack: app.bsky.graph.defs.StarterPackView | undefined
|
||||
let listItems: app.bsky.graph.defs.ListItemView[] | undefined
|
||||
|
||||
if (activeStarterPack?.uri) {
|
||||
try {
|
||||
const spRes = await agent.app.bsky.graph.getStarterPack({
|
||||
starterPack: activeStarterPack.uri,
|
||||
const spRes = await appviewClient.call(app.bsky.graph.getStarterPack, {
|
||||
starterPack: activeStarterPack.uri as AtUriString,
|
||||
})
|
||||
starterPack = spRes.data.starterPack
|
||||
starterPack = spRes.starterPack
|
||||
} catch (e) {
|
||||
logger.error('Failed to fetch starter pack', {safeMessage: e})
|
||||
// don't tell the user, just get them through onboarding.
|
||||
@@ -109,19 +107,15 @@ export function StepFinished() {
|
||||
appviewClient,
|
||||
[BSKY_APP_ACCOUNT_DID, ...(listItems?.map(i => i.subject.did) ?? [])],
|
||||
starterPack
|
||||
? // the starter pack view is still legacy-typed
|
||||
{
|
||||
uri: starterPack.uri as AtUriString,
|
||||
cid: starterPack.cid,
|
||||
}
|
||||
? {uri: starterPack.uri, cid: starterPack.cid}
|
||||
: undefined,
|
||||
),
|
||||
(async () => {
|
||||
// Interests need to get saved first, then we can write the feeds to prefs
|
||||
await agent.setInterestsPref({tags: selectedInterests})
|
||||
await pdsClient.call(setInterestsPref, {tags: selectedInterests})
|
||||
|
||||
// Default feeds that every user should have pinned when landing in the app
|
||||
const feedsToSave: AppBskyActorDefs.SavedFeed[] = [
|
||||
const feedsToSave: app.bsky.actor.defs.SavedFeed[] = [
|
||||
{
|
||||
...DISCOVER_SAVED_FEED,
|
||||
id: TID.nextStr(),
|
||||
@@ -140,7 +134,7 @@ export function StepFinished() {
|
||||
if (starterPack && starterPack.feeds?.length) {
|
||||
feedsToSave.push(
|
||||
...starterPack.feeds.map(f => ({
|
||||
type: 'feed',
|
||||
type: 'feed' as const,
|
||||
value: f.uri,
|
||||
pinned: true,
|
||||
id: TID.nextStr(),
|
||||
@@ -148,7 +142,7 @@ export function StepFinished() {
|
||||
)
|
||||
}
|
||||
|
||||
await agent.overwriteSavedFeeds(feedsToSave)
|
||||
await pdsClient.call(overwriteSavedFeeds, feedsToSave)
|
||||
})(),
|
||||
(async () => {
|
||||
const {imageUri, imageMime} = profileStepResults
|
||||
@@ -157,13 +151,13 @@ export function StepFinished() {
|
||||
? uploadBlob(pdsClient, imageUri, imageMime)
|
||||
: undefined
|
||||
|
||||
await agent.upsertProfile(async existing => {
|
||||
let next: Un$Typed<AppBskyActorProfile.Record> = existing ?? {}
|
||||
await pdsClient.call(upsertProfile, async existing => {
|
||||
let next: Un$Typed<app.bsky.actor.profile.Main> = existing ?? {}
|
||||
|
||||
if (blobPromise) {
|
||||
const res = await blobPromise
|
||||
if (res.blob) {
|
||||
next.avatar = toLegacyBlobRef(res.blob)
|
||||
next.avatar = res.blob
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +171,7 @@ export function StepFinished() {
|
||||
next.displayName = ''
|
||||
|
||||
if (!next.createdAt) {
|
||||
next.createdAt = new Date().toISOString()
|
||||
next.createdAt = toDatetimeString(new Date())
|
||||
}
|
||||
return next
|
||||
})
|
||||
@@ -204,7 +198,7 @@ export function StepFinished() {
|
||||
queryKey: preferencesQueryKey,
|
||||
}),
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: profileRQKey(agent.session?.did ?? ''),
|
||||
queryKey: profileRQKey(pdsClient.did ?? ''),
|
||||
}),
|
||||
]).catch(e => {
|
||||
logger.error(e)
|
||||
@@ -221,10 +215,7 @@ export function StepFinished() {
|
||||
usedStarterPack: Boolean(starterPack),
|
||||
starterPackName:
|
||||
starterPack &&
|
||||
bsky.dangerousIsType<AppBskyGraphStarterpack.Record>(
|
||||
starterPack.record,
|
||||
AppBskyGraphStarterpack.isRecord,
|
||||
)
|
||||
bsky.isType(app.bsky.graph.starterpack, starterPack.record)
|
||||
? starterPack.record.name
|
||||
: undefined,
|
||||
starterPackCreator: starterPack?.creator.did,
|
||||
@@ -242,9 +233,8 @@ export function StepFinished() {
|
||||
}, [
|
||||
ax,
|
||||
queryClient,
|
||||
agent,
|
||||
appviewClient,
|
||||
pdsClient,
|
||||
appviewClient,
|
||||
dispatch,
|
||||
onboardDispatch,
|
||||
activeStarterPack,
|
||||
|
||||
Reference in New Issue
Block a user