2020-01-19 14:07:42 +00:00
|
|
|
import 'package:famedlysdk/famedlysdk.dart';
|
2020-05-16 06:02:33 +00:00
|
|
|
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
2020-05-07 09:19:29 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
2020-01-19 14:07:42 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2020-05-16 06:02:33 +00:00
|
|
|
import 'matrix_file_extension.dart';
|
2020-01-19 14:07:42 +00:00
|
|
|
|
|
|
|
extension LocalizedBody on Event {
|
2020-05-16 06:02:33 +00:00
|
|
|
void openFile(BuildContext context) async {
|
|
|
|
final MatrixFile matrixFile =
|
|
|
|
await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
|
|
|
downloadAndDecryptAttachment(),
|
|
|
|
);
|
|
|
|
matrixFile.open();
|
|
|
|
}
|
|
|
|
|
2020-03-13 19:09:32 +00:00
|
|
|
IconData get statusIcon {
|
2020-05-13 13:58:59 +00:00
|
|
|
switch (status) {
|
2020-03-13 19:09:32 +00:00
|
|
|
case -1:
|
|
|
|
return Icons.error_outline;
|
|
|
|
case 0:
|
|
|
|
return Icons.timer;
|
|
|
|
case 1:
|
|
|
|
return Icons.done;
|
|
|
|
case 2:
|
|
|
|
return Icons.done_all;
|
|
|
|
default:
|
|
|
|
return Icons.done;
|
|
|
|
}
|
|
|
|
}
|
2020-03-13 20:58:48 +00:00
|
|
|
|
2020-05-07 09:19:29 +00:00
|
|
|
bool get showThumbnail =>
|
2020-05-10 11:26:52 +00:00
|
|
|
[MessageTypes.Image, MessageTypes.Sticker].contains(messageType) &&
|
2020-05-09 14:38:27 +00:00
|
|
|
(kIsWeb ||
|
2020-05-10 11:26:52 +00:00
|
|
|
(content['info'] is Map &&
|
2020-05-13 13:58:59 +00:00
|
|
|
content['info']['size'] < room.client.database.maxFileSize));
|
2020-05-07 09:19:29 +00:00
|
|
|
|
2020-03-13 20:58:48 +00:00
|
|
|
String get sizeString {
|
2020-05-13 13:58:59 +00:00
|
|
|
if (content['info'] is Map<String, dynamic> &&
|
|
|
|
content['info'].containsKey('size')) {
|
|
|
|
num size = content['info']['size'];
|
2020-03-13 20:58:48 +00:00
|
|
|
if (size < 1000000) {
|
|
|
|
size = size / 1000;
|
2020-05-16 06:09:07 +00:00
|
|
|
size = (size * 10).round() / 10;
|
|
|
|
return '${size.toString()} KB';
|
2020-03-13 20:58:48 +00:00
|
|
|
} else if (size < 1000000000) {
|
|
|
|
size = size / 1000000;
|
2020-05-16 06:09:07 +00:00
|
|
|
size = (size * 10).round() / 10;
|
|
|
|
return '${size.toString()} MB';
|
2020-03-13 20:58:48 +00:00
|
|
|
} else {
|
|
|
|
size = size / 1000000000;
|
2020-05-16 06:09:07 +00:00
|
|
|
size = (size * 10).round() / 10;
|
|
|
|
return '${size.toString()} GB';
|
2020-03-13 20:58:48 +00:00
|
|
|
}
|
2020-03-14 10:05:28 +00:00
|
|
|
} else {
|
2020-03-13 20:58:48 +00:00
|
|
|
return null;
|
2020-03-14 10:05:28 +00:00
|
|
|
}
|
2020-03-13 20:58:48 +00:00
|
|
|
}
|
2020-01-19 14:07:42 +00:00
|
|
|
}
|