Bluesky app fork with some witchin' additions 💫

Immediately parse pre-filled links in composer state (#6974)

* Immediately parse pre-filled links in composer state

* Add hack to fix PasteInput height bug

* Parse out ext links separately from post links

authored by

Eric Bailey and committed by
GitHub
d05217e5 8c68093d

+75 -5
+68 -2
src/view/com/composer/state/composer.ts
··· 1 1 import {ImagePickerAsset} from 'expo-image-picker' 2 - import {AppBskyFeedPostgate, RichText} from '@atproto/api' 2 + import {AppBskyFeedPostgate, AppBskyRichtextFacet, RichText} from '@atproto/api' 3 3 import {nanoid} from 'nanoid/non-secure' 4 4 5 5 import {SelfLabel} from '#/lib/moderation' ··· 16 16 import {threadgateViewToAllowUISetting} from '#/state/queries/threadgate' 17 17 import {ThreadgateAllowUISetting} from '#/state/queries/threadgate' 18 18 import {ComposerOpts} from '#/state/shell/composer' 19 + import { 20 + LinkFacetMatch, 21 + suggestLinkCardUri, 22 + } from '#/view/com/composer/text-input/text-input-util' 19 23 import {createVideoState, VideoAction, videoReducer, VideoState} from './video' 20 24 21 25 type ImagesMedia = { ··· 508 512 ) 509 513 : '', 510 514 }) 515 + 516 + let link: Link | undefined 517 + 518 + /** 519 + * `initText` atm is only used for compose intents, meaning share links from 520 + * external sources. If `initText` is defined, we want to extract links/posts 521 + * from `initText` and suggest them as embeds. 522 + * 523 + * This checks for posts separately from other types of links so that posts 524 + * can become quotes. The util `suggestLinkCardUri` is then applied to ensure 525 + * we suggest at most 1 of each. 526 + */ 527 + if (initText) { 528 + initRichText.detectFacetsWithoutResolution() 529 + const detectedExtUris = new Map<string, LinkFacetMatch>() 530 + const detectedPostUris = new Map<string, LinkFacetMatch>() 531 + if (initRichText.facets) { 532 + for (const facet of initRichText.facets) { 533 + for (const feature of facet.features) { 534 + if (AppBskyRichtextFacet.isLink(feature)) { 535 + if (isBskyPostUrl(feature.uri)) { 536 + detectedPostUris.set(feature.uri, {facet, rt: initRichText}) 537 + } else { 538 + detectedExtUris.set(feature.uri, {facet, rt: initRichText}) 539 + } 540 + } 541 + } 542 + } 543 + } 544 + const pastSuggestedUris = new Set<string>() 545 + const suggestedExtUri = suggestLinkCardUri( 546 + true, 547 + detectedExtUris, 548 + new Map(), 549 + pastSuggestedUris, 550 + ) 551 + if (suggestedExtUri) { 552 + link = { 553 + type: 'link', 554 + uri: suggestedExtUri, 555 + } 556 + } 557 + const suggestedPostUri = suggestLinkCardUri( 558 + true, 559 + detectedPostUris, 560 + new Map(), 561 + pastSuggestedUris, 562 + ) 563 + if (suggestedPostUri) { 564 + /* 565 + * `initQuote` is only populated via in-app user action, but we're being 566 + * future-defensive here. 567 + */ 568 + if (!quote) { 569 + quote = { 570 + type: 'link', 571 + uri: suggestedPostUri, 572 + } 573 + } 574 + } 575 + } 576 + 511 577 return { 512 578 activePostIndex: 0, 513 579 mutableNeedsFocusActive: false, ··· 521 587 embed: { 522 588 quote, 523 589 media, 524 - link: undefined, 590 + link, 525 591 }, 526 592 }, 527 593 ],
+4
src/view/com/composer/text-input/TextInput.tsx
··· 257 257 minHeight: 60, 258 258 includeFontPadding: false, 259 259 }, 260 + { 261 + borderWidth: 1, 262 + borderColor: 'transparent', 263 + }, 260 264 ]} 261 265 {...props}> 262 266 {textDecorated}
+3 -3
src/view/com/composer/text-input/text-input-util.ts
··· 6 6 } 7 7 8 8 export function suggestLinkCardUri( 9 - mayBePaste: boolean, 9 + suggestLinkImmediately: boolean, 10 10 nextDetectedUris: Map<string, LinkFacetMatch>, 11 11 prevDetectedUris: Map<string, LinkFacetMatch>, 12 12 pastSuggestedUris: Set<string>, ··· 20 20 // Don't suggest already added or already dismissed link cards. 21 21 continue 22 22 } 23 - if (mayBePaste) { 24 - // Immediately add the pasted link without waiting to type more. 23 + if (suggestLinkImmediately) { 24 + // Immediately add the pasted or intent-prefilled link without waiting to type more. 25 25 suggestedUris.add(uri) 26 26 continue 27 27 }