Sort hidden replies to bottom

This commit is contained in:
Eric Bailey
2024-08-07 16:16:45 -05:00
parent c5c3ce7f04
commit defd61e85b
2 changed files with 28 additions and 2 deletions
+22 -1
View File
@@ -4,6 +4,7 @@ import {
AppBskyFeedDefs, AppBskyFeedDefs,
AppBskyFeedGetPostThread, AppBskyFeedGetPostThread,
AppBskyFeedPost, AppBskyFeedPost,
AppBskyFeedThreadgate,
AtUri, AtUri,
ModerationDecision, ModerationDecision,
ModerationOpts, ModerationOpts,
@@ -136,6 +137,7 @@ export function sortThread(
node: ThreadNode, node: ThreadNode,
opts: UsePreferencesQueryResponse['threadViewPrefs'], opts: UsePreferencesQueryResponse['threadViewPrefs'],
modCache: ThreadModerationCache, modCache: ThreadModerationCache,
threadgateRecord?: AppBskyFeedThreadgate.Record,
): ThreadNode { ): ThreadNode {
if (node.type !== 'post') { if (node.type !== 'post') {
return node return node
@@ -149,6 +151,23 @@ export function sortThread(
return -1 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 aIsByOp = a.post.author.did === node.post?.author.did
const bIsByOp = b.post.author.did === node.post?.author.did const bIsByOp = b.post.author.did === node.post?.author.did
if (aIsByOp && bIsByOp) { if (aIsByOp && bIsByOp) {
@@ -195,7 +214,9 @@ export function sortThread(
} }
return b.post.indexedAt.localeCompare(a.post.indexedAt) 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 return node
} }
+6 -1
View File
@@ -182,7 +182,12 @@ export function PostThread({
if (!threadViewPrefs || !thread) return null if (!threadViewPrefs || !thread) return null
return createThreadSkeleton( return createThreadSkeleton(
sortThread(thread, threadViewPrefs, threadModerationCache), sortThread(
thread,
threadViewPrefs,
threadModerationCache,
threadgateRecord ?? undefined,
),
hasSession, hasSession,
treeView, treeView,
threadModerationCache, threadModerationCache,