Simple working version, no pref for OP
This commit is contained in:
@@ -86,9 +86,9 @@ export function usePostThread({
|
|||||||
showHidden: state.shownHiddenReplyKinds.has(HiddenReplyKind.Hidden),
|
showHidden: state.shownHiddenReplyKinds.has(HiddenReplyKind.Hidden),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
console.log(items)
|
|
||||||
|
|
||||||
const mutator = createCacheMutator({
|
const mutator = createCacheMutator({
|
||||||
|
params,
|
||||||
queryKey,
|
queryKey,
|
||||||
queryClient: qc,
|
queryClient: qc,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {findAllPostsInQueryData as findAllPostsInSearchQueryData} from '#/state/
|
|||||||
import {
|
import {
|
||||||
type createPostThreadQueryKey,
|
type createPostThreadQueryKey,
|
||||||
postThreadQueryKeyRoot,
|
postThreadQueryKeyRoot,
|
||||||
|
type PostThreadParams,
|
||||||
} from '#/state/queries/usePostThread/types'
|
} from '#/state/queries/usePostThread/types'
|
||||||
import {
|
import {
|
||||||
embedViewToThreadPlaceholder,
|
embedViewToThreadPlaceholder,
|
||||||
@@ -17,9 +18,11 @@ import {
|
|||||||
import {didOrHandleUriMatches, getEmbeddedPost} from '#/state/queries/util'
|
import {didOrHandleUriMatches, getEmbeddedPost} from '#/state/queries/util'
|
||||||
|
|
||||||
export function createCacheMutator({
|
export function createCacheMutator({
|
||||||
|
params,
|
||||||
queryKey,
|
queryKey,
|
||||||
queryClient,
|
queryClient,
|
||||||
}: {
|
}: {
|
||||||
|
params: PostThreadParams
|
||||||
queryKey: ReturnType<typeof createPostThreadQueryKey>
|
queryKey: ReturnType<typeof createPostThreadQueryKey>
|
||||||
queryClient: QueryClient
|
queryClient: QueryClient
|
||||||
}) {
|
}) {
|
||||||
@@ -55,20 +58,31 @@ export function createCacheMutator({
|
|||||||
replyCount: parent.value.post.replyCount,
|
replyCount: parent.value.post.replyCount,
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
const nextItem = thread.at(i + 1)
|
||||||
* Splice in new replies
|
const isReplyToRoot = existingParent.depth === 0
|
||||||
*/
|
const isEndOfReplyChain =
|
||||||
for (let ri = 0; ri < replies.length; ri++) {
|
!nextItem || nextItem.depth <= existingParent.depth
|
||||||
const reply = replies[ri]
|
const shouldInsertReplies =
|
||||||
if (
|
isReplyToRoot ||
|
||||||
!AppBskyUnspeccedGetPostThreadV2.isThreadItemPost(reply.value)
|
params.view === 'tree' ||
|
||||||
)
|
(params.view === 'linear' && isEndOfReplyChain)
|
||||||
continue
|
|
||||||
const insertIndex = i + 1 + ri
|
if (shouldInsertReplies) {
|
||||||
thread.splice(insertIndex, 0, {
|
/*
|
||||||
...reply,
|
* Splice in new replies
|
||||||
depth: existingParent.depth + 1 + ri,
|
*/
|
||||||
})
|
for (let ri = 0; ri < replies.length; ri++) {
|
||||||
|
const reply = replies[ri]
|
||||||
|
if (
|
||||||
|
!AppBskyUnspeccedGetPostThreadV2.isThreadItemPost(reply.value)
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
const insertIndex = i + 1 + ri
|
||||||
|
thread.splice(insertIndex, 0, {
|
||||||
|
...reply,
|
||||||
|
depth: existingParent.depth + 1 + ri,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -204,66 +204,66 @@ export function sort(
|
|||||||
/*
|
/*
|
||||||
* Not moderated, probably need to insert it
|
* Not moderated, probably need to insert it
|
||||||
*/
|
*/
|
||||||
// items.push(post)
|
items.push(post)
|
||||||
if (view === 'tree') {
|
// if (view === 'tree') {
|
||||||
items.push(post)
|
// items.push(post)
|
||||||
} else {
|
// } else {
|
||||||
if (post.depth > 1) {
|
// if (post.depth > 1) {
|
||||||
const maybeNextSiblingIndex = getBranch(thread, i, post.depth).end + 1
|
// const maybeNextSiblingIndex = getBranch(thread, i, post.depth).end + 1
|
||||||
const maybeNextSibling = thread.at(maybeNextSiblingIndex)
|
// const maybeNextSibling = thread.at(maybeNextSiblingIndex)
|
||||||
|
|
||||||
/*
|
// /*
|
||||||
* If we've got two replies at the same depth, we need to decide
|
// * If we've got two replies at the same depth, we need to decide
|
||||||
* which one to show.
|
// * which one to show.
|
||||||
*/
|
// */
|
||||||
if (post.depth === maybeNextSibling?.depth) {
|
// if (post.depth === maybeNextSibling?.depth) {
|
||||||
// continue with next sibling
|
// // continue with next sibling
|
||||||
i = maybeNextSiblingIndex - 1
|
// i = maybeNextSiblingIndex - 1
|
||||||
debugger;
|
// debugger;
|
||||||
continue traversal
|
// continue traversal
|
||||||
} else {
|
// } else {
|
||||||
const maybePrevSiblingIndex = getBranchUp(thread, i - 1, post.depth).end
|
// const maybePrevSiblingIndex = getBranchUp(thread, i - 1, post.depth).end
|
||||||
const maybePrevSibling = thread.at(maybePrevSiblingIndex)
|
// const maybePrevSibling = thread.at(maybePrevSiblingIndex)
|
||||||
|
|
||||||
if (post.depth === maybePrevSibling?.depth) {
|
// if (post.depth === maybePrevSibling?.depth) {
|
||||||
const post = views.threadPost({
|
// const post = views.threadPost({
|
||||||
uri: item.uri,
|
// uri: item.uri,
|
||||||
depth: item.depth,
|
// depth: item.depth,
|
||||||
value: item.value,
|
// value: item.value,
|
||||||
oneUp: thread.at(maybePrevSiblingIndex - 1),
|
// oneUp: thread.at(maybePrevSiblingIndex - 1),
|
||||||
oneDown,
|
// oneDown,
|
||||||
moderationOpts,
|
// moderationOpts,
|
||||||
})
|
// })
|
||||||
debugger;
|
// debugger;
|
||||||
items.push(post)
|
// items.push(post)
|
||||||
} else {
|
// } else {
|
||||||
items.push(post)
|
// items.push(post)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
/*
|
// /*
|
||||||
if (post.depth === oneDown?.depth) {
|
// if (post.depth === oneDown?.depth) {
|
||||||
const opDid = new AtUri(post.value.post.record.reply?.root?.uri).host
|
// const opDid = new AtUri(post.value.post.record.reply?.root?.uri).host
|
||||||
const postAuthorDid = new AtUri(post.uri).host
|
// const postAuthorDid = new AtUri(post.uri).host
|
||||||
debugger;
|
// debugger;
|
||||||
if (postAuthorDid === opDid) {
|
// if (postAuthorDid === opDid) {
|
||||||
// prioritize OP optimistic reply
|
// // prioritize OP optimistic reply
|
||||||
items.push(post)
|
// items.push(post)
|
||||||
// skip next reply
|
// // skip next reply
|
||||||
i = getBranch(thread, i, oneDown.depth).end
|
// i = getBranch(thread, i, oneDown.depth).end
|
||||||
debugger;
|
// debugger;
|
||||||
continue traversal
|
// continue traversal
|
||||||
} else {
|
// } else {
|
||||||
i = getBranch(thread, i, post.depth).end
|
// i = getBranch(thread, i, post.depth).end
|
||||||
debugger;
|
// debugger;
|
||||||
continue traversal
|
// continue traversal
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
*/
|
// */
|
||||||
} else {
|
// } else {
|
||||||
items.push(post)
|
// items.push(post)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* Moderated in some way, we're going to walk children
|
* Moderated in some way, we're going to walk children
|
||||||
|
|||||||
Reference in New Issue
Block a user