fluffychat/lib/utils/room_send_file_extension.dart

36 lines
843 B
Dart
Raw Normal View History

import 'package:matrix/matrix.dart';
import 'resize_image.dart';
2020-09-03 12:58:54 +02:00
extension RoomSendFileExtension on Room {
2021-08-26 19:03:08 +02:00
Future<Uri> sendFileEventWithThumbnail(
2020-09-03 12:58:54 +02:00
MatrixFile file, {
String? txid,
Event? inReplyTo,
String? editEventId,
bool? waitUntilSent,
Map<String, dynamic>? extraContent,
2020-09-03 12:58:54 +02:00
}) async {
MatrixImageFile? thumbnail;
if (file is MatrixImageFile) {
thumbnail = await file.resizeImage();
2020-09-03 12:58:54 +02:00
if (thumbnail.size > file.size ~/ 2) {
thumbnail = null;
2020-09-03 12:58:54 +02:00
}
} else if (file is MatrixVideoFile) {
thumbnail = await file.getVideoThumbnail();
2020-09-03 12:58:54 +02:00
}
return sendFileEvent(
file,
txid: txid,
inReplyTo: inReplyTo,
editEventId: editEventId,
waitUntilSent: waitUntilSent ?? false,
thumbnail: thumbnail,
extraContent: extraContent,
2020-09-03 12:58:54 +02:00
);
}
}