Hook up post shadow to saved posts (#9225)
This commit is contained in:
Vendored
+4
@@ -8,6 +8,7 @@ import {type QueryClient} from '@tanstack/react-query'
|
|||||||
import EventEmitter from 'eventemitter3'
|
import EventEmitter from 'eventemitter3'
|
||||||
|
|
||||||
import {batchedUpdates} from '#/lib/batchedUpdates'
|
import {batchedUpdates} from '#/lib/batchedUpdates'
|
||||||
|
import {findAllPostsInQueryData as findAllPostsInBookmarksQueryData} from '#/state/queries/bookmarks/useBookmarksQuery'
|
||||||
import {findAllPostsInQueryData as findAllPostsInExploreFeedPreviewsQueryData} from '#/state/queries/explore-feed-previews'
|
import {findAllPostsInQueryData as findAllPostsInExploreFeedPreviewsQueryData} from '#/state/queries/explore-feed-previews'
|
||||||
import {findAllPostsInQueryData as findAllPostsInNotifsQueryData} from '#/state/queries/notifications/feed'
|
import {findAllPostsInQueryData as findAllPostsInNotifsQueryData} from '#/state/queries/notifications/feed'
|
||||||
import {findAllPostsInQueryData as findAllPostsInFeedQueryData} from '#/state/queries/post-feed'
|
import {findAllPostsInQueryData as findAllPostsInFeedQueryData} from '#/state/queries/post-feed'
|
||||||
@@ -190,4 +191,7 @@ function* findPostsInCache(
|
|||||||
)) {
|
)) {
|
||||||
yield post
|
yield post
|
||||||
}
|
}
|
||||||
|
for (let post of findAllPostsInBookmarksQueryData(queryClient, uri)) {
|
||||||
|
yield post
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import {
|
import {
|
||||||
type $Typed,
|
type $Typed,
|
||||||
type AppBskyBookmarkGetBookmarks,
|
type AppBskyBookmarkGetBookmarks,
|
||||||
type AppBskyFeedDefs,
|
AppBskyFeedDefs,
|
||||||
|
AtUri,
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
import {
|
import {
|
||||||
type InfiniteData,
|
type InfiniteData,
|
||||||
@@ -10,7 +11,13 @@ import {
|
|||||||
useInfiniteQuery,
|
useInfiniteQuery,
|
||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
|
|
||||||
|
import {
|
||||||
|
didOrHandleUriMatches,
|
||||||
|
embedViewRecordToPostView,
|
||||||
|
getEmbeddedPost,
|
||||||
|
} from '#/state/queries/util'
|
||||||
import {useAgent} from '#/state/session'
|
import {useAgent} from '#/state/session'
|
||||||
|
import * as bsky from '#/types/bsky'
|
||||||
|
|
||||||
export const bookmarksQueryKeyRoot = 'bookmarks'
|
export const bookmarksQueryKeyRoot = 'bookmarks'
|
||||||
export const createBookmarksQueryKey = () => [bookmarksQueryKeyRoot]
|
export const createBookmarksQueryKey = () => [bookmarksQueryKeyRoot]
|
||||||
@@ -112,3 +119,41 @@ export async function optimisticallyDeleteBookmark(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function* findAllPostsInQueryData(
|
||||||
|
queryClient: QueryClient,
|
||||||
|
uri: string,
|
||||||
|
): Generator<AppBskyFeedDefs.PostView, undefined> {
|
||||||
|
const queryDatas = queryClient.getQueriesData<
|
||||||
|
InfiniteData<AppBskyBookmarkGetBookmarks.OutputSchema>
|
||||||
|
>({
|
||||||
|
queryKey: [bookmarksQueryKeyRoot],
|
||||||
|
})
|
||||||
|
const atUri = new AtUri(uri)
|
||||||
|
|
||||||
|
for (const [_queryKey, queryData] of queryDatas) {
|
||||||
|
if (!queryData?.pages) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for (const page of queryData?.pages) {
|
||||||
|
for (const bookmark of page.bookmarks) {
|
||||||
|
if (
|
||||||
|
!bsky.dangerousIsType<AppBskyFeedDefs.PostView>(
|
||||||
|
bookmark.item,
|
||||||
|
AppBskyFeedDefs.isPostView,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
|
||||||
|
if (didOrHandleUriMatches(atUri, bookmark.item)) {
|
||||||
|
yield bookmark.item
|
||||||
|
}
|
||||||
|
|
||||||
|
const quotedPost = getEmbeddedPost(bookmark.item.embed)
|
||||||
|
if (quotedPost && didOrHandleUriMatches(atUri, quotedPost)) {
|
||||||
|
yield embedViewRecordToPostView(quotedPost)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user