about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEric Bailey <git@esb.lol>2023-10-30 22:40:06 -0500
committerGitHub <noreply@github.com>2023-10-30 20:40:06 -0700
commitddf0a1ccede4ffaf051b37ea39547fa1223ac5c5 (patch)
treeec9423d804afc66386923e27f2f3034e27dbd78e /src
parent40752982da07ff05001129e26f3ea1bca39c7ad9 (diff)
downloadvoidsky-ddf0a1ccede4ffaf051b37ea39547fa1223ac5c5.tar.zst
Filter non-self threads from profile view (#1757)
Diffstat (limited to 'src')
-rw-r--r--src/lib/api/feed/author.ts48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/lib/api/feed/author.ts b/src/lib/api/feed/author.ts
index 1ae925123..ec8795e1a 100644
--- a/src/lib/api/feed/author.ts
+++ b/src/lib/api/feed/author.ts
@@ -35,11 +35,57 @@ export class AuthorFeedAPI implements FeedAPI {
       this.cursor = res.data.cursor
       return {
         cursor: res.data.cursor,
-        feed: res.data.feed,
+        feed: this._filter(res.data.feed),
       }
     }
     return {
       feed: [],
     }
   }
+
+  _filter(feed: AppBskyFeedDefs.FeedViewPost[]) {
+    if (this.params.filter === 'posts_no_replies') {
+      return feed.filter(post => {
+        const isReply = post.reply
+        const isRepost = AppBskyFeedDefs.isReasonRepost(post.reason)
+        if (!isReply) return true
+        if (isRepost) return true
+        return isReply && isAuthorReplyChain(this.params.actor, post, feed)
+      })
+    }
+
+    return feed
+  }
+}
+
+function isAuthorReplyChain(
+  actor: string,
+  post: AppBskyFeedDefs.FeedViewPost,
+  posts: AppBskyFeedDefs.FeedViewPost[],
+): boolean {
+  // current post is by a different user (shouldn't happen)
+  if (post.post.author.handle !== actor) return false
+
+  const replyParent = post.reply?.parent
+
+  if (AppBskyFeedDefs.isPostView(replyParent)) {
+    // reply parent is by a different user
+    if (replyParent.author.handle !== actor) return false
+
+    // A top-level post that matches the parent of the current post.
+    const parentPost = posts.find(p => p.post.uri === replyParent.uri)
+
+    /*
+     * Either we haven't fetched the parent at the top level, or the only
+     * record we have is on feedItem.reply.parent, which we've already checked
+     * above.
+     */
+    if (!parentPost) return true
+
+    // Walk up to parent
+    return isAuthorReplyChain(actor, parentPost, posts)
+  }
+
+  // Just default to showing it
+  return true
 }