Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make video posts which are quote posts show up in video feeds #7534

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/VideoPostCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react'

import {getVideoEmbed} from '#/lib/embeds'
import {sanitizeHandle} from '#/lib/strings/handles'
import {formatCount} from '#/view/com/util/numeric/format'
import {UserAvatar} from '#/view/com/util/UserAvatar'
Expand Down Expand Up @@ -52,7 +53,7 @@ export function VideoPostCard({
}) {
const t = useTheme()
const {_, i18n} = useLingui()
const embed = post.embed
const embed = getVideoEmbed(post.embed)
const {
state: pressed,
onIn: onPressIn,
Expand Down
4 changes: 2 additions & 2 deletions src/components/feeds/PostFeedVideoGridRow.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {View} from 'react-native'
import {AppBskyEmbedVideo} from '@atproto/api'

import {isVideoView} from '#/lib/embeds'
import {logEvent} from '#/lib/statsig/statsig'
import {FeedPostSliceItem} from '#/state/queries/post-feed'
import {VideoFeedSourceContext} from '#/screens/VideoFeed/types'
Expand All @@ -20,7 +20,7 @@ export function PostFeedVideoGridRow({
}) {
const gutters = useGutters(['base', 'base', 0, 'base'])
const posts = slices
.filter(slice => AppBskyEmbedVideo.isView(slice.post.embed))
.filter(slice => isVideoView(slice.post.embed))
.map(slice => ({
post: slice.post,
moderation: slice.moderation,
Expand Down
25 changes: 25 additions & 0 deletions src/lib/embeds.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
AppBskyEmbedRecord,
AppBskyEmbedRecordWithMedia,
AppBskyEmbedVideo,
AppBskyFeedDefs,
} from '@atproto/api'

Expand All @@ -22,3 +23,27 @@ export function isEmbedByEmbedder(
}
return true
}

export function isVideoView(
v: unknown,
): v is
| AppBskyEmbedVideo.View
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type refinement feels like it should convince ts that the returned value can only be one of these two types of view but judging by my lsp it didn’t seem to work in practice.

| (AppBskyEmbedRecordWithMedia.View & {media: AppBskyEmbedVideo.View}) {
return (
AppBskyEmbedVideo.isView(v) ||
(AppBskyEmbedRecordWithMedia.isView(v) && AppBskyEmbedVideo.isView(v.media))
)
}

export function getVideoEmbed(v: unknown): AppBskyEmbedVideo.View | null {
if (AppBskyEmbedVideo.isView(v)) {
return v
}
if (
AppBskyEmbedRecordWithMedia.isView(v) &&
AppBskyEmbedVideo.isView(v.media)
) {
return v.media
}
return null
}
20 changes: 12 additions & 8 deletions src/screens/VideoFeed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
import {NativeStackScreenProps} from '@react-navigation/native-stack'

import {HITSLOP_20} from '#/lib/constants'
import {getVideoEmbed, isVideoView} from '#/lib/embeds'
import {useHaptics} from '#/lib/haptics'
import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback'
import {CommonNavigatorParams, NavigationProp} from '#/lib/routes/types'
Expand Down Expand Up @@ -210,14 +211,17 @@ function Feed() {
const feedPost = slice.items.find(
item => item.uri === slice.feedPostUri,
)
if (feedPost && AppBskyEmbedVideo.isView(feedPost.post.embed)) {
items.push({
_reactKey: feedPost._reactKey,
moderation: feedPost.moderation,
post: feedPost.post,
video: feedPost.post.embed,
feedContext: slice.feedContext,
})
if (feedPost && isVideoView(feedPost.post.embed)) {
const video = getVideoEmbed(feedPost.post.embed)
if (video) {
items.push({
_reactKey: feedPost._reactKey,
moderation: feedPost.moderation,
post: feedPost.post,
video: video,
feedContext: slice.feedContext,
})
}
}
}
return items
Expand Down
5 changes: 3 additions & 2 deletions src/view/com/posts/PostFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import {
View,
ViewStyle,
} from 'react-native'
import {AppBskyActorDefs, AppBskyEmbedVideo} from '@atproto/api'
import {AppBskyActorDefs} from '@atproto/api'
import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react'
import {useQueryClient} from '@tanstack/react-query'

import {DISCOVER_FEED_URI, KNOWN_SHUTDOWN_FEEDS} from '#/lib/constants'
import {isVideoView} from '#/lib/embeds'
import {useInitialNumToRender} from '#/lib/hooks/useInitialNumToRender'
import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
import {logEvent} from '#/lib/statsig/statsig'
Expand Down Expand Up @@ -350,7 +351,7 @@ let PostFeed = ({
const item = slice.items.find(
item => item.uri === slice.feedPostUri,
)
if (item && AppBskyEmbedVideo.isView(item.post.embed)) {
if (item && isVideoView(item.post.embed)) {
videos.push({item, feedContext: slice.feedContext})
}
}
Expand Down