diff --git a/src/components/messageStream/bubbles/VideoBubble.tsx b/src/components/messageStream/bubbles/VideoBubble.tsx index 314eb60..a683a1b 100644 --- a/src/components/messageStream/bubbles/VideoBubble.tsx +++ b/src/components/messageStream/bubbles/VideoBubble.tsx @@ -1,12 +1,14 @@ import { Play } from "lucide-react"; import { useRef, useState } from "react"; import { useI18n } from "../../../i18n"; -import type { Post } from "../../../types/post"; -import { useVideoPlayer } from "../overlays/VideoPlayer"; +import type { Attachment, Post } from "../../../types/post"; import { AttachmentDownloadPill } from "../AttachmentDownloadPill"; +import { useVideoPlayer } from "../overlays/VideoPlayer"; import { autolink } from "../utils/autolink"; import { postDisplayText } from "../utils/postText"; +const MAX_VISIBLE = 4; + function formatDuration(sec: number | undefined): string { if (!sec || sec <= 0) return ""; const m = Math.floor(sec / 60); @@ -14,81 +16,171 @@ function formatDuration(sec: number | undefined): string { return `${m}:${s.toString().padStart(2, "0")}`; } -export function VideoBubble({ post }: { post: Post }) { +function isVideoAttachment(att: Attachment): boolean { + return att.kind === "video" || att.mime.startsWith("video/"); +} + +function videoRatio(att: Attachment) { + return att.width && att.height ? `${att.width} / ${att.height}` : "16 / 9"; +} + +function VideoAttachmentCard({ + postId, + attachment, + compact = false, + overlayCount, +}: { + postId: string; + attachment: Attachment; + compact?: boolean; + overlayCount?: number; +}) { const { openVideo } = useVideoPlayer(); - const { lang } = useI18n(); - const att = post.attachments[0]; const [playing, setPlaying] = useState(false); const videoRef = useRef(null); - const text = postDisplayText(post, lang); - if (!att) return null; - const ratio = - att.width && att.height ? `${att.width} / ${att.height}` : "16 / 9"; - const posterUrl = att.posterUrl ?? att.thumbnailUrl; - const duration = formatDuration(att.durationSec); - const previewVideoUrl = att.url.includes("#") ? att.url : `${att.url}#t=0.1`; + const posterUrl = attachment.posterUrl ?? attachment.thumbnailUrl; + const duration = formatDuration(attachment.durationSec); + const previewVideoUrl = attachment.url.includes("#") + ? attachment.url + : `${attachment.url}#t=0.1`; return ( -
-
{ - if (playing) { - const v = videoRef.current; - openVideo(att, v?.currentTime ?? 0); - } - }} - > - {playing ? ( -