From 334483ad9a77ae7a83873264565f9a85241bd50a Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Thu, 23 May 2024 03:52:46 +0100 Subject: [PATCH] [Embeds] stop adding tracking params to non-bsky.app links (#4167) * don't add tracking params on non-bsky.app links * validate facets --- bskyembed/.eslintrc | 2 +- bskyembed/src/components/embed.tsx | 5 +++-- bskyembed/src/components/link.tsx | 8 +++++--- bskyembed/src/components/post.tsx | 33 ++++++++++++++++++++++-------- bskyembed/src/screens/landing.tsx | 4 ++-- bskyembed/src/screens/post.tsx | 4 ++-- 6 files changed, 37 insertions(+), 19 deletions(-) diff --git a/bskyembed/.eslintrc b/bskyembed/.eslintrc index 339900dd..e6e575a1 100644 --- a/bskyembed/.eslintrc +++ b/bskyembed/.eslintrc @@ -15,6 +15,6 @@ "parserOptions": { "sourceType": "module", "ecmaVersion": "latest", - "project": "./tsconfig.json" + "project": "./bskyembed/tsconfig.json" } } \ No newline at end of file diff --git a/bskyembed/src/components/embed.tsx b/bskyembed/src/components/embed.tsx index 4457defc..1dadfee3 100644 --- a/bskyembed/src/components/embed.tsx +++ b/bskyembed/src/components/embed.tsx @@ -193,7 +193,7 @@ export function Embed({ function Info({children}: {children: ComponentChildren}) { return (
- +

{children}

) @@ -293,7 +293,8 @@ function ExternalEmbed({ return ( + className="w-full rounded-lg overflow-hidden border flex flex-col items-stretch" + disableTracking> {content.external.thumb && ( ) { const searchParam = new URLSearchParams(window.location.search) const ref_url = searchParam.get('ref_url') @@ -19,9 +21,9 @@ export function Link({ return ( evt.stopPropagation()} diff --git a/bskyembed/src/components/post.tsx b/bskyembed/src/components/post.tsx index 3f2c745b..d23c84cb 100644 --- a/bskyembed/src/components/post.tsx +++ b/bskyembed/src/components/post.tsx @@ -1,4 +1,9 @@ -import {AppBskyFeedDefs, AppBskyFeedPost, RichText} from '@atproto/api' +import { + AppBskyFeedDefs, + AppBskyFeedPost, + AppBskyRichtextFacet, + RichText, +} from '@atproto/api' import {h} from 'preact' import replyIcon from '../../assets/bubble_filled_stroke2_corner2_rounded.svg' @@ -56,7 +61,7 @@ export function Post({thread}: Props) { - + @@ -71,7 +76,7 @@ export function Post({thread}: Props) {
{!!post.likeCount && (
- +

{post.likeCount}

@@ -79,14 +84,14 @@ export function Post({thread}: Props) { )} {!!post.repostCount && (
- +

{post.repostCount}

)}
- +

Reply

@@ -118,16 +123,23 @@ function PostContent({record}: {record: AppBskyFeedPost.Record | null}) { let counter = 0 for (const segment of rt.segments()) { - if (segment.isLink() && segment.link) { + if ( + segment.link && + AppBskyRichtextFacet.validateLink(segment.link).success + ) { richText.push( + className="text-blue-400 hover:underline" + disableTracking={!segment.link.uri.startsWith('https://bsky.app')}> {segment.text} , ) - } else if (segment.isMention() && segment.mention) { + } else if ( + segment.mention && + AppBskyRichtextFacet.validateMention(segment.mention).success + ) { richText.push( , ) - } else if (segment.isTag() && segment.tag) { + } else if ( + segment.tag && + AppBskyRichtextFacet.validateTag(segment.tag).success + ) { richText.push( - +

Embed a Bluesky Post

@@ -125,7 +125,7 @@ function LandingPage() { placeholder={DEFAULT_POST} /> - + {loading ? ( diff --git a/bskyembed/src/screens/post.tsx b/bskyembed/src/screens/post.tsx index 365227cd..337bf010 100644 --- a/bskyembed/src/screens/post.tsx +++ b/bskyembed/src/screens/post.tsx @@ -52,7 +52,7 @@ function PwiOptOut({thread}: {thread: AppBskyFeedDefs.ThreadViewPost}) { - +

@@ -75,7 +75,7 @@ function ErrorMessage() { - +

Post not found, it may have been deleted.