Add feed sharing
parent
84990c509e
commit
1ecf0da81b
|
@ -18,6 +18,7 @@ export interface ExternalEmbedDraft {
|
||||||
uri: string
|
uri: string
|
||||||
isLoading: boolean
|
isLoading: boolean
|
||||||
meta?: LinkMeta
|
meta?: LinkMeta
|
||||||
|
embed?: AppBskyEmbedRecord.Main
|
||||||
localThumb?: ImageModel
|
localThumb?: ImageModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,6 +136,9 @@ export async function post(store: RootStoreModel, opts: PostOpts) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.extLink && !opts.images?.length) {
|
if (opts.extLink && !opts.images?.length) {
|
||||||
|
if (opts.extLink.embed) {
|
||||||
|
embed = opts.extLink.embed
|
||||||
|
} else {
|
||||||
let thumb
|
let thumb
|
||||||
if (opts.extLink.localThumb) {
|
if (opts.extLink.localThumb) {
|
||||||
opts.onStateChange?.('Uploading link thumbnail...')
|
opts.onStateChange?.('Uploading link thumbnail...')
|
||||||
|
@ -190,6 +194,7 @@ export async function post(store: RootStoreModel, opts: PostOpts) {
|
||||||
} as AppBskyEmbedExternal.Main
|
} as AppBskyEmbedExternal.Main
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (opts.replyTo) {
|
if (opts.replyTo) {
|
||||||
const replyToUrip = new AtUri(opts.replyTo)
|
const replyToUrip = new AtUri(opts.replyTo)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import * as apilib from 'lib/api/index'
|
||||||
import {LikelyType, LinkMeta} from './link-meta'
|
import {LikelyType, LinkMeta} from './link-meta'
|
||||||
// import {match as matchRoute} from 'view/routes'
|
// import {match as matchRoute} from 'view/routes'
|
||||||
import {convertBskyAppUrlIfNeeded, makeRecordUri} from '../strings/url-helpers'
|
import {convertBskyAppUrlIfNeeded, makeRecordUri} from '../strings/url-helpers'
|
||||||
|
@ -128,3 +129,29 @@ export async function getPostAsQuote(
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getFeedAsEmbed(
|
||||||
|
store: RootStoreModel,
|
||||||
|
url: string,
|
||||||
|
): Promise<apilib.ExternalEmbedDraft> {
|
||||||
|
url = convertBskyAppUrlIfNeeded(url)
|
||||||
|
const [_0, user, _1, rkey] = url.split('/').filter(Boolean)
|
||||||
|
const feed = makeRecordUri(user, 'app.bsky.feed.generator', rkey)
|
||||||
|
const res = await store.agent.app.bsky.feed.getFeedGenerator({feed})
|
||||||
|
return {
|
||||||
|
isLoading: false,
|
||||||
|
uri: feed,
|
||||||
|
meta: {
|
||||||
|
url: feed,
|
||||||
|
likelyType: LikelyType.AtpData,
|
||||||
|
title: res.data.view.displayName,
|
||||||
|
},
|
||||||
|
embed: {
|
||||||
|
$type: 'app.bsky.embed.record',
|
||||||
|
record: {
|
||||||
|
uri: res.data.view.uri,
|
||||||
|
cid: res.data.view.cid,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -82,6 +82,18 @@ export function isBskyPostUrl(url: string): boolean {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isBskyCustomFeedUrl(url: string): boolean {
|
||||||
|
if (isBskyAppUrl(url)) {
|
||||||
|
try {
|
||||||
|
const urlp = new URL(url)
|
||||||
|
return /profile\/(?<name>[^/]+)\/feed\/(?<rkey>[^/]+)/i.test(
|
||||||
|
urlp.pathname,
|
||||||
|
)
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
export function convertBskyAppUrlIfNeeded(url: string): string {
|
export function convertBskyAppUrlIfNeeded(url: string): string {
|
||||||
if (isBskyAppUrl(url)) {
|
if (isBskyAppUrl(url)) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -2,9 +2,9 @@ import {useState, useEffect} from 'react'
|
||||||
import {useStores} from 'state/index'
|
import {useStores} from 'state/index'
|
||||||
import * as apilib from 'lib/api/index'
|
import * as apilib from 'lib/api/index'
|
||||||
import {getLinkMeta} from 'lib/link-meta/link-meta'
|
import {getLinkMeta} from 'lib/link-meta/link-meta'
|
||||||
import {getPostAsQuote} from 'lib/link-meta/bsky'
|
import {getPostAsQuote, getFeedAsEmbed} from 'lib/link-meta/bsky'
|
||||||
import {downloadAndResize} from 'lib/media/manip'
|
import {downloadAndResize} from 'lib/media/manip'
|
||||||
import {isBskyPostUrl} from 'lib/strings/url-helpers'
|
import {isBskyPostUrl, isBskyCustomFeedUrl} from 'lib/strings/url-helpers'
|
||||||
import {ComposerOpts} from 'state/models/ui/shell'
|
import {ComposerOpts} from 'state/models/ui/shell'
|
||||||
import {POST_IMG_MAX} from 'lib/constants'
|
import {POST_IMG_MAX} from 'lib/constants'
|
||||||
|
|
||||||
|
@ -41,6 +41,24 @@ export function useExternalLinkFetch({
|
||||||
setExtLink(undefined)
|
setExtLink(undefined)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
} else if (isBskyCustomFeedUrl(extLink.uri)) {
|
||||||
|
getFeedAsEmbed(store, extLink.uri).then(
|
||||||
|
({embed, meta}) => {
|
||||||
|
if (aborted) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setExtLink({
|
||||||
|
uri: extLink.uri,
|
||||||
|
isLoading: false,
|
||||||
|
meta,
|
||||||
|
embed,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
err => {
|
||||||
|
store.log.error('Failed to fetch feed for embedding', {err})
|
||||||
|
setExtLink(undefined)
|
||||||
|
},
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
getLinkMeta(store, extLink.uri).then(meta => {
|
getLinkMeta(store, extLink.uri).then(meta => {
|
||||||
if (aborted) {
|
if (aborted) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import React, {useMemo, useRef} from 'react'
|
import React, {useMemo, useRef} from 'react'
|
||||||
import {NativeStackScreenProps} from '@react-navigation/native-stack'
|
import {NativeStackScreenProps} from '@react-navigation/native-stack'
|
||||||
|
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||||
import {usePalette} from 'lib/hooks/usePalette'
|
import {usePalette} from 'lib/hooks/usePalette'
|
||||||
import {HeartIcon, HeartIconSolid} from 'lib/icons'
|
import {HeartIcon, HeartIconSolid} from 'lib/icons'
|
||||||
import {CommonNavigatorParams} from 'lib/routes/types'
|
import {CommonNavigatorParams} from 'lib/routes/types'
|
||||||
|
@ -21,6 +22,8 @@ import {Text} from 'view/com/util/text/Text'
|
||||||
import * as Toast from 'view/com/util/Toast'
|
import * as Toast from 'view/com/util/Toast'
|
||||||
import {isDesktopWeb} from 'platform/detection'
|
import {isDesktopWeb} from 'platform/detection'
|
||||||
import {useSetTitle} from 'lib/hooks/useSetTitle'
|
import {useSetTitle} from 'lib/hooks/useSetTitle'
|
||||||
|
import {shareUrl} from 'lib/sharing'
|
||||||
|
import {toShareUrl} from 'lib/strings/url-helpers'
|
||||||
|
|
||||||
type Props = NativeStackScreenProps<CommonNavigatorParams, 'CustomFeed'>
|
type Props = NativeStackScreenProps<CommonNavigatorParams, 'CustomFeed'>
|
||||||
export const CustomFeedScreen = withAuthRequired(
|
export const CustomFeedScreen = withAuthRequired(
|
||||||
|
@ -73,10 +76,22 @@ export const CustomFeedScreen = withAuthRequired(
|
||||||
store.log.error('Failed up toggle like', {err})
|
store.log.error('Failed up toggle like', {err})
|
||||||
}
|
}
|
||||||
}, [store, currentFeed])
|
}, [store, currentFeed])
|
||||||
|
const onPressShare = React.useCallback(() => {
|
||||||
|
const url = toShareUrl(`/profile/${name}/feed/${rkey}`)
|
||||||
|
shareUrl(url)
|
||||||
|
}, [name, rkey])
|
||||||
|
|
||||||
const renderHeaderBtns = React.useCallback(() => {
|
const renderHeaderBtns = React.useCallback(() => {
|
||||||
return (
|
return (
|
||||||
<View style={styles.headerBtns}>
|
<View style={styles.headerBtns}>
|
||||||
|
<Button
|
||||||
|
testID="shareBtn"
|
||||||
|
type="default"
|
||||||
|
accessibilityLabel="Share this feed"
|
||||||
|
accessibilityHint=""
|
||||||
|
onPress={onPressShare}>
|
||||||
|
<FontAwesomeIcon icon="share" size={18} color={pal.colors.icon} />
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
type="default"
|
type="default"
|
||||||
testID="toggleLikeBtn"
|
testID="toggleLikeBtn"
|
||||||
|
@ -108,6 +123,7 @@ export const CustomFeedScreen = withAuthRequired(
|
||||||
currentFeed?.isLiked,
|
currentFeed?.isLiked,
|
||||||
onToggleSaved,
|
onToggleSaved,
|
||||||
onToggleLiked,
|
onToggleLiked,
|
||||||
|
onPressShare,
|
||||||
])
|
])
|
||||||
|
|
||||||
const renderListHeaderComponent = React.useCallback(() => {
|
const renderListHeaderComponent = React.useCallback(() => {
|
||||||
|
@ -151,14 +167,28 @@ export const CustomFeedScreen = withAuthRequired(
|
||||||
: 'Add to My Feeds'
|
: 'Add to My Feeds'
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
<Button
|
||||||
<Button type="default" onPress={onToggleLiked}>
|
type="default"
|
||||||
|
accessibilityLabel="Like this feed"
|
||||||
|
accessibilityHint=""
|
||||||
|
onPress={onToggleLiked}>
|
||||||
{currentFeed?.isLiked ? (
|
{currentFeed?.isLiked ? (
|
||||||
<HeartIconSolid size={18} style={styles.liked} />
|
<HeartIconSolid size={18} style={styles.liked} />
|
||||||
) : (
|
) : (
|
||||||
<HeartIcon strokeWidth={3} size={18} style={pal.icon} />
|
<HeartIcon strokeWidth={3} size={18} style={pal.icon} />
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="default"
|
||||||
|
accessibilityLabel="Share this feed"
|
||||||
|
accessibilityHint=""
|
||||||
|
onPress={onPressShare}>
|
||||||
|
<FontAwesomeIcon
|
||||||
|
icon="share"
|
||||||
|
size={18}
|
||||||
|
color={pal.colors.icon}
|
||||||
|
/>
|
||||||
|
</Button>
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
|
@ -202,6 +232,7 @@ export const CustomFeedScreen = withAuthRequired(
|
||||||
currentFeed,
|
currentFeed,
|
||||||
onToggleLiked,
|
onToggleLiked,
|
||||||
onToggleSaved,
|
onToggleSaved,
|
||||||
|
onPressShare,
|
||||||
name,
|
name,
|
||||||
rkey,
|
rkey,
|
||||||
])
|
])
|
||||||
|
|
Loading…
Reference in New Issue