Skip to content

Commit

Permalink
Show own replies before follows' replies in threads (bluesky-social#4882
Browse files Browse the repository at this point in the history
)
  • Loading branch information
gaearon authored Aug 6, 2024
1 parent b291a1e commit 5845e08
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
13 changes: 12 additions & 1 deletion src/state/queries/post-thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export function sortThread(
node: ThreadNode,
opts: UsePreferencesQueryResponse['threadViewPrefs'],
modCache: ThreadModerationCache,
currentDid: string | undefined,
): ThreadNode {
if (node.type !== 'post') {
return node
Expand All @@ -159,6 +160,16 @@ export function sortThread(
return 1 // op's own reply
}

const aIsBySelf = a.post.author.did === currentDid
const bIsBySelf = b.post.author.did === currentDid
if (aIsBySelf && bIsBySelf) {
return a.post.indexedAt.localeCompare(b.post.indexedAt) // oldest
} else if (aIsBySelf) {
return -1 // current account's reply
} else if (bIsBySelf) {
return 1 // current account's reply
}

const aBlur = Boolean(modCache.get(a)?.ui('contentList').blur)
const bBlur = Boolean(modCache.get(b)?.ui('contentList').blur)
if (aBlur !== bBlur) {
Expand Down Expand Up @@ -195,7 +206,7 @@ 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, currentDid))
}
return node
}
Expand Down
9 changes: 5 additions & 4 deletions src/view/com/post-thread/PostThread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function PostThread({
onCanReply: (canReply: boolean) => void
onPressReply: () => unknown
}) {
const {hasSession} = useSession()
const {hasSession, currentAccount} = useSession()
const {_} = useLingui()
const t = useTheme()
const {isMobile, isTabletOrMobile} = useWebMediaQueries()
Expand Down Expand Up @@ -154,6 +154,7 @@ export function PostThread({
// On the web this is not necessary because we can synchronously adjust the scroll in onContentSizeChange instead.
const [deferParents, setDeferParents] = React.useState(isNative)

const currentDid = currentAccount?.did
const threadModerationCache = React.useMemo(() => {
const cache: ThreadModerationCache = new WeakMap()
if (thread && moderationOpts) {
Expand All @@ -167,16 +168,16 @@ export function PostThread({
if (!threadViewPrefs || !thread) return null

return createThreadSkeleton(
sortThread(thread, threadViewPrefs, threadModerationCache),
hasSession,
sortThread(thread, threadViewPrefs, threadModerationCache, currentDid),
!!currentDid,
treeView,
threadModerationCache,
hiddenRepliesState !== HiddenRepliesState.Hide,
)
}, [
thread,
preferences?.threadViewPrefs,
hasSession,
currentDid,
treeView,
threadModerationCache,
hiddenRepliesState,
Expand Down

0 comments on commit 5845e08

Please sign in to comment.