Skip to content
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
1 change: 1 addition & 0 deletions apps/docs/content/docs/guides/workspaces.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ If you post on behalf of clients, they can approve each post before it goes out.
<Step title="Wait for the decision.">
The post shows **Awaiting client approval**. The client gets a notification, reviews the exact
version you sent, and chooses **Approve this version** or **Request changes** with feedback.
They can press **Play video** in the preview to watch a video with sound.
</Step>
<Step title="Schedule or publish.">
Once it shows **Client approved**, schedule or publish it. Approval alone never publishes
Expand Down
3 changes: 3 additions & 0 deletions apps/web/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8275,6 +8275,9 @@
"review_submitted_version": "View submitted version",
"review_timing_later": "Publishing time will be chosen later.",
"review_title": "Client review",
"review_video_error": "This video could not be played.",
"review_video_pause": "Pause",
"review_video_play": "Play video",
"notifications_event_post_review": "Post reviews",
"series_title": "Create a series",
"series_description": "Choose and edit distinct concepts before generating posts. Thin sources may produce fewer concepts.",
Expand Down
15 changes: 12 additions & 3 deletions apps/web/src/lib/components/composer-preview.svelte
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
<script lang="ts">
import type { PreviewModel, PreviewEditing } from '@openpost/social-preview';
import type {
PreviewModel,
PreviewEditing,
PreviewVideoPlayback
} from '@openpost/social-preview';

import { m } from '#lib/paraglide/messages.js';

let { model, editor }: { model: PreviewModel; editor?: PreviewEditing } = $props();
let {
model,
editor,
playableVideo
}: { model: PreviewModel; editor?: PreviewEditing; playableVideo?: PreviewVideoPlayback } =
$props();
</script>

<section class="min-w-0" aria-label={m.compose_preview()} data-testid="composer-account-preview">
{#await import('@openpost/social-preview')}
<p class="py-8 text-center text-sm text-muted-foreground" role="status">{m.common_loading()}</p>
{:then module}
<module.SocialPreview {model} {editor} />
<module.SocialPreview {model} {editor} {playableVideo} />
{:catch}
<p class="text-sm text-muted-foreground" role="status">{m.preview_load_failed()}</p>
{/await}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<script lang="ts">
import type { ComponentProps } from 'svelte';
import * as Dialog from '#lib/components/ui/dialog/index.ts';
import PublicationReviewPreview from './publication-review-preview.svelte';

let {
open = $bindable(true),
...props
}: { open?: boolean } & ComponentProps<typeof PublicationReviewPreview> = $props();
</script>

<Dialog.Root bind:open>
<Dialog.Content>
<Dialog.Header>
<Dialog.Title>Client review</Dialog.Title>
<Dialog.Description>Review</Dialog.Description>
</Dialog.Header>
<PublicationReviewPreview {...props} />
</Dialog.Content>
</Dialog.Root>
7 changes: 7 additions & 0 deletions apps/web/src/lib/components/publication-review-preview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
}: { publication: components['schemas']['PublicationResponse']; accounts: SocialAccount[] } =
$props();

// Reviewers judge motion and sound, so review previews play videos on request.
const playableVideo = $derived({
playLabel: m.review_video_play(),
pauseLabel: m.review_video_pause(),
errorLabel: m.review_video_error()
});
const scalarSchema = z.union([z.string(), z.number(), z.boolean()]);
const jsonSchema = z.json();
const catalog = createQuery(() => capabilityCatalogQueryOptions(queryAPI));
Expand Down Expand Up @@ -98,6 +104,7 @@
</p>
{#if account}
<ComposerPreview
{playableVideo}
model={buildComposerPreview({
account,
mode: (rendition.segments?.length ?? 0) > 1 ? 'thread' : 'post',
Expand Down
254 changes: 254 additions & 0 deletions apps/web/src/lib/components/publication-review-preview.svelte.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { render } from 'vitest-browser-svelte';
import { QueryClientProvider } from '@tanstack/svelte-query';
import { openPostQueryKeys } from '@openpost/query-catalog';
import type { SocialAccount } from '#lib/api/client.ts';
import type { components } from '#lib/api/types.js';
import { m } from '#lib/paraglide/messages.js';
import { queryClient } from '#lib/query/client.ts';
import PublicationReviewPreview from './publication-review-preview.svelte';
import PublicationReviewPreviewDialog from './publication-review-preview.fixture.svelte';

type Publication = components['schemas']['PublicationResponse'];

const account: SocialAccount = {
id: 'account-1',
slug: 'openpost',
platform: 'x',
account_id: 'provider-1',
account_username: 'openpost',
account_avatar_url: '',
instance_url: '',
is_active: true,
grant_destination_count: 1,
shared_grant: false,
messaging_supported: false,
messages_enabled: false,
thread_replies_supported: true
};

type Media = components['schemas']['MediaSummary'];

function media(id: string, mimeType: string): Media {
return {
id,
mime_type: mimeType,
alt_text: `Media ${id}`,
width: 1920,
height: 1080,
analysis_status: 'ready',
aspect_ratio: '16:9',
dominant_type: mimeType.split('/')[0],
duration_ms: 12000,
frame_rate: 24,
original_filename: `${id}.bin`,
public_url_ready: false,
public_url_status: 0,
size: 1024,
url: `/media/${id}`
};
}

function snapshot(items: Media[]): Publication {
return {
content_profile: '',
created_at: '2026-11-30T09:00:00Z',
created_by: 'user-1',
creation_preset: '',
creation_source: 'web',
id: 'publication-1',
intent: 'single',
media: [],
metadata: {},
random_delay_inherited: false,
random_delay_minutes: 0,
repost_override: { mode: 'inherit' },
revision: 1,
segments: [],
source_text: 'Launch day',
status: 'draft',
title: 'Launch',
updated_at: '2026-11-30T09:00:00Z',
workspace_id: 'workspace-1',
scheduled_at: '2026-12-01T09:00:00Z',
renditions: [
{
id: 'rendition-1',
publication_id: 'publication-1',
platform: 'x',
output_profile: 'x.post',
profile: '',
social_account_id: account.id,
target_key: account.id,
status: 'draft',
format_locked: false,
error_retryable: false,
body: 'Launch day',
title: '',
description: '',
settings: {},
media: [],
segments: [
{
id: 'segment-1',
publication_segment_id: 'source-segment-1',
position: 0,
status: 'draft',
error_retryable: false,
body: 'Launch day',
title: '',
description: '',
settings: {},
media_inherited: false,
media: items,
output_media: items
}
]
}
]
};
}

// Chromium for arm64 cannot decode H.264, and decoding is not under test: model
// the media element rules the review dialog depends on (paused flips inside
// play(), play and pause events arrive later, pause() rejects a pending play()
// with AbortError, a failed source stays failed until load()) and record what
// the dialog asks of it.
interface Fake {
paused: boolean;
error: object | null;
played: number;
pending: { resolve: () => void; reject: (reason: DOMException) => void } | null;
}
const fakes = new WeakMap<HTMLMediaElement, Fake>();
const fake = (element: HTMLMediaElement) => {
let state = fakes.get(element);
if (!state) {
state = { paused: true, error: null, played: 0, pending: null };
fakes.set(element, state);
}
return state;
};
const played: HTMLMediaElement[] = [];
const stopped: HTMLMediaElement[] = [];
const fireLater = (element: Element, type: string) =>
queueMicrotask(() => element.dispatchEvent(new Event(type)));

beforeEach(() => {
played.length = 0;
stopped.length = 0;
queryClient.clear();
queryClient.setQueryData(openPostQueryKeys.capabilities(), { capabilities: [] });
vi.spyOn(HTMLMediaElement.prototype, 'play').mockImplementation(
function (this: HTMLMediaElement) {
played.push(this);
const state = fake(this);
state.paused = false;
fireLater(this, 'play');
return new Promise<void>((resolve, reject) => {
state.pending = { resolve, reject };
queueMicrotask(() => {
if (state.pending?.resolve !== resolve) return;
state.pending = null;
state.played = 1;
resolve();
});
});
}
);
vi.spyOn(HTMLMediaElement.prototype, 'pause').mockImplementation(
function (this: HTMLMediaElement) {
stopped.push(this);
const state = fake(this);
if (state.paused) return;
state.paused = true;
state.pending?.reject(new DOMException('Interrupted by pause().', 'AbortError'));
state.pending = null;
fireLater(this, 'pause');
}
);
vi.spyOn(HTMLMediaElement.prototype, 'load').mockImplementation(
function (this: HTMLMediaElement) {
Object.assign(fake(this), { paused: true, error: null, played: 0, pending: null });
}
);
vi.spyOn(HTMLMediaElement.prototype, 'paused', 'get').mockImplementation(
function (this: HTMLMediaElement) {
return fake(this).paused;
}
);
vi.spyOn(HTMLMediaElement.prototype, 'error', 'get').mockImplementation(
function (this: HTMLMediaElement) {
// SAFETY: only the truthiness of `video.error` is read by the code under test.
return fake(this).error as MediaError | null;
}
);
vi.spyOn(HTMLMediaElement.prototype, 'played', 'get').mockImplementation(
function (this: HTMLMediaElement) {
const count = fake(this).played;
// SAFETY: only `length` is read by the code under test.
return { length: count } as TimeRanges;
}
);
});

afterEach(() => vi.restoreAllMocks());

const wrapperOptions = { wrapper: QueryClientProvider, wrapperProps: { client: queryClient } };

function mount(publication: Publication) {
return render(PublicationReviewPreview, { publication, accounts: [account] }, wrapperOptions);
}

function mountInDialog(publication: Publication) {
return render(
PublicationReviewPreviewDialog,
{ publication, accounts: [account] },
wrapperOptions
);
}

describe('review preview video playback', () => {
it('lets a reviewer play and pause a video with the localized labels', async () => {
const screen = await mount(snapshot([media('clip', 'video/mp4')]));
const play = screen.getByRole('button', { name: m.review_video_play() });
await expect.element(play).toBeVisible();
expect(played).toHaveLength(0);
await play.click();
expect(played).toHaveLength(1);
await screen.getByRole('button', { name: m.review_video_pause() }).click();
await expect.element(screen.getByRole('button', { name: m.review_video_play() })).toBeVisible();
});

it('shows the localized error when the browser refuses to play', async () => {
vi.spyOn(HTMLMediaElement.prototype, 'play').mockRejectedValue(
new DOMException('blocked', 'NotAllowedError')
);
const screen = await mount(snapshot([media('clip', 'video/mp4')]));
await screen.getByRole('button', { name: m.review_video_play() }).click();
await expect.element(screen.getByRole('alert')).toHaveTextContent(m.review_video_error());
});

it('offers no playback control for an image-only post', async () => {
const screen = await mount(snapshot([media('photo', 'image/jpeg')]));
await expect.element(screen.getByRole('img', { name: 'Media photo' })).toBeVisible();
await expect
.element(screen.getByRole('button', { name: m.review_video_play() }))
.not.toBeInTheDocument();
});

it('stops the video when the review dialog closes', async () => {
const screen = await mountInDialog(snapshot([media('clip', 'video/mp4')]));
await screen.getByRole('button', { name: m.review_video_play() }).click();
await expect
.element(screen.getByRole('button', { name: m.review_video_pause() }))
.toBeVisible();
const [video] = played;
await screen.rerender({ open: false });
await expect
.element(screen.getByRole('button', { name: m.review_video_pause() }))
.not.toBeInTheDocument();
expect(stopped).toContain(video);
expect(video.paused).toBe(true);
});
});
3 changes: 3 additions & 0 deletions changes/review-video-playback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Added

- Videos in post previews can be played where a post is reviewed: in the client's review dialog (including "View submitted version"), in the dialog where you send a post for review, and in the preview on the post's page. Each video gets a Play video button that starts it with sound and turns into Pause, so a reviewer can judge motion and audio before approving. Nothing plays until the button is pressed, only one video plays at a time, a video that cannot be played shows a short message and can be retried, and playback stops when the dialog closes, the preview is hidden, or it moves to another slide. The composer and the free tools still show videos as still frames.
1 change: 1 addition & 0 deletions docs/development/social-previews.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Preview support is separate from publishing readiness. Reddit is a preview-only
- Use supplied image dimensions when available and intrinsic dimensions otherwise. Selected feed, carousel, multi-image, Story, Reel, and video profiles take precedence over attachment inference. Project supported covers, cover frames and focal points from effective account settings, and deduplicate joined attachments in source order, retaining the first item metadata. A missing ratio must not permanently force portrait media into a landscape crop.
- Shared capability counts describe verified preview limits. Unspecified limits can vary by instance or client; public tools must label their own input limits and never silently discard uploads.
- Navigation and neighboring content illustrate a platform. Only real preview interactions, such as carousel navigation and content-warning disclosure, should look operable.
- Video playback is opt-in and off by default. A preview shows a still frame with a decorative play icon unless the host passes `playableVideo` to `SocialPreview` with its localized `playLabel`, `pauseLabel` and `errorLabel` (the package has no catalogue; omitted labels fall back to English). Only the publication review preview opts in, so the composer, public tools and marketing render exactly as before. With it on, each video gets a real play/pause button of at least 44px: a pill near the bottom of a single tile, above the caption in Reels, Stories and Shorts, and a centred icon in small grid tiles and carousels. A failed play shows a short alert; small tiles show it below the media so it never covers a control. Nothing plays until the button is pressed, sound is on after the press, one video plays at a time across previews, and playback stops when the preview is destroyed or hidden, or moves to another slide or item. The chosen cover frame still shows first and the first play starts at 0.

The Threads preview limit is 20 mixed images or videos, matching [Meta's published carousel contract](https://www.postman.com/meta/threads/documentation/dht3nzz/threads-api). Unverified limits remain labeled as preview-tool limits, rather than publishing guarantees.

Expand Down
1 change: 1 addition & 0 deletions packages/social-preview/src/CommunityPreview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<PreviewMedia
{media}
layout={platform === "reddit" && media.length > 1 ? "carousel" : "single"}
alertGutter={false}
/>
{/if}

Expand Down
2 changes: 1 addition & 1 deletion packages/social-preview/src/DiscordPreview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
platform="discord"
/>{/if}
{#if media.length > 0}
<PreviewMedia {media} {segment} layout="discord" />
<PreviewMedia {media} {segment} layout="discord" alertGutter={false} />
{:else if index === 0 && model.format === "video"}
<PreviewMedia
media={[]}
Expand Down
1 change: 1 addition & 0 deletions packages/social-preview/src/LinkedInPreview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
media={reply.media}
segment={reply}
layout="grid"
alertGutter={false}
/>{/if}
</div>
<small>Like · Reply · {model.createdAtLabel}</small>
Expand Down
1 change: 1 addition & 0 deletions packages/social-preview/src/MicroPreview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
media={segmentMedia}
{segment}
layout={platform === "threads" ? "carousel" : "grid"}
alertGutter={false}
/>
{/if}
{/if}
Expand Down
Loading