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:
+29
-29
@@ -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)
|
||||
|
||||
@@ -66,7 +66,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
cid: opts.quote.cid,
|
||||
uri: opts.quote.uri,
|
||||
},
|
||||
meta: opts.quote,
|
||||
view: opts.quote,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user