fluffychat/lib/utils/room_send_file_extension.dart

34 lines
691 B
Dart
Raw Normal View History

//@dart=2.12
2020-09-03 12:58:54 +02:00
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,
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
}
}
return sendFileEvent(
file,
txid: txid,
inReplyTo: inReplyTo,
editEventId: editEventId,
waitUntilSent: waitUntilSent ?? false,
thumbnail: thumbnail,
);
}
}