Implement profile-update api
This commit is contained in:
parent
bf39791f01
commit
0aaa406b17
4 changed files with 39 additions and 15 deletions
|
@ -5,7 +5,7 @@
|
|||
|
||||
// import {ReactNativeStore} from './auth'
|
||||
import AdxApi from '../../third-party/api'
|
||||
import {ServiceClient} from '../../third-party/api/src/index'
|
||||
import * as Profile from '../../third-party/api/src/types/todo/social/profile'
|
||||
import {AdxUri} from '../../third-party/uri'
|
||||
import {RootStoreModel} from '../models/root-store'
|
||||
import {extractEntities} from '../../view/lib/strings'
|
||||
|
@ -100,11 +100,29 @@ export async function unfollow(store: RootStoreModel, followUri: string) {
|
|||
}
|
||||
|
||||
export async function updateProfile(
|
||||
adx: ServiceClient,
|
||||
user: string,
|
||||
profile: bsky.Profile.Record,
|
||||
store: RootStoreModel,
|
||||
modifyFn: (existing?: Profile.Record) => Profile.Record,
|
||||
) {
|
||||
throw new Error('TODO')
|
||||
const res = await store.api.todo.social.profile.list({
|
||||
nameOrDid: store.me.did || '',
|
||||
})
|
||||
const existing = res.records[0]
|
||||
if (existing) {
|
||||
await store.api.todo.social.profile.put(
|
||||
{
|
||||
did: store.me.did || '',
|
||||
tid: new AdxUri(existing.uri).recordKey,
|
||||
},
|
||||
modifyFn(existing.value),
|
||||
)
|
||||
} else {
|
||||
await store.api.todo.social.profile.create(
|
||||
{
|
||||
did: store.me.did || '',
|
||||
},
|
||||
modifyFn(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
interface FetchHandlerResponse {
|
||||
|
|
|
@ -88,11 +88,11 @@ export class ProfileViewModel {
|
|||
}
|
||||
}
|
||||
|
||||
async updateProfile(profile: Profile.Record) {
|
||||
async updateProfile(fn: (existing?: Profile.Record) => Profile.Record) {
|
||||
if (this.did !== this.rootStore.me.did) {
|
||||
throw new Error('Not your profile!')
|
||||
}
|
||||
await apilib.updateProfile(this.rootStore.api, this.did, profile)
|
||||
await apilib.updateProfile(this.rootStore, fn)
|
||||
await this.refresh()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue