Include hydrated responses for other records (#5646)

* Include hydrated responses for other records

* Rename meta -> view

This is actually all it is now.
This commit is contained in:
dan
2024-10-24 20:43:00 +01:00
committed by GitHub
parent e8a53dcea8
commit 3327c47957
4 changed files with 53 additions and 37 deletions
+29 -29
View File
@@ -1,6 +1,6 @@
import { import {
AppBskyFeedDefs, AppBskyFeedDefs,
AppBskyGraphStarterpack, AppBskyGraphDefs,
ComAtprotoRepoStrongRef, ComAtprotoRepoStrongRef,
} from '@atproto/api' } from '@atproto/api'
import {AtUri} from '@atproto/api' import {AtUri} from '@atproto/api'
@@ -40,24 +40,36 @@ type ResolvedPostRecord = {
type: 'record' type: 'record'
record: ComAtprotoRepoStrongRef.Main record: ComAtprotoRepoStrongRef.Main
kind: 'post' kind: 'post'
meta: AppBskyFeedDefs.PostView view: AppBskyFeedDefs.PostView
} }
type ResolvedOtherRecord = { type ResolvedFeedRecord = {
type: 'record' type: 'record'
record: ComAtprotoRepoStrongRef.Main record: ComAtprotoRepoStrongRef.Main
kind: 'other' kind: 'feed'
meta: { view: AppBskyFeedDefs.GeneratorView
// 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 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 = export type ResolvedLink =
| ResolvedExternalLink | ResolvedExternalLink
| ResolvedPostRecord | ResolvedPostRecord
| ResolvedOtherRecord | ResolvedFeedRecord
| ResolvedListRecord
| ResolvedStarterPackRecord
export class EmbeddingDisabledError extends Error { export class EmbeddingDisabledError extends Error {
constructor() { constructor() {
@@ -87,7 +99,7 @@ export async function resolveLink(
uri: post.uri, uri: post.uri,
}, },
kind: 'post', kind: 'post',
meta: post, view: post,
} }
} }
if (isBskyCustomFeedUrl(uri)) { if (isBskyCustomFeedUrl(uri)) {
@@ -102,11 +114,8 @@ export async function resolveLink(
uri: res.data.view.uri, uri: res.data.view.uri,
cid: res.data.view.cid, cid: res.data.view.cid,
}, },
kind: 'other', kind: 'feed',
meta: { view: res.data.view,
// TODO: Include hydrated content instead.
title: res.data.view.displayName,
},
} }
} }
if (isBskyListUrl(uri)) { if (isBskyListUrl(uri)) {
@@ -121,11 +130,8 @@ export async function resolveLink(
uri: res.data.list.uri, uri: res.data.list.uri,
cid: res.data.list.cid, cid: res.data.list.cid,
}, },
kind: 'other', kind: 'list',
meta: { view: res.data.list,
// TODO: Include hydrated content instead.
title: res.data.list.name,
},
} }
} }
if (isBskyStartUrl(uri) || isBskyStarterPackUrl(uri)) { if (isBskyStartUrl(uri) || isBskyStarterPackUrl(uri)) {
@@ -138,20 +144,14 @@ export async function resolveLink(
const did = await fetchDid(parsed.name) const did = await fetchDid(parsed.name)
const starterPack = createStarterPackUri({did, rkey: parsed.rkey}) const starterPack = createStarterPackUri({did, rkey: parsed.rkey})
const res = await agent.app.bsky.graph.getStarterPack({starterPack}) const res = await agent.app.bsky.graph.getStarterPack({starterPack})
const record = res.data.starterPack.record
return { return {
type: 'record', type: 'record',
record: { record: {
uri: res.data.starterPack.uri, uri: res.data.starterPack.uri,
cid: res.data.starterPack.cid, cid: res.data.starterPack.cid,
}, },
kind: 'other', kind: 'starter-pack',
meta: { view: res.data.starterPack,
// TODO: Include hydrated content instead.
title: AppBskyGraphStarterpack.isRecord(record)
? record.name
: 'Starter Pack',
},
} }
} }
return resolveExternal(agent, uri) return resolveExternal(agent, uri)
+1 -1
View File
@@ -66,7 +66,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
cid: opts.quote.cid, cid: opts.quote.cid,
uri: opts.quote.uri, uri: opts.quote.uri,
}, },
meta: opts.quote, view: opts.quote,
}) })
} }
} }
+22 -6
View File
@@ -1,6 +1,8 @@
import React from 'react' import React from 'react'
import {StyleProp, View, ViewStyle} from 'react-native' 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 {cleanError} from '#/lib/strings/errors'
import { import {
useResolveGifQuery, useResolveGifQuery,
@@ -75,12 +77,7 @@ export const ExternalEmbedLink = ({
const linkInfo = React.useMemo( const linkInfo = React.useMemo(
() => () =>
data && { data && {
title: title: getExternalLinkTitle(data) ?? uri,
data.type === 'external'
? data.title
: data.kind === 'other'
? data.meta.title
: uri,
uri, uri,
description: data.type === 'external' ? data.description : '', description: data.type === 'external' ? data.description : '',
thumb: data.type === 'external' ? data.thumb?.source.path : undefined, thumb: data.type === 'external' ? data.thumb?.source.path : undefined,
@@ -137,3 +134,22 @@ function Container({
</View> </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'
}
}
+1 -1
View File
@@ -284,7 +284,7 @@ export function LazyQuoteEmbed({uri}: {uri: string}) {
if (!data || data.type !== 'record' || data.kind !== 'post') { if (!data || data.type !== 'record' || data.kind !== 'post') {
return null return null
} }
return <QuoteEmbed quote={data.meta} /> return <QuoteEmbed quote={data.view} />
} }
function viewRecordToPostView( function viewRecordToPostView(