mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
## 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>
82 lines
2.4 KiB
Dart
82 lines
2.4 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:image_picker/image_picker.dart';
|
|
|
|
var _retainedImageCounter = 0;
|
|
|
|
Future<void> processCapturedImage(
|
|
XFile image,
|
|
Future<void> Function(XFile image) onCapture,
|
|
) async {
|
|
await processTemporaryImages([image], (images) => onCapture(images.single));
|
|
}
|
|
|
|
/// Processes native-owned [images], then removes their temporary files.
|
|
Future<void> processTemporaryImages(
|
|
List<XFile> images,
|
|
Future<void> Function(List<XFile> images) process,
|
|
) async {
|
|
try {
|
|
await process(images);
|
|
} finally {
|
|
for (final image in images) {
|
|
final path = image.path;
|
|
if (path.isNotEmpty) {
|
|
try {
|
|
await File(path).delete();
|
|
} on FileSystemException {
|
|
// The native picker may already have removed its temporary file.
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Copies native-owned [images] into composer-owned temporary files.
|
|
///
|
|
/// Native camera and picker integrations delete their source files as soon as
|
|
/// their callback returns. Deferred sends must therefore retain their own copy
|
|
/// before queueing a preview for later upload.
|
|
Future<List<XFile>> retainTemporaryImages(List<XFile> images) async {
|
|
final retained = <XFile>[];
|
|
try {
|
|
for (final image in images) {
|
|
final sourcePath = image.path;
|
|
final extension = _safeFileExtension(sourcePath);
|
|
final destination = File(
|
|
'${Directory.systemTemp.path}${Platform.pathSeparator}'
|
|
'buzz-compose-${DateTime.now().microsecondsSinceEpoch}-'
|
|
'${_retainedImageCounter++}$extension',
|
|
);
|
|
if (sourcePath.isNotEmpty && await File(sourcePath).exists()) {
|
|
await File(sourcePath).copy(destination.path);
|
|
} else {
|
|
await destination.writeAsBytes(await image.readAsBytes(), flush: true);
|
|
}
|
|
retained.add(
|
|
XFile(destination.path, name: image.name, mimeType: image.mimeType),
|
|
);
|
|
}
|
|
return retained;
|
|
} catch (_) {
|
|
for (final image in retained) {
|
|
try {
|
|
await File(image.path).delete();
|
|
} on FileSystemException {
|
|
// A failed copy may not have created every destination.
|
|
}
|
|
}
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
String _safeFileExtension(String path) {
|
|
final separator = path.lastIndexOf(Platform.pathSeparator);
|
|
final dot = path.lastIndexOf('.');
|
|
if (dot <= separator || dot == path.length - 1) return '.jpg';
|
|
final extension = path.substring(dot);
|
|
return RegExp(r'^\.[A-Za-z0-9]{1,10}$').hasMatch(extension)
|
|
? extension
|
|
: '.jpg';
|
|
}
|