about summary refs log tree commit diff
path: root/src/state/models
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2022-11-23 14:22:40 -0600
committerPaul Frazee <pfrazee@gmail.com>2022-11-23 14:22:40 -0600
commit2b37b6549b6cb17db582a81a2bdca8316b1e4861 (patch)
tree4bbefea0af632f6f9bb537a7c78d5b045f8d916f /src/state/models
parenta9934998909b7d828f66e2b1b0b1e0aeb20adf6a (diff)
downloadvoidsky-2b37b6549b6cb17db582a81a2bdca8316b1e4861.tar.zst
Add replying-to context to threads
Diffstat (limited to 'src/state/models')
-rw-r--r--src/state/models/post-thread-view.ts34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/state/models/post-thread-view.ts b/src/state/models/post-thread-view.ts
index 860a8f6ad..70e34537f 100644
--- a/src/state/models/post-thread-view.ts
+++ b/src/state/models/post-thread-view.ts
@@ -12,6 +12,17 @@ function* reactKeyGenerator(): Generator<string> {
   }
 }
 
+interface ReplyingTo {
+  author: {
+    handle: string
+    displayName?: string
+  }
+  text: string
+}
+interface OriginalRecord {
+  text: string
+}
+
 export class PostThreadViewPostMyStateModel {
   repost?: string
   upvote?: string
@@ -52,7 +63,7 @@ export class PostThreadViewPostModel implements GetPostThread.Post {
   myState = new PostThreadViewPostMyStateModel()
 
   // added data
-  replyingToAuthor?: string
+  replyingTo?: ReplyingTo
 
   constructor(
     public rootStore: RootStoreModel,
@@ -74,6 +85,7 @@ export class PostThreadViewPostModel implements GetPostThread.Post {
     v: GetPostThread.Post,
     includeParent = true,
     includeChildren = true,
+    isFirstChild = true,
   ) {
     // parents
     if (includeParent && v.parent) {
@@ -89,12 +101,19 @@ export class PostThreadViewPostModel implements GetPostThread.Post {
       }
       this.parent = parentModel
     }
-    if (v.parent?.author.handle) {
-      this.replyingToAuthor = v.parent.author.handle
+    if (!includeParent && v.parent?.author.handle && !isFirstChild) {
+      this.replyingTo = {
+        author: {
+          handle: v.parent.author.handle,
+          displayName: v.parent.author.displayName,
+        },
+        text: (v.parent.record as OriginalRecord).text,
+      }
     }
     // replies
     if (includeChildren && v.replies) {
       const replies = []
+      let isChildFirstChild = true
       for (const item of v.replies) {
         // TODO: validate .record
         const itemModel = new PostThreadViewPostModel(
@@ -104,8 +123,15 @@ export class PostThreadViewPostModel implements GetPostThread.Post {
         )
         itemModel._depth = this._depth + 1
         if (item.replies) {
-          itemModel.assignTreeModels(keyGen, item, false, true)
+          itemModel.assignTreeModels(
+            keyGen,
+            item,
+            false,
+            true,
+            isChildFirstChild,
+          )
         }
+        isChildFirstChild = false
         replies.push(itemModel)
       }
       this.replies = replies