mirror of
https://github.com/block/buzz.git
synced 2026-11-24 18:21:59 +00:00
Follow-up to [#9356 gallery video selection](https://github.com/block/buzz/pull/9356), merged as [ef57fec4d](ef57fec4d2). It makes two changes that came out of review. ### 1. Remove automatic stills for videos without poster metadata #9356 generated a still for every rendered video bubble or stack card that had no NIP-71 poster. To do that it downloaded the **whole video** (up to the 100 MB limit), grabbed a frame and threw the file away. Desktop (buzz-app) never writes `image`/`thumb` on video attachments, so this covered every desktop-sent video, not only old mobile messages. Before #9356 those bubbles were a static placeholder that used no network. The cost on a real timeline: - A four-card stack could pull up to about 400 MB just for stills, before anyone pressed play. - When the user did open a video, playback started its own separate download of the same file, and the poster download kept competing for bandwidth. - A failed, cancelled or stalled download saved nothing, so every remount (scroll back, swipe back in a stack) started the full GET again. Cached stills from non-relay URLs were also dropped and fetched again after the cache's seven-day expiry. This PR deletes that path: `video_poster.dart` and its test, plus the watchers and `generatedPoster` branches in `video_preview.dart` and `media_stack.dart`. Posterless videos are back to base behavior: "Video attachment" in a bubble, the plain surface on a stack card, and the source snapshot in the native viewer. The rest of #9356 stays: queued local stills (`prepareVideoPoster` on the local file, no network), the remote-poster preview in the native viewer, the picker changes and swipe dismissal. `NativeVideoFiles._cancelTimeouts` was added for poster disposal. No remaining test depends on it, so it goes back to base too. If stills for desktop-sent videos are still wanted, a bounded follow-up is to generate and cache the still from the file that playback already downloaded, after the user opens it. That adds no network. ### 2. Route `.3gpp` and `.3g2` picks as videos The Video row is gone from the attachment menu, so `_isPickedVideo` is now the only thing that classifies path-only picker results. Its extension list missed `3gpp` and `3g2`. The recent-media grid returns the original library file, and PHPicker exports 3GPP2 as `.3g2`, so those videos were queued as images and then rejected by `uploadImage`. Before #9356, the explicit Video action uploaded them through `uploadVideo`, which transcodes to MP4. ### Pareto The change only removes work: no extra network or decoding for posterless videos, and no change for videos that carry a poster. The one thing we give up is the still on posterless videos that #9356 added and base never had. ### Validation - Added test rows: `clip.3gpp` and `clip.3g2` in the existing mixed-gallery composer journey. Both now queue as video. - Full mobile `flutter test` passes on [518af3a0d](518af3a0d2): 4,688 passed, 71 skipped. `flutter analyze` is clean. - I didn't run an app journey for this fix. It brings the posterless paths back to base code, and #9356's own validation covers the rest. Review report: `buzz://message?channel=e71f9a2a-ac46-473d-a24e-5e16fd8cb7b1&id=bcae52d59c255add1a927e0135441a1c58115b6aa6cda8d9ff7e58d47a627a87` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Tom Brow <tomb@squareup.com> Co-authored-by: Tom Brow <tomb@squareup.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
145 lines
4.9 KiB
Dart
145 lines
4.9 KiB
Dart
part of '../message_content.dart';
|
|
|
|
/// A video bubble. It shows the NIP-71 poster when the event has one;
|
|
/// otherwise a static placeholder, so scrolling never starts a video decoder.
|
|
class _MessageVideoPreview extends HookConsumerWidget {
|
|
final String url;
|
|
final ImetaEntry? imeta;
|
|
final VoidCallback? onReply;
|
|
|
|
const _MessageVideoPreview({
|
|
required this.url,
|
|
required this.imeta,
|
|
required this.onReply,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final sourceKey = useMemoized(GlobalKey.new);
|
|
final opening = useRef(false);
|
|
final aspectRatio = messageVideoAspectRatio(imeta?.aspectRatio);
|
|
final posterUrl = imeta?.posterUrl;
|
|
|
|
return Padding(
|
|
padding: const EdgeInsets.only(top: Grid.half),
|
|
child: GestureDetector(
|
|
onTap: () async {
|
|
if (opening.value) return;
|
|
opening.value = true;
|
|
NativeVideoFiles? files;
|
|
try {
|
|
if (NativePhotoZoomPreview.enabled) {
|
|
await WidgetsBinding.instance.endOfFrame;
|
|
if (!context.mounted) return;
|
|
final auth = ref.read(mediaGetAuthServiceProvider);
|
|
final client = ref.read(mediaHttpClientProvider);
|
|
files = NativeVideoFiles(auth: auth, client: client, index: 0);
|
|
final fallback = await NativePhotoZoomPreview.open(
|
|
context: context,
|
|
sourceKeys: [sourceKey],
|
|
previewProviders: [
|
|
if (posterUrl != null)
|
|
MediaImageProvider(
|
|
url: posterUrl,
|
|
auth: auth,
|
|
client: client,
|
|
)
|
|
else
|
|
null,
|
|
],
|
|
providers: [
|
|
MediaImageProvider(
|
|
url: posterUrl ?? url,
|
|
auth: auth,
|
|
client: client,
|
|
),
|
|
],
|
|
urls: [url],
|
|
labels: [imeta?.alt ?? 'Video'],
|
|
initialIndex: 0,
|
|
videoIndices: {0},
|
|
loadVideo: (_) => files!.load(0, url),
|
|
onSelect: (_) async {},
|
|
onReply: onReply,
|
|
);
|
|
if (!fallback || !context.mounted) return;
|
|
}
|
|
openVideoViewer(
|
|
context,
|
|
videoUrl: url,
|
|
posterUrl: posterUrl,
|
|
onReply: onReply,
|
|
);
|
|
} finally {
|
|
await files?.dispose();
|
|
opening.value = false;
|
|
}
|
|
},
|
|
child: RepaintBoundary(
|
|
key: sourceKey,
|
|
child: _MessageMediaPreviewFrame(
|
|
previewKey: ValueKey('message-media-video-preview:$url'),
|
|
backgroundColor: Colors.black,
|
|
child: AspectRatio(
|
|
aspectRatio: aspectRatio.toDouble(),
|
|
child: Stack(
|
|
fit: StackFit.expand,
|
|
children: [
|
|
if (posterUrl != null)
|
|
MediaImage(
|
|
url: posterUrl,
|
|
fit: BoxFit.cover,
|
|
frameBuilder: (context, child, frame, synchronous) =>
|
|
frame != null || synchronous
|
|
? child
|
|
: const MediaLoadingPlaceholder(
|
|
label: 'Loading video',
|
|
),
|
|
errorBuilder: (_, _, _) => const _MediaPreviewFallback(
|
|
icon: BuzzIcons.video,
|
|
label: 'Video preview unavailable',
|
|
),
|
|
)
|
|
else
|
|
const _MediaPreviewFallback(
|
|
icon: BuzzIcons.video,
|
|
label: 'Video attachment',
|
|
),
|
|
const ColoredBox(color: Color.fromRGBO(0, 0, 0, 0.28)),
|
|
Center(
|
|
child: Container(
|
|
width: 52,
|
|
height: 52,
|
|
decoration: const BoxDecoration(
|
|
color: Color.fromRGBO(0, 0, 0, 0.6),
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: const Icon(
|
|
BuzzIcons.play,
|
|
color: Colors.white,
|
|
size: 24,
|
|
),
|
|
),
|
|
),
|
|
Positioned(
|
|
left: Grid.xxs,
|
|
right: Grid.xxs,
|
|
bottom: Grid.xxs,
|
|
child: Text(
|
|
'Video',
|
|
style: context.textTheme.labelSmall?.copyWith(
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|