Merge pull request #188 from trash-pandy/sable/feat/more-preview-media-types

Add support for audio and video previews in URL previews and reuse attachment components
This commit is contained in:
7w1 authored and GitHub committed 2026-03-06 12:42:28 -06:00
commit 1e1a5ea8fb
4 files changed
+56 -20

No files matched your search

@@ -0,0 +1,5 @@
---
sable: minor
---
Add support for audio and video in URL previews if homeserver provides it.
@@ -6,13 +6,10 @@ export const UrlPreview = as<'div'>(({ className, ...props }, ref) => (
<Box shrink="No" className={classNames(css.UrlPreview, className)} {...props} ref={ref} />
));
export const UrlPreviewImg = as<'img'>(({ className, alt, ...props }, ref) => (
<img className={classNames(css.UrlPreviewImg, className)} alt={alt} {...props} ref={ref} />
));
export const UrlPreviewContent = as<'div'>(({ className, ...props }, ref) => (
<Box
grow="Yes"
shrink="No"
direction="Column"
gap="100"
className={classNames(css.UrlPreviewContent, className)}
@@ -1,5 +1,14 @@
import { style } from '@vanilla-extract/css';
import { recipe } from '@vanilla-extract/recipes';
import { DefaultReset, color, toRem } from 'folds';
import { DefaultReset, color, config, toRem } from 'folds';
export const UrlPreviewAudio = style([
DefaultReset,
{
padding: config.space.S300,
paddingTop: 0,
},
]);
export const UrlPreviewHolderGradient = recipe({
base: [
@@ -10,7 +10,10 @@ import {
import { mxcUrlToHttp } from '$utils/matrix';
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
import * as css from './UrlPreviewCard.css';
import { UrlPreview, UrlPreviewContent, UrlPreviewDescription, UrlPreviewImg } from './UrlPreview';
import { UrlPreview, UrlPreviewContent, UrlPreviewDescription } from './UrlPreview';
import { AudioContent, ImageContent, VideoContent } from '../message';
import { Image, MediaControl, Video } from '../media';
import { ImageViewer } from '../image-viewer';
const linkStyles = { color: color.Success.Main };
@@ -49,22 +52,44 @@ export const UrlPreviewCard = as<'div', { url: string; ts: number; mediaType?: s
);
return (
<>
{imgUrl && (
<UrlPreviewImg
src={imgUrl}
alt="Media"
<Box grow="Yes" direction="ColumnReverse" gap="0">
{(prev['og:video'] && (
<VideoContent
style={{
width: 'auto',
height: 'auto',
maxWidth: '100%',
maxHeight: '100px',
borderRadius: '8px',
objectFit: 'contain',
display: 'block',
aspectRatio:
((prev['og:video:width'] as number) ?? 1) /
((prev['og:video:height'] as number) ?? 1),
}}
body={prev['og:title']}
info={{}}
url={prev['og:video'] as string}
mimeType={(prev['og:video:type'] as string) ?? ''}
renderVideo={(vidProps) => <Video style={{ objectFit: 'contain' }} {...vidProps} />}
renderThumbnail={() => <Image src={imgUrl ?? undefined} />}
/>
)}
)) ||
(prev['og:image'] && (
<ImageContent
style={{
aspectRatio: (prev['og:image:width'] ?? 1) / (prev['og:image:height'] ?? 1),
}}
autoPlay
body={prev['og:title']}
url={prev['og:image']}
renderViewer={(p) => <ImageViewer {...p} />}
renderImage={(p) => <Image style={{ objectFit: 'contain' }} {...p} />}
/>
)) ||
(prev['og:audio'] && (
<Box className={css.UrlPreviewAudio}>
<AudioContent
url={(prev['og:audio'] as string) ?? ''}
mimeType={(prev['og:audio:type'] as string) ?? ''}
info={{}}
renderMediaControl={(p) => <MediaControl {...p} />}
/>
</Box>
))}
<UrlPreviewContent>
<Text
style={linkStyles}
@@ -90,7 +115,7 @@ export const UrlPreviewCard = as<'div', { url: string; ts: number; mediaType?: s
</Text>
)}
</UrlPreviewContent>
</>
</Box>
);
};