···1313} from 'react-native-reanimated'
1414import {ReanimatedScrollEvent} from 'react-native-reanimated/lib/typescript/reanimated2/hook/commonTypes'
1515import {useSafeAreaInsets} from 'react-native-safe-area-context'
1616-import {AppBskyEmbedRecord, RichText} from '@atproto/api'
1616+import {AppBskyEmbedRecord, AppBskyRichtextFacet, RichText} from '@atproto/api'
17171818import {shortenLinks, stripInvalidMentions} from '#/lib/strings/rich-text-manip'
1919+import {
2020+ convertBskyAppUrlIfNeeded,
2121+ isBskyPostUrl,
2222+} from '#/lib/strings/url-helpers'
1923import {logger} from '#/logger'
2024import {isNative} from '#/platform/detection'
2125import {isConvoActive, useConvoActive} from '#/state/messages/convo'
···288292 uri: post.uri,
289293 cid: post.cid,
290294 },
295295+ }
296296+297297+ // look for the embed uri in the facets, so we can remove it from the text
298298+ const postLinkFacet = rt.facets?.find(facet => {
299299+ return facet.features.find(feature => {
300300+ if (AppBskyRichtextFacet.isLink(feature)) {
301301+ if (isBskyPostUrl(feature.uri)) {
302302+ const url = convertBskyAppUrlIfNeeded(feature.uri)
303303+ const [_0, _1, _2, rkey] = url.split('/').filter(Boolean)
304304+305305+ // this might have a handle instead of a DID
306306+ // so just compare the rkey - not particularly dangerous
307307+ return post.uri.endsWith(rkey)
308308+ }
309309+ }
310310+ return false
311311+ })
312312+ })
313313+314314+ if (postLinkFacet) {
315315+ // remove the post link from the text
316316+ rt.delete(
317317+ postLinkFacet.index.byteStart,
318318+ postLinkFacet.index.byteEnd,
319319+ )
320320+321321+ // re-trim the text, now that we've removed the post link
322322+ //
323323+ // if the post link is at the start of the text, we don't want to leave a leading space
324324+ // so trim on both sides
325325+ if (postLinkFacet.index.byteStart === 0) {
326326+ rt = new RichText({text: rt.text.trim()}, {cleanNewlines: true})
327327+ } else {
328328+ // otherwise just trim the end
329329+ rt = new RichText(
330330+ {text: rt.text.trimEnd()},
331331+ {cleanNewlines: true},
332332+ )
333333+ }
291334 }
292335 }
293336 } catch (error) {