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-07-22 16:06:51 -0500
committerPaul Frazee <pfrazee@gmail.com>2022-07-22 16:06:51 -0500
commit7f04ac172e8ada1244de1df2064e32d32f1c2348 (patch)
treedcecdfcad0746a296b38e8d3acb5dd983589d6b0 /src/state/lib/api.ts
parentce83648f9da3a93018fc7845bec1d35c1519028d (diff)
downloadvoidsky-7f04ac172e8ada1244de1df2064e32d32f1c2348.tar.zst
Add post composer
Diffstat (limited to 'src/state/lib/api.ts')
-rw-r--r--src/state/lib/api.ts46
1 files changed, 40 insertions, 6 deletions
diff --git a/src/state/lib/api.ts b/src/state/lib/api.ts
index b3992544b..bb3ef5d1a 100644
--- a/src/state/lib/api.ts
+++ b/src/state/lib/api.ts
@@ -28,12 +28,46 @@ export async function setup(adx: AdxClient) {
   )
 }
 
+export async function post(
+  adx: AdxClient,
+  user: string,
+  text: string,
+  replyToUri?: string,
+) {
+  let reply
+  if (replyToUri) {
+    const replyToUrip = new AdxUri(replyToUri)
+    const parentPost = await adx
+      .repo(replyToUrip.host, false)
+      .collection(replyToUrip.collection)
+      .get('Post', replyToUrip.recordKey)
+    if (parentPost) {
+      reply = {
+        root: parentPost.value.reply?.root || parentPost.uri,
+        parent: parentPost.uri,
+      }
+    }
+  }
+  return await adx
+    .repo(user, true)
+    .collection('blueskyweb.xyz:Posts')
+    .create('Post', {
+      $type: 'blueskyweb.xyz:Post',
+      text,
+      reply,
+      createdAt: new Date().toISOString(),
+    })
+}
+
 export async function like(adx: AdxClient, user: string, uri: string) {
-  await adx.repo(user, true).collection('blueskyweb.xyz:Likes').create('Like', {
-    $type: 'blueskyweb.xyz:Like',
-    subject: uri,
-    createdAt: new Date().toISOString(),
-  })
+  return await adx
+    .repo(user, true)
+    .collection('blueskyweb.xyz:Likes')
+    .create('Like', {
+      $type: 'blueskyweb.xyz:Like',
+      subject: uri,
+      createdAt: new Date().toISOString(),
+    })
 }
 
 export async function unlike(adx: AdxClient, user: string, uri: string) {
@@ -45,7 +79,7 @@ export async function unlike(adx: AdxClient, user: string, uri: string) {
 }
 
 export async function repost(adx: AdxClient, user: string, uri: string) {
-  await adx
+  return await adx
     .repo(user, true)
     .collection('blueskyweb.xyz:Posts')
     .create('Repost', {