Sort hidden replies to bottom
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user