Skip to content

Commit

Permalink
Use fastIsType where no validation was happening before
Browse files Browse the repository at this point in the history
  • Loading branch information
estrattonbailey committed Jan 7, 2025
1 parent 9520fdb commit 5e1262b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/state/queries/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
} from '@atproto/api'
import {InfiniteData, QueryClient, QueryKey} from '@tanstack/react-query'

import * as atp from '#/types/atproto'

export async function truncateAndInvalidate<T = any>(
queryClient: QueryClient,
queryKey: QueryKey,
Expand Down Expand Up @@ -44,15 +46,20 @@ export function didOrHandleUriMatches(
export function getEmbeddedPost(
v: unknown,
): AppBskyEmbedRecord.ViewRecord | undefined {
if (AppBskyEmbedRecord.isValidView(v)) {
if (atp.fastIsType<AppBskyEmbedRecord.View>(v, AppBskyEmbedRecord.isView)) {
if (
AppBskyEmbedRecord.isViewRecord(v.record) &&
AppBskyFeedPost.isRecord(v.record.value)
) {
return v.record
}
}
if (AppBskyEmbedRecordWithMedia.isValidView(v)) {
if (
atp.fastIsType<AppBskyEmbedRecordWithMedia.View>(
v,
AppBskyEmbedRecordWithMedia.isView,
)
) {
if (
AppBskyEmbedRecord.isViewRecord(v.record.record) &&
AppBskyFeedPost.isRecord(v.record.record.value)
Expand Down

0 comments on commit 5e1262b

Please sign in to comment.