From c06040cc209338fc37980648b31d4d64cc0c5c09 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 8 Oct 2024 09:02:58 +0900 Subject: Fetch link previews from RQ (#5608) Co-authored-by: Mary Co-authored-by: Hailey --- src/state/shell/composer/index.tsx | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/state/shell/composer/index.tsx') diff --git a/src/state/shell/composer/index.tsx b/src/state/shell/composer/index.tsx index 770b0789e..096948506 100644 --- a/src/state/shell/composer/index.tsx +++ b/src/state/shell/composer/index.tsx @@ -7,9 +7,12 @@ import { } from '@atproto/api' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' +import {useQueryClient} from '@tanstack/react-query' import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback' +import {postUriToRelativePath, toBskyAppUrl} from '#/lib/strings/url-helpers' import {purgeTemporaryImageFiles} from '#/state/gallery' +import {precacheResolveLinkQuery} from '#/state/queries/resolve-link' import * as Toast from '#/view/com/util/Toast' export interface ComposerOptsPostRef { @@ -58,8 +61,28 @@ const controlsContext = React.createContext({ export function Provider({children}: React.PropsWithChildren<{}>) { const {_} = useLingui() const [state, setState] = React.useState() + const queryClient = useQueryClient() const openComposer = useNonReactiveCallback((opts: ComposerOpts) => { + if (opts.quote) { + const path = postUriToRelativePath(opts.quote.uri) + if (path) { + const appUrl = toBskyAppUrl(path) + precacheResolveLinkQuery(queryClient, appUrl, { + type: 'record', + kind: 'post', + record: { + cid: opts.quote.cid, + uri: opts.quote.uri, + }, + meta: { + author: opts.quote.author, + indexedAt: opts.quote.indexedAt, + text: opts.quote.text, + }, + }) + } + } const author = opts.replyTo?.author || opts.quote?.author const isBlocked = Boolean( author && -- cgit 1.4.1