diff options
author | dan <dan.abramov@gmail.com> | 2024-10-24 20:43:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-24 20:43:00 +0100 |
commit | 3327c479575da7f5b3c3a457ec53a24ad9a2cda1 (patch) | |
tree | f0b7dbbe3661288e936fc5cdb416ad8c6cc90d9c /src | |
parent | e8a53dcea84afc3b313037dbaf059c68121eb9ab (diff) | |
download | voidsky-3327c479575da7f5b3c3a457ec53a24ad9a2cda1.tar.zst |
Include hydrated responses for other records (#5646)
* Include hydrated responses for other records * Rename meta -> view This is actually all it is now.
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/api/resolve.ts | 58 | ||||
-rw-r--r-- | src/state/shell/composer/index.tsx | 2 | ||||
-rw-r--r-- | src/view/com/composer/ExternalEmbed.tsx | 28 | ||||
-rw-r--r-- | src/view/com/util/post-embeds/QuoteEmbed.tsx | 2 |
4 files changed, 53 insertions, 37 deletions
diff --git a/src/lib/api/resolve.ts b/src/lib/api/resolve.ts index 277c17b7b..371062350 100644 --- a/src/lib/api/resolve.ts +++ b/src/lib/api/resolve.ts @@ -1,6 +1,6 @@ import { AppBskyFeedDefs, - AppBskyGraphStarterpack, + AppBskyGraphDefs, ComAtprotoRepoStrongRef, } from '@atproto/api' import {AtUri} from '@atproto/api' @@ -40,24 +40,36 @@ type ResolvedPostRecord = { type: 'record' record: ComAtprotoRepoStrongRef.Main kind: 'post' - meta: AppBskyFeedDefs.PostView + view: AppBskyFeedDefs.PostView } -type ResolvedOtherRecord = { +type ResolvedFeedRecord = { type: 'record' record: ComAtprotoRepoStrongRef.Main - kind: 'other' - meta: { - // We should replace this with a hydrated record (e.g. feed, list, starter pack) - // and change the composer preview to use the actual post embed components: - title: string - } + kind: 'feed' + view: AppBskyFeedDefs.GeneratorView +} + +type ResolvedListRecord = { + type: 'record' + record: ComAtprotoRepoStrongRef.Main + kind: 'list' + view: AppBskyGraphDefs.ListView +} + +type ResolvedStarterPackRecord = { + type: 'record' + record: ComAtprotoRepoStrongRef.Main + kind: 'starter-pack' + view: AppBskyGraphDefs.StarterPackView } export type ResolvedLink = | ResolvedExternalLink | ResolvedPostRecord - | ResolvedOtherRecord + | ResolvedFeedRecord + | ResolvedListRecord + | ResolvedStarterPackRecord export class EmbeddingDisabledError extends Error { constructor() { @@ -87,7 +99,7 @@ export async function resolveLink( uri: post.uri, }, kind: 'post', - meta: post, + view: post, } } if (isBskyCustomFeedUrl(uri)) { @@ -102,11 +114,8 @@ export async function resolveLink( uri: res.data.view.uri, cid: res.data.view.cid, }, - kind: 'other', - meta: { - // TODO: Include hydrated content instead. - title: res.data.view.displayName, - }, + kind: 'feed', + view: res.data.view, } } if (isBskyListUrl(uri)) { @@ -121,11 +130,8 @@ export async function resolveLink( uri: res.data.list.uri, cid: res.data.list.cid, }, - kind: 'other', - meta: { - // TODO: Include hydrated content instead. - title: res.data.list.name, - }, + kind: 'list', + view: res.data.list, } } if (isBskyStartUrl(uri) || isBskyStarterPackUrl(uri)) { @@ -138,20 +144,14 @@ export async function resolveLink( const did = await fetchDid(parsed.name) const starterPack = createStarterPackUri({did, rkey: parsed.rkey}) const res = await agent.app.bsky.graph.getStarterPack({starterPack}) - const record = res.data.starterPack.record return { type: 'record', record: { uri: res.data.starterPack.uri, cid: res.data.starterPack.cid, }, - kind: 'other', - meta: { - // TODO: Include hydrated content instead. - title: AppBskyGraphStarterpack.isRecord(record) - ? record.name - : 'Starter Pack', - }, + kind: 'starter-pack', + view: res.data.starterPack, } } return resolveExternal(agent, uri) diff --git a/src/state/shell/composer/index.tsx b/src/state/shell/composer/index.tsx index dc9a7d880..9cac64426 100644 --- a/src/state/shell/composer/index.tsx +++ b/src/state/shell/composer/index.tsx @@ -66,7 +66,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) { cid: opts.quote.cid, uri: opts.quote.uri, }, - meta: opts.quote, + view: opts.quote, }) } } diff --git a/src/view/com/composer/ExternalEmbed.tsx b/src/view/com/composer/ExternalEmbed.tsx index d7dc32f14..1f1feaf91 100644 --- a/src/view/com/composer/ExternalEmbed.tsx +++ b/src/view/com/composer/ExternalEmbed.tsx @@ -1,6 +1,8 @@ import React from 'react' import {StyleProp, View, ViewStyle} from 'react-native' +import {AppBskyGraphStarterpack} from '@atproto/api' +import {ResolvedLink} from '#/lib/api/resolve' import {cleanError} from '#/lib/strings/errors' import { useResolveGifQuery, @@ -75,12 +77,7 @@ export const ExternalEmbedLink = ({ const linkInfo = React.useMemo( () => data && { - title: - data.type === 'external' - ? data.title - : data.kind === 'other' - ? data.meta.title - : uri, + title: getExternalLinkTitle(data) ?? uri, uri, description: data.type === 'external' ? data.description : '', thumb: data.type === 'external' ? data.thumb?.source.path : undefined, @@ -137,3 +134,22 @@ function Container({ </View> ) } + +function getExternalLinkTitle(link: ResolvedLink): string | undefined { + if (link.type === 'external') { + return link.title + } + switch (link.kind) { + // These are currently treated as external. + // TODO: Display them as embeds instead. + case 'feed': + return link.view.displayName + case 'list': + return link.view.name + case 'starter-pack': + const record = link.view.record + return AppBskyGraphStarterpack.isRecord(record) + ? record.name + : 'Starter Pack' + } +} diff --git a/src/view/com/util/post-embeds/QuoteEmbed.tsx b/src/view/com/util/post-embeds/QuoteEmbed.tsx index 49cfb2150..2844d562b 100644 --- a/src/view/com/util/post-embeds/QuoteEmbed.tsx +++ b/src/view/com/util/post-embeds/QuoteEmbed.tsx @@ -284,7 +284,7 @@ export function LazyQuoteEmbed({uri}: {uri: string}) { if (!data || data.type !== 'record' || data.kind !== 'post') { return null } - return <QuoteEmbed quote={data.meta} /> + return <QuoteEmbed quote={data.view} /> } function viewRecordToPostView( |