8c421952db
Operator-attached images render as rounded thumbnails above the user bubble and open a zoomable Material/Cupertino viewer. Inline data: URIs decode locally; file:// attachment-store URIs load through the new chat_attachment_image websocket request, which serves only regular image files directly inside the private attachment store (os.Root, <= 4 MiB, sniffed raster types). Missing files show an 'Image no longer available' placeholder; other files keep the file row.
58 lines
1.9 KiB
Dart
58 lines
1.9 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
|
|
import '../../../../core/api_gateway.dart';
|
|
import '../../data/chat_attachment_images.dart';
|
|
import '../../domain/chat_attachment_image.dart';
|
|
import 'chat_attachment_thumbnail.dart';
|
|
|
|
/// Whether a file part draws as a thumbnail: a raster image whose bytes the
|
|
/// client can reach (inline, the server's attachment store or a fresh upload).
|
|
bool chatPartIsThumbnail(JsonMap part) =>
|
|
chatPartImageMime(part) != null &&
|
|
chatImageSourceOf('${part['uri'] ?? ''}'.trim()) != null;
|
|
|
|
/// The operator's attached images above their message, end-aligned like the
|
|
/// turn itself, wrapping onto further lines on a narrow pane.
|
|
class ChatAttachmentGallery extends StatelessWidget {
|
|
const ChatAttachmentGallery({
|
|
super.key,
|
|
required this.parts,
|
|
required this.images,
|
|
required this.cupertino,
|
|
});
|
|
|
|
/// File parts for which [chatPartIsThumbnail] holds.
|
|
final List<JsonMap> parts;
|
|
final ChatAttachmentImages images;
|
|
final bool cupertino;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Wrap(
|
|
key: const Key('chat-attachment-gallery'),
|
|
alignment: WrapAlignment.end,
|
|
spacing: 8,
|
|
runSpacing: 8,
|
|
children: [
|
|
for (final (index, part) in parts.indexed)
|
|
ChatAttachmentThumbnail(
|
|
key: ValueKey<String>('chat-attachment-image-$index'),
|
|
name: chatAttachmentPartName(part),
|
|
uri: '${part['uri'] ?? ''}'.trim(),
|
|
images: images,
|
|
cupertino: cupertino,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
/// The web's attachment name rule: its own name, else the URI basename, else
|
|
/// `file`. A `data:` URI has no useful basename, so it reads `image`.
|
|
String chatAttachmentPartName(JsonMap part) {
|
|
final name = '${part['name'] ?? ''}'.trim();
|
|
if (name.isNotEmpty) return name;
|
|
final uri = '${part['uri'] ?? ''}'.trim();
|
|
if (uri.startsWith('data:')) return 'image';
|
|
final basename = uri.split('/').last.trim();
|
|
return basename.isEmpty ? 'file' : basename;
|
|
}
|