about summary refs log tree commit diff
path: root/src/state/lib/api.ts
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2022-10-04 11:10:24 -0500
committerPaul Frazee <pfrazee@gmail.com>2022-10-04 11:10:24 -0500
commit0aaa406b179e366e6a527f052379184787440b42 (patch)
tree8e85b68c1557a9d3162e7bf1f3eaeda76950091d /src/state/lib/api.ts
parentbf39791f011f19c6ff192eb223e15259dc9de53a (diff)
downloadvoidsky-0aaa406b179e366e6a527f052379184787440b42.tar.zst
Implement profile-update api
Diffstat (limited to 'src/state/lib/api.ts')
-rw-r--r--src/state/lib/api.ts28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/state/lib/api.ts b/src/state/lib/api.ts
index ad81301ff..f2418ef31 100644
--- a/src/state/lib/api.ts
+++ b/src/state/lib/api.ts
@@ -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 {