diff options
author | dan <dan.abramov@gmail.com> | 2024-10-08 09:02:58 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-07 17:02:58 -0700 |
commit | c06040cc209338fc37980648b31d4d64cc0c5c09 (patch) | |
tree | 766e41a310b03bed2e927f468114ca8d14602e5f /src/state/shell/composer | |
parent | dd8be2e939d2879e2bb23b2ccd843a034d19b8dd (diff) | |
download | voidsky-c06040cc209338fc37980648b31d4d64cc0c5c09.tar.zst |
Fetch link previews from RQ (#5608)
Co-authored-by: Mary <git@mary.my.id> Co-authored-by: Hailey <me@haileyok.com>
Diffstat (limited to 'src/state/shell/composer')
-rw-r--r-- | src/state/shell/composer/index.tsx | 23 |
1 files changed, 23 insertions, 0 deletions
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<ControlsContext>({ export function Provider({children}: React.PropsWithChildren<{}>) { const {_} = useLingui() const [state, setState] = React.useState<StateContext>() + 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 && |