Show own replies before follows' replies in threads (#4882)

zio/stable
dan 2024-08-06 17:12:27 +01:00 committed by GitHub
parent b291a1ed8a
commit 5845e08eee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 5 deletions

View File

@ -136,6 +136,7 @@ export function sortThread(
node: ThreadNode, node: ThreadNode,
opts: UsePreferencesQueryResponse['threadViewPrefs'], opts: UsePreferencesQueryResponse['threadViewPrefs'],
modCache: ThreadModerationCache, modCache: ThreadModerationCache,
currentDid: string | undefined,
): ThreadNode { ): ThreadNode {
if (node.type !== 'post') { if (node.type !== 'post') {
return node return node
@ -159,6 +160,16 @@ export function sortThread(
return 1 // op's own reply 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 aBlur = Boolean(modCache.get(a)?.ui('contentList').blur)
const bBlur = Boolean(modCache.get(b)?.ui('contentList').blur) const bBlur = Boolean(modCache.get(b)?.ui('contentList').blur)
if (aBlur !== bBlur) { if (aBlur !== bBlur) {
@ -195,7 +206,7 @@ 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, currentDid))
} }
return node return node
} }

View File

@ -89,7 +89,7 @@ export function PostThread({
onCanReply: (canReply: boolean) => void onCanReply: (canReply: boolean) => void
onPressReply: () => unknown onPressReply: () => unknown
}) { }) {
const {hasSession} = useSession() const {hasSession, currentAccount} = useSession()
const {_} = useLingui() const {_} = useLingui()
const t = useTheme() const t = useTheme()
const {isMobile, isTabletOrMobile} = useWebMediaQueries() const {isMobile, isTabletOrMobile} = useWebMediaQueries()
@ -154,6 +154,7 @@ export function PostThread({
// On the web this is not necessary because we can synchronously adjust the scroll in onContentSizeChange instead. // On the web this is not necessary because we can synchronously adjust the scroll in onContentSizeChange instead.
const [deferParents, setDeferParents] = React.useState(isNative) const [deferParents, setDeferParents] = React.useState(isNative)
const currentDid = currentAccount?.did
const threadModerationCache = React.useMemo(() => { const threadModerationCache = React.useMemo(() => {
const cache: ThreadModerationCache = new WeakMap() const cache: ThreadModerationCache = new WeakMap()
if (thread && moderationOpts) { if (thread && moderationOpts) {
@ -167,8 +168,8 @@ 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, currentDid),
hasSession, !!currentDid,
treeView, treeView,
threadModerationCache, threadModerationCache,
hiddenRepliesState !== HiddenRepliesState.Hide, hiddenRepliesState !== HiddenRepliesState.Hide,
@ -176,7 +177,7 @@ export function PostThread({
}, [ }, [
thread, thread,
preferences?.threadViewPrefs, preferences?.threadViewPrefs,
hasSession, currentDid,
treeView, treeView,
threadModerationCache, threadModerationCache,
hiddenRepliesState, hiddenRepliesState,