Fetch link previews from RQ (#5608)
Co-authored-by: Mary <git@mary.my.id> Co-authored-by: Hailey <me@haileyok.com>
This commit is contained in:
@@ -18,6 +18,8 @@ import {msg, plural} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
|
||||
import {POST_CTRL_HITSLOP} from '#/lib/constants'
|
||||
import {CountWheel} from '#/lib/custom-animations/CountWheel'
|
||||
import {AnimatedLikeIcon} from '#/lib/custom-animations/LikeIcon'
|
||||
import {useHaptics} from '#/lib/haptics'
|
||||
import {makeProfileLink} from '#/lib/routes/links'
|
||||
import {shareUrl} from '#/lib/sharing'
|
||||
@@ -35,8 +37,6 @@ import {
|
||||
ProgressGuideAction,
|
||||
useProgressGuideControls,
|
||||
} from '#/state/shell/progress-guide'
|
||||
import {CountWheel} from 'lib/custom-animations/CountWheel'
|
||||
import {AnimatedLikeIcon} from 'lib/custom-animations/LikeIcon'
|
||||
import {atoms as a, useTheme} from '#/alf'
|
||||
import {useDialogControl} from '#/components/Dialog'
|
||||
import {ArrowOutOfBox_Stroke2_Corner0_Rounded as ArrowOutOfBox} from '#/components/icons/ArrowOutOfBox'
|
||||
|
||||
@@ -5,6 +5,7 @@ import {AppBskyEmbedExternal} from '@atproto/api'
|
||||
import {msg} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
|
||||
import {parseAltFromGIFDescription} from '#/lib/gif-alt-text'
|
||||
import {usePalette} from '#/lib/hooks/usePalette'
|
||||
import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
|
||||
import {shareUrl} from '#/lib/sharing'
|
||||
@@ -55,7 +56,16 @@ export const ExternalLinkEmbed = ({
|
||||
}, [link.uri, externalEmbedPrefs])
|
||||
|
||||
if (embedPlayerParams?.source === 'tenor') {
|
||||
return <GifEmbed params={embedPlayerParams} link={link} hideAlt={hideAlt} />
|
||||
const parsedAlt = parseAltFromGIFDescription(link.description)
|
||||
return (
|
||||
<GifEmbed
|
||||
params={embedPlayerParams}
|
||||
thumb={link.thumb}
|
||||
altText={parsedAlt.alt}
|
||||
isPreferredAltText={parsedAlt.isPreferred}
|
||||
hideAlt={hideAlt}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -7,12 +7,10 @@ import {
|
||||
View,
|
||||
ViewStyle,
|
||||
} from 'react-native'
|
||||
import {AppBskyEmbedExternal} from '@atproto/api'
|
||||
import {msg, Trans} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
|
||||
import {HITSLOP_20} from '#/lib/constants'
|
||||
import {parseAltFromGIFDescription} from '#/lib/gif-alt-text'
|
||||
import {EmbedPlayerParams} from '#/lib/strings/embed-player'
|
||||
import {isWeb} from '#/platform/detection'
|
||||
import {useAutoplayDisabled} from '#/state/preferences'
|
||||
@@ -77,12 +75,16 @@ function PlaybackControls({
|
||||
|
||||
export function GifEmbed({
|
||||
params,
|
||||
link,
|
||||
thumb,
|
||||
altText,
|
||||
isPreferredAltText,
|
||||
hideAlt,
|
||||
style = {width: '100%'},
|
||||
}: {
|
||||
params: EmbedPlayerParams
|
||||
link: AppBskyEmbedExternal.ViewExternal
|
||||
thumb: string | undefined
|
||||
altText: string
|
||||
isPreferredAltText: boolean
|
||||
hideAlt?: boolean
|
||||
style?: StyleProp<ViewStyle>
|
||||
}) {
|
||||
@@ -111,11 +113,6 @@ export function GifEmbed({
|
||||
playerRef.current?.toggleAsync()
|
||||
}, [])
|
||||
|
||||
const parsedAlt = React.useMemo(
|
||||
() => parseAltFromGIFDescription(link.description),
|
||||
[link],
|
||||
)
|
||||
|
||||
return (
|
||||
<View style={[a.rounded_md, a.overflow_hidden, a.mt_sm, style]}>
|
||||
<View
|
||||
@@ -131,13 +128,13 @@ export function GifEmbed({
|
||||
/>
|
||||
<GifView
|
||||
source={params.playerUri}
|
||||
placeholderSource={link.thumb}
|
||||
placeholderSource={thumb}
|
||||
style={[a.flex_1, a.rounded_md]}
|
||||
autoplay={!autoplayDisabled}
|
||||
onPlayerStateChange={onPlayerStateChange}
|
||||
ref={playerRef}
|
||||
accessibilityHint={_(msg`Animated GIF`)}
|
||||
accessibilityLabel={parsedAlt.alt}
|
||||
accessibilityLabel={altText}
|
||||
/>
|
||||
{!playerState.isPlaying && (
|
||||
<Fill
|
||||
@@ -150,7 +147,7 @@ export function GifEmbed({
|
||||
/>
|
||||
)}
|
||||
<MediaInsetBorder />
|
||||
{!hideAlt && parsedAlt.isPreferred && <AltText text={parsedAlt.alt} />}
|
||||
{!hideAlt && isPreferredAltText && <AltText text={altText} />}
|
||||
</View>
|
||||
</View>
|
||||
)
|
||||
|
||||
@@ -31,6 +31,7 @@ import {makeProfileLink} from '#/lib/routes/links'
|
||||
import {s} from '#/lib/styles'
|
||||
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
||||
import {precacheProfile} from '#/state/queries/profile'
|
||||
import {useResolveLinkQuery} from '#/state/queries/resolve-link'
|
||||
import {useSession} from '#/state/session'
|
||||
import {ComposerOptsQuote} from '#/state/shell/composer'
|
||||
import {atoms as a, useTheme} from '#/alf'
|
||||
@@ -286,6 +287,24 @@ export function QuoteX({onRemove}: {onRemove: () => void}) {
|
||||
)
|
||||
}
|
||||
|
||||
export function LazyQuoteEmbed({uri}: {uri: string}) {
|
||||
const {data} = useResolveLinkQuery(uri)
|
||||
if (!data || data.type !== 'record' || data.kind !== 'post') {
|
||||
return null
|
||||
}
|
||||
return (
|
||||
<QuoteEmbed
|
||||
quote={{
|
||||
cid: data.record.cid,
|
||||
uri: data.record.uri,
|
||||
author: data.meta.author,
|
||||
indexedAt: data.meta.indexedAt,
|
||||
text: data.meta.text,
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function viewRecordToPostView(
|
||||
viewRecord: AppBskyEmbedRecord.ViewRecord,
|
||||
): AppBskyFeedDefs.PostView {
|
||||
|
||||
Reference in New Issue
Block a user