Files
buzz/mobile/lib/features/channels/message_media.dart
feccf4eabc Polish mobile inbox and media flows (#4512)
## Summary

- make mobile unread state visible with bold channel names, an animated
Inbox badge, and swipe-to-toggle Inbox rows
- add directional transitions for top-level mobile navigation
- let mobile send while media uploads, with cancellable progress UI
- normalize iOS and Android video uploads, attach poster frames, and
improve native video playback

## Validation

- `just mobile-check`
- `just mobile-test`
- `cargo test -p buzz-media`
- Pixel smoke test
- iPhone smoke test

Desktop background uploads moved to #4522 so the two platforms can be
reviewed independently.

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Signed-off-by: Tom Brow <tomb@block.xyz>
Co-authored-by: leader <71e9f2c44a6932b6772caaaccda1911d010463c3e2c6c40410b8329956046801@buzz.block.builderlab.xyz>
Co-authored-by: Tom Brow <tomb@block.xyz>
2026-08-04 00:05:13 -07:00

117 lines
2.7 KiB
Dart

import 'package:flutter/foundation.dart';
enum MessageMediaKind { image, video }
@immutable
class ImetaEntry {
final String url;
final String? mimeType;
final String? dimensions;
final String? thumb;
final String? image;
final String? alt;
const ImetaEntry({
required this.url,
this.mimeType,
this.dimensions,
this.thumb,
this.image,
this.alt,
});
bool get isVideo => mimeType?.startsWith('video/') == true;
String? get posterUrl => image ?? thumb;
double? get aspectRatio {
final parts = dimensions?.split('x');
if (parts == null || parts.length != 2) return null;
final width = double.tryParse(parts[0]);
final height = double.tryParse(parts[1]);
if (width == null || height == null || width <= 0 || height <= 0) {
return null;
}
return width / height;
}
}
Map<String, ImetaEntry> parseImetaTags(List<List<String>> tags) {
final byUrl = <String, ImetaEntry>{};
for (final tag in tags) {
if (tag.isEmpty || tag.first != 'imeta') continue;
String? url;
String? mimeType;
String? dimensions;
String? thumb;
String? image;
String? alt;
for (final part in tag.skip(1)) {
final separator = part.indexOf(' ');
if (separator <= 0) continue;
final key = part.substring(0, separator);
final value = part.substring(separator + 1);
switch (key) {
case 'url':
url = value;
case 'm':
mimeType = value;
case 'dim':
dimensions = value;
case 'thumb':
thumb = value;
case 'image':
image = value;
case 'alt':
alt = value;
}
}
if (url == null || url.isEmpty) continue;
byUrl[url] = ImetaEntry(
url: url,
mimeType: mimeType,
dimensions: dimensions,
thumb: thumb,
image: image,
alt: alt,
);
}
return byUrl;
}
MessageMediaKind? classifyMediaUrl(String url, {ImetaEntry? imeta}) {
final mimeType = imeta?.mimeType;
if (mimeType != null) {
// An imeta MIME type is authoritative. The native video player chooses
// whether the device can decode the specific codec/container; rejecting
// every non-MP4 video here prevents it from even trying.
if (mimeType.startsWith('video/')) return MessageMediaKind.video;
if (mimeType.startsWith('image/')) return MessageMediaKind.image;
}
final path = (Uri.tryParse(url)?.path ?? url).toLowerCase();
if (path.endsWith(_mp4Extension)) {
return MessageMediaKind.video;
}
if (_imageExtensions.any(path.endsWith)) {
return MessageMediaKind.image;
}
return null;
}
const _imageExtensions = {
'.jpg',
'.jpeg',
'.png',
'.webp',
'.bmp',
'.heic',
'.heif',
'.avif',
};
const _mp4Extension = '.mp4';