Bluesky app fork with some witchin' additions 💫

Filter non-self threads from profile view (#1757)

authored by

Eric Bailey and committed by
GitHub
ddf0a1cc 40752982

+47 -1
+47 -1
src/lib/api/feed/author.ts
··· 35 35 this.cursor = res.data.cursor 36 36 return { 37 37 cursor: res.data.cursor, 38 - feed: res.data.feed, 38 + feed: this._filter(res.data.feed), 39 39 } 40 40 } 41 41 return { 42 42 feed: [], 43 43 } 44 44 } 45 + 46 + _filter(feed: AppBskyFeedDefs.FeedViewPost[]) { 47 + if (this.params.filter === 'posts_no_replies') { 48 + return feed.filter(post => { 49 + const isReply = post.reply 50 + const isRepost = AppBskyFeedDefs.isReasonRepost(post.reason) 51 + if (!isReply) return true 52 + if (isRepost) return true 53 + return isReply && isAuthorReplyChain(this.params.actor, post, feed) 54 + }) 55 + } 56 + 57 + return feed 58 + } 59 + } 60 + 61 + function isAuthorReplyChain( 62 + actor: string, 63 + post: AppBskyFeedDefs.FeedViewPost, 64 + posts: AppBskyFeedDefs.FeedViewPost[], 65 + ): boolean { 66 + // current post is by a different user (shouldn't happen) 67 + if (post.post.author.handle !== actor) return false 68 + 69 + const replyParent = post.reply?.parent 70 + 71 + if (AppBskyFeedDefs.isPostView(replyParent)) { 72 + // reply parent is by a different user 73 + if (replyParent.author.handle !== actor) return false 74 + 75 + // A top-level post that matches the parent of the current post. 76 + const parentPost = posts.find(p => p.post.uri === replyParent.uri) 77 + 78 + /* 79 + * Either we haven't fetched the parent at the top level, or the only 80 + * record we have is on feedItem.reply.parent, which we've already checked 81 + * above. 82 + */ 83 + if (!parentPost) return true 84 + 85 + // Walk up to parent 86 + return isAuthorReplyChain(actor, parentPost, posts) 87 + } 88 + 89 + // Just default to showing it 90 + return true 45 91 }