mirror of
https://github.com/block/buzz.git
synced 2026-11-28 04:01:45 +00:00
Human profile setup and editing now offer **Image** and **Animated**. The human editor hides Emoji through its available modes. The emoji picker, editing controls and setup default remain in source. Existing emoji artwork still displays, and agents can still choose Emoji. Validation: mobile analysis and formatting passed; the complete Flutter suite passed 5,117 tests (71 skipped). The follow-up restores the Image → Animated preview regression test proposed in #9734. The final pre-push mobile checks passed, including the complete suite. A prior run at this revision failed in the profile-cache persistence test and passed on rerun. The crypto package passed all 27 tests. The iPhone Air preview opened with the existing session. Physical recording and saving still need human verification. Check setup and Settings → Edit Photo: only Image and Animated appear, image upload and animation recording/save work, and agent avatar editing still offers emoji. --------- Signed-off-by: kenny lopez <klopez4212@gmail.com> Signed-off-by: Tom Brow <tomb@block.xyz> Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz> Co-authored-by: Tom Brow <tomb@block.xyz>
146 lines
4.9 KiB
Dart
146 lines
4.9 KiB
Dart
import 'dart:typed_data';
|
|
|
|
import '../../shared/animated_avatar.dart';
|
|
import '../../shared/relay/relay.dart';
|
|
|
|
/// A prepared profile-avatar change that is uploaded only when the user saves.
|
|
sealed class ProfileAvatarDraft {
|
|
/// Creates a prepared profile-avatar draft.
|
|
const ProfileAvatarDraft();
|
|
|
|
/// Returns the avatar URL for this draft using [service] when upload is
|
|
/// required.
|
|
///
|
|
/// Implementations cache successful uploads for the same service so a
|
|
/// profile-publish retry does not create duplicate media. Failed uploads may
|
|
/// be retried, and changing services starts a new upload for that community.
|
|
Future<String> upload(MediaUploadService service);
|
|
}
|
|
|
|
/// A locally prepared still image awaiting upload on Save.
|
|
final class ProfileImageAvatarDraft extends ProfileAvatarDraft {
|
|
/// Creates a still-image draft from JPEG or PNG [bytes].
|
|
ProfileImageAvatarDraft(this.bytes);
|
|
|
|
/// The prepared JPEG or PNG payload.
|
|
final Uint8List bytes;
|
|
MediaUploadService? _uploadService;
|
|
Future<String>? _uploadedUrl;
|
|
|
|
@override
|
|
Future<String> upload(MediaUploadService service) async {
|
|
if (!identical(_uploadService, service)) {
|
|
_uploadService = service;
|
|
_uploadedUrl = null;
|
|
}
|
|
final existing = _uploadedUrl;
|
|
if (existing != null) return existing;
|
|
final upload = service
|
|
.uploadBytes(bytes, mimeType: detectImageMimeType(bytes))
|
|
.then((descriptor) => descriptor.url);
|
|
_uploadedUrl = upload;
|
|
try {
|
|
return await upload;
|
|
} catch (_) {
|
|
if (identical(_uploadedUrl, upload)) _uploadedUrl = null;
|
|
rethrow;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// A locally prepared animated avatar and its still poster awaiting upload.
|
|
final class ProfileAnimatedAvatarDraft extends ProfileAvatarDraft {
|
|
/// Creates an animated draft from PNG [animation] and [poster] payloads.
|
|
ProfileAnimatedAvatarDraft({required this.animation, required this.poster});
|
|
|
|
/// The animated PNG payload.
|
|
final Uint8List animation;
|
|
|
|
/// The still PNG poster shown when animation is unavailable or disabled.
|
|
final Uint8List poster;
|
|
MediaUploadService? _uploadService;
|
|
Future<String>? _uploadedUrl;
|
|
Future<BlobDescriptor>? _posterUpload;
|
|
Future<BlobDescriptor>? _animationUpload;
|
|
|
|
Future<BlobDescriptor> _uploadPoster(MediaUploadService service) {
|
|
final existing = _posterUpload;
|
|
if (existing != null) return existing;
|
|
late final Future<BlobDescriptor> upload;
|
|
upload = service.uploadBytes(poster, mimeType: 'image/png').catchError((
|
|
Object error,
|
|
StackTrace stackTrace,
|
|
) {
|
|
if (identical(_posterUpload, upload)) _posterUpload = null;
|
|
Error.throwWithStackTrace(error, stackTrace);
|
|
});
|
|
_posterUpload = upload;
|
|
return upload;
|
|
}
|
|
|
|
Future<BlobDescriptor> _uploadAnimation(MediaUploadService service) {
|
|
final existing = _animationUpload;
|
|
if (existing != null) return existing;
|
|
late final Future<BlobDescriptor> upload;
|
|
upload = service.uploadBytes(animation, mimeType: 'image/png').catchError((
|
|
Object error,
|
|
StackTrace stackTrace,
|
|
) {
|
|
if (identical(_animationUpload, upload)) _animationUpload = null;
|
|
Error.throwWithStackTrace(error, stackTrace);
|
|
});
|
|
_animationUpload = upload;
|
|
return upload;
|
|
}
|
|
|
|
@override
|
|
Future<String> upload(MediaUploadService service) async {
|
|
if (!identical(_uploadService, service)) {
|
|
_uploadService = service;
|
|
_uploadedUrl = null;
|
|
_posterUpload = null;
|
|
_animationUpload = null;
|
|
}
|
|
final existing = _uploadedUrl;
|
|
if (existing != null) return existing;
|
|
// Cache each content-addressed part independently. If one request fails,
|
|
// retry only that part so a successful counterpart remains attached to
|
|
// this draft instead of becoming an abandoned duplicate.
|
|
final upload = Future.wait(
|
|
[_uploadPoster(service), _uploadAnimation(service)],
|
|
).then((uploads) => buildAnimatedAvatarUrl(uploads[0].url, uploads[1].url));
|
|
_uploadedUrl = upload;
|
|
try {
|
|
return await upload;
|
|
} catch (_) {
|
|
if (identical(_uploadedUrl, upload)) _uploadedUrl = null;
|
|
rethrow;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Transfers only local draft data between the app and its native sheet engine.
|
|
Map<String, Object?>? encodeProfileAvatarDraft(ProfileAvatarDraft? draft) =>
|
|
switch (draft) {
|
|
ProfileImageAvatarDraft(:final bytes) => {
|
|
'type': 'image',
|
|
'bytes': bytes,
|
|
},
|
|
ProfileAnimatedAvatarDraft(:final animation, :final poster) => {
|
|
'type': 'animated',
|
|
'animation': animation,
|
|
'poster': poster,
|
|
},
|
|
null => null,
|
|
};
|
|
|
|
ProfileAvatarDraft? decodeProfileAvatarDraft(Map<dynamic, dynamic>? value) =>
|
|
switch (value?['type']) {
|
|
'image' => ProfileImageAvatarDraft(value!['bytes'] as Uint8List),
|
|
'animated' => ProfileAnimatedAvatarDraft(
|
|
animation: value!['animation'] as Uint8List,
|
|
poster: value['poster'] as Uint8List,
|
|
),
|
|
_ => null,
|
|
};
|