Perf: Include quote posts in the post-thread placeholder (#2104)
This commit is contained in:
parent
accb25ccf2
commit
712cd3fde5
4 changed files with 96 additions and 1 deletions
|
@ -1,4 +1,10 @@
|
|||
import {QueryClient, QueryKey, InfiniteData} from '@tanstack/react-query'
|
||||
import {
|
||||
AppBskyEmbedRecord,
|
||||
AppBskyEmbedRecordWithMedia,
|
||||
AppBskyFeedDefs,
|
||||
AppBskyFeedPost,
|
||||
} from '@atproto/api'
|
||||
|
||||
export function truncateAndInvalidate<T = any>(
|
||||
queryClient: QueryClient,
|
||||
|
@ -15,3 +21,45 @@ export function truncateAndInvalidate<T = any>(
|
|||
})
|
||||
queryClient.invalidateQueries({queryKey})
|
||||
}
|
||||
|
||||
export function getEmbeddedPost(
|
||||
v: unknown,
|
||||
): AppBskyEmbedRecord.ViewRecord | undefined {
|
||||
if (
|
||||
AppBskyEmbedRecord.isView(v) &&
|
||||
AppBskyEmbedRecord.validateView(v).success
|
||||
) {
|
||||
if (
|
||||
AppBskyEmbedRecord.isViewRecord(v.record) &&
|
||||
AppBskyFeedPost.isRecord(v.record.value) &&
|
||||
AppBskyFeedPost.validateRecord(v.record.value).success
|
||||
) {
|
||||
return v.record
|
||||
}
|
||||
}
|
||||
if (
|
||||
AppBskyEmbedRecordWithMedia.isView(v) &&
|
||||
AppBskyEmbedRecordWithMedia.validateView(v).success
|
||||
) {
|
||||
if (
|
||||
AppBskyEmbedRecord.isViewRecord(v.record.record) &&
|
||||
AppBskyFeedPost.isRecord(v.record.record.value) &&
|
||||
AppBskyFeedPost.validateRecord(v.record.record.value).success
|
||||
) {
|
||||
return v.record.record
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function embedViewRecordToPostView(
|
||||
v: AppBskyEmbedRecord.ViewRecord,
|
||||
): AppBskyFeedDefs.PostView {
|
||||
return {
|
||||
uri: v.uri,
|
||||
cid: v.cid,
|
||||
author: v.author,
|
||||
record: v.value,
|
||||
indexedAt: v.indexedAt,
|
||||
labels: v.labels,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue