diff --git a/src/state/queries/post-thread.ts b/src/state/queries/post-thread.ts index db85e8a177..70aa6eca08 100644 --- a/src/state/queries/post-thread.ts +++ b/src/state/queries/post-thread.ts @@ -4,6 +4,7 @@ import { AppBskyFeedDefs, AppBskyFeedGetPostThread, AppBskyFeedPost, + AppBskyFeedThreadgate, AtUri, ModerationDecision, ModerationOpts, @@ -136,6 +137,7 @@ export function sortThread( node: ThreadNode, opts: UsePreferencesQueryResponse['threadViewPrefs'], modCache: ThreadModerationCache, + threadgateRecord?: AppBskyFeedThreadgate.Record, ): ThreadNode { if (node.type !== 'post') { return node @@ -149,6 +151,23 @@ export function sortThread( return -1 } + /* + * Hiding takes precendence over OP check below bc thread root author + * can't hide their own posts, therefore this only applies to other + * authors. + */ + const aHidden = threadgateRecord?.hiddenReplies?.includes(a.uri) + const bHidden = threadgateRecord?.hiddenReplies?.includes(b.uri) + if (aHidden && !bHidden) { + return 1 + } else if (bHidden && !aHidden) { + return -1 + } + + /* + * Here, OP is actually whatever node is highlighted in the thread view, + * NOT necessarily the root post of the thread, though it can be. + */ const aIsByOp = a.post.author.did === node.post?.author.did const bIsByOp = b.post.author.did === node.post?.author.did if (aIsByOp && bIsByOp) { @@ -195,7 +214,9 @@ export function sortThread( } return b.post.indexedAt.localeCompare(a.post.indexedAt) }) - node.replies.forEach(reply => sortThread(reply, opts, modCache)) + node.replies.forEach(reply => + sortThread(reply, opts, modCache, threadgateRecord), + ) } return node } diff --git a/src/view/com/post-thread/PostThread.tsx b/src/view/com/post-thread/PostThread.tsx index 9655ea17d5..6b3fa495c1 100644 --- a/src/view/com/post-thread/PostThread.tsx +++ b/src/view/com/post-thread/PostThread.tsx @@ -182,7 +182,12 @@ export function PostThread({ if (!threadViewPrefs || !thread) return null return createThreadSkeleton( - sortThread(thread, threadViewPrefs, threadModerationCache), + sortThread( + thread, + threadViewPrefs, + threadModerationCache, + threadgateRecord ?? undefined, + ), hasSession, treeView, threadModerationCache,