Prefer full posts for post thread placeholder (#2943)
* Revert "Prefer post over quote when finding cached post (#2935)"
This reverts commit da62a77f05
.
* Prefer full posts for post thread placeholder
* Clarify with a comment
zio/stable
parent
fab6c286f4
commit
3a75855677
|
@ -133,23 +133,6 @@ export function useNotificationFeedQuery(opts?: {enabled?: boolean}) {
|
||||||
return query
|
return query
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This helper is used by the post-thread placeholder function to
|
|
||||||
* find a post in the query-data cache
|
|
||||||
*/
|
|
||||||
export function findPostInQueryData(
|
|
||||||
queryClient: QueryClient,
|
|
||||||
uri: string,
|
|
||||||
): AppBskyFeedDefs.PostView | undefined {
|
|
||||||
const generator = findAllPostsInQueryData(queryClient, uri)
|
|
||||||
const result = generator.next()
|
|
||||||
if (result.done) {
|
|
||||||
return undefined
|
|
||||||
} else {
|
|
||||||
return result.value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* findAllPostsInQueryData(
|
export function* findAllPostsInQueryData(
|
||||||
queryClient: QueryClient,
|
queryClient: QueryClient,
|
||||||
uri: string,
|
uri: string,
|
||||||
|
|
|
@ -365,23 +365,6 @@ function createApi(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This helper is used by the post-thread placeholder function to
|
|
||||||
* find a post in the query-data cache
|
|
||||||
*/
|
|
||||||
export function findPostInQueryData(
|
|
||||||
queryClient: QueryClient,
|
|
||||||
uri: string,
|
|
||||||
): AppBskyFeedDefs.PostView | undefined {
|
|
||||||
const generator = findAllPostsInQueryData(queryClient, uri)
|
|
||||||
const result = generator.next()
|
|
||||||
if (result.done) {
|
|
||||||
return undefined
|
|
||||||
} else {
|
|
||||||
return result.value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* findAllPostsInQueryData(
|
export function* findAllPostsInQueryData(
|
||||||
queryClient: QueryClient,
|
queryClient: QueryClient,
|
||||||
uri: string,
|
uri: string,
|
||||||
|
@ -391,9 +374,6 @@ export function* findAllPostsInQueryData(
|
||||||
>({
|
>({
|
||||||
queryKey: ['post-feed'],
|
queryKey: ['post-feed'],
|
||||||
})
|
})
|
||||||
|
|
||||||
let foundEmbed: AppBskyFeedDefs.PostView | undefined
|
|
||||||
|
|
||||||
for (const [_queryKey, queryData] of queryDatas) {
|
for (const [_queryKey, queryData] of queryDatas) {
|
||||||
if (!queryData?.pages) {
|
if (!queryData?.pages) {
|
||||||
continue
|
continue
|
||||||
|
@ -405,7 +385,7 @@ export function* findAllPostsInQueryData(
|
||||||
}
|
}
|
||||||
const quotedPost = getEmbeddedPost(item.post.embed)
|
const quotedPost = getEmbeddedPost(item.post.embed)
|
||||||
if (quotedPost?.uri === uri) {
|
if (quotedPost?.uri === uri) {
|
||||||
foundEmbed = embedViewRecordToPostView(quotedPost)
|
yield embedViewRecordToPostView(quotedPost)
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
AppBskyFeedDefs.isPostView(item.reply?.parent) &&
|
AppBskyFeedDefs.isPostView(item.reply?.parent) &&
|
||||||
|
@ -422,10 +402,6 @@ export function* findAllPostsInQueryData(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foundEmbed) {
|
|
||||||
yield foundEmbed
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function assertSomePostsPassModeration(feed: AppBskyFeedDefs.FeedViewPost[]) {
|
function assertSomePostsPassModeration(feed: AppBskyFeedDefs.FeedViewPost[]) {
|
||||||
|
|
|
@ -8,8 +8,8 @@ import {useQuery, useQueryClient, QueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {getAgent} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
import {UsePreferencesQueryResponse} from '#/state/queries/preferences/types'
|
import {UsePreferencesQueryResponse} from '#/state/queries/preferences/types'
|
||||||
import {findPostInQueryData as findPostInFeedQueryData} from './post-feed'
|
import {findAllPostsInQueryData as findAllPostsInFeedQueryData} from './post-feed'
|
||||||
import {findPostInQueryData as findPostInNotifsQueryData} from './notifications/feed'
|
import {findAllPostsInQueryData as findAllPostsInNotifsQueryData} from './notifications/feed'
|
||||||
import {precacheThreadPostProfiles} from './profile'
|
import {precacheThreadPostProfiles} from './profile'
|
||||||
import {getEmbeddedPost} from './util'
|
import {getEmbeddedPost} from './util'
|
||||||
|
|
||||||
|
@ -82,21 +82,9 @@ export function usePostThreadQuery(uri: string | undefined) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const item = findPostInQueryData(queryClient, uri)
|
const post = findPostInQueryData(queryClient, uri)
|
||||||
if (item) {
|
if (post) {
|
||||||
return threadNodeToPlaceholderThread(item)
|
return post
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
const item = findPostInFeedQueryData(queryClient, uri)
|
|
||||||
if (item) {
|
|
||||||
return postViewToPlaceholderThread(item)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
const item = findPostInNotifsQueryData(queryClient, uri)
|
|
||||||
if (item) {
|
|
||||||
return postViewToPlaceholderThread(item)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return undefined
|
return undefined
|
||||||
|
@ -213,14 +201,24 @@ function responseToThreadNodes(
|
||||||
function findPostInQueryData(
|
function findPostInQueryData(
|
||||||
queryClient: QueryClient,
|
queryClient: QueryClient,
|
||||||
uri: string,
|
uri: string,
|
||||||
): ThreadNode | undefined {
|
): ThreadNode | void {
|
||||||
const generator = findAllPostsInQueryData(queryClient, uri)
|
let partial
|
||||||
const result = generator.next()
|
for (let item of findAllPostsInQueryData(queryClient, uri)) {
|
||||||
if (result.done) {
|
if (item.type === 'post') {
|
||||||
return undefined
|
// Currently, the backend doesn't send full post info in some cases
|
||||||
} else {
|
// (for example, for quoted posts). We use missing `likeCount`
|
||||||
return result.value
|
// as a way to detect that. In the future, we should fix this on
|
||||||
|
// the backend, which will let us always stop on the first result.
|
||||||
|
const hasAllInfo = item.post.likeCount != null
|
||||||
|
if (hasAllInfo) {
|
||||||
|
return item
|
||||||
|
} else {
|
||||||
|
partial = item
|
||||||
|
// Keep searching, we might still find a full post in the cache.
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return partial
|
||||||
}
|
}
|
||||||
|
|
||||||
export function* findAllPostsInQueryData(
|
export function* findAllPostsInQueryData(
|
||||||
|
@ -236,7 +234,10 @@ export function* findAllPostsInQueryData(
|
||||||
}
|
}
|
||||||
for (const item of traverseThread(queryData)) {
|
for (const item of traverseThread(queryData)) {
|
||||||
if (item.uri === uri) {
|
if (item.uri === uri) {
|
||||||
yield item
|
const placeholder = threadNodeToPlaceholderThread(item)
|
||||||
|
if (placeholder) {
|
||||||
|
yield placeholder
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const quotedPost =
|
const quotedPost =
|
||||||
item.type === 'post' ? getEmbeddedPost(item.post.embed) : undefined
|
item.type === 'post' ? getEmbeddedPost(item.post.embed) : undefined
|
||||||
|
@ -245,6 +246,12 @@ export function* findAllPostsInQueryData(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (let post of findAllPostsInFeedQueryData(queryClient, uri)) {
|
||||||
|
yield postViewToPlaceholderThread(post)
|
||||||
|
}
|
||||||
|
for (let post of findAllPostsInNotifsQueryData(queryClient, uri)) {
|
||||||
|
yield postViewToPlaceholderThread(post)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function* traverseThread(node: ThreadNode): Generator<ThreadNode, void> {
|
function* traverseThread(node: ThreadNode): Generator<ThreadNode, void> {
|
||||||
|
|
Loading…
Reference in New Issue