[APP-2160] Extract StandardSiteEmbed type guards into utils.ts
Move isStandardSiteEmbed alongside a new isStandardSitePublicationEmbed helper. The publication check now requires at least one publication ref and zero document refs, replacing a tautological condition that also returned true for empty associatedRefs arrays.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import {type AppBskyEmbedExternal, AtUri} from '@atproto/api'
|
||||
|
||||
export function isStandardSiteEmbed(view: AppBskyEmbedExternal.ViewExternal) {
|
||||
return view.associatedRefs?.some(ref =>
|
||||
new AtUri(ref.uri).collection.startsWith('site.standard.'),
|
||||
)
|
||||
}
|
||||
|
||||
export function isStandardSitePublicationEmbed(
|
||||
view: AppBskyEmbedExternal.ViewExternal,
|
||||
) {
|
||||
return (
|
||||
view.associatedRefs?.some(
|
||||
ref => new AtUri(ref.uri).collection === 'site.standard.publication',
|
||||
) &&
|
||||
view.associatedRefs.every(
|
||||
ref => new AtUri(ref.uri).collection !== 'site.standard.document',
|
||||
)
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user