From 31ae18591cc8fdfcb103b9112f2719765aef50a4 Mon Sep 17 00:00:00 2001 From: Matthieu Sieben Date: Tue, 7 Jan 2025 17:19:52 +0100 Subject: [PATCH] suggestions (#7382) * suggestions * Revert unneeded changes --------- Co-authored-by: Eric Bailey --- src/lib/strings/embed-player.ts | 9 +++++++++ src/screens/Messages/components/MessageInputEmbed.tsx | 6 +----- src/types/atproto/index.ts | 4 ++-- src/types/atproto/profile.ts | 6 ++---- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/lib/strings/embed-player.ts b/src/lib/strings/embed-player.ts index 9ee5128c89..0b3073b95d 100644 --- a/src/lib/strings/embed-player.ts +++ b/src/lib/strings/embed-player.ts @@ -568,3 +568,12 @@ export function parseTenorGif(urlp: URL): dimensions, } } + +export function isTenorGifUri(url: URL | string) { + try { + return parseTenorGif(typeof url === 'string' ? new URL(url) : url).success + } catch { + // Invalid URL + return false + } +} diff --git a/src/screens/Messages/components/MessageInputEmbed.tsx b/src/screens/Messages/components/MessageInputEmbed.tsx index 6df0ef2fc8..827c62f061 100644 --- a/src/screens/Messages/components/MessageInputEmbed.tsx +++ b/src/screens/Messages/components/MessageInputEmbed.tsx @@ -111,11 +111,7 @@ export function MessageInputEmbed({ ) const {rt, record} = useMemo(() => { - if ( - post && - AppBskyFeedPost.isRecord(post.record) && - AppBskyFeedPost.validateRecord(post.record).success - ) { + if (post && AppBskyFeedPost.isValidRecord(post.record)) { return { rt: new RichTextAPI({ text: post.record.text, diff --git a/src/types/atproto/index.ts b/src/types/atproto/index.ts index 0f17653cc7..75f78d7b11 100644 --- a/src/types/atproto/index.ts +++ b/src/types/atproto/index.ts @@ -16,9 +16,9 @@ export * as profile from '#/types/atproto/profile' * } * ``` */ -export function fastIsType( +export function fastIsType( record: unknown, - identity: (v: V) => boolean, + identity: (v: V) => v is V & {$type: NonNullable}, ): record is R { return identity(record) } diff --git a/src/types/atproto/profile.ts b/src/types/atproto/profile.ts index fd3a0c0816..55881fe126 100644 --- a/src/types/atproto/profile.ts +++ b/src/types/atproto/profile.ts @@ -42,10 +42,8 @@ export function anyToBasic( associated: view.associated, viewer: view.viewer, labels: view.labels, - // @ts-expect-error `createdAt` doesn't exist on chat view - createdAt: ChatBskyActorDefs.isProfileViewBasic(view) - ? undefined - : view.createdAt, + // `createdAt` doesn't exist in ChatBskyActorDefs.ProfileViewBasic + createdAt: 'createdAt' in view ? view.createdAt : undefined, } }