You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.4 KiB
Dart
50 lines
1.4 KiB
Dart
5 years ago
|
import 'package:flutter/foundation.dart';
|
||
6 years ago
|
import 'package:flutter/material.dart';
|
||
4 years ago
|
|
||
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||
|
import 'package:matrix/matrix.dart';
|
||
|
|
||
3 years ago
|
import 'package:fluffychat/utils/size_string.dart';
|
||
5 years ago
|
import 'matrix_file_extension.dart';
|
||
6 years ago
|
|
||
|
extension LocalizedBody on Event {
|
||
3 years ago
|
Future<LoadingDialogResult<MatrixFile?>> _getFile(BuildContext context) =>
|
||
|
showFutureLoadingDialog(
|
||
|
context: context,
|
||
3 years ago
|
future: downloadAndDecryptAttachment,
|
||
3 years ago
|
);
|
||
|
|
||
4 years ago
|
void saveFile(BuildContext context) async {
|
||
3 years ago
|
final matrixFile = await _getFile(context);
|
||
4 years ago
|
|
||
|
matrixFile.result?.save(context);
|
||
5 years ago
|
}
|
||
|
|
||
3 years ago
|
void shareFile(BuildContext context) async {
|
||
|
final matrixFile = await _getFile(context);
|
||
|
|
||
|
matrixFile.result?.share(context);
|
||
|
}
|
||
|
|
||
5 years ago
|
bool get isAttachmentSmallEnough =>
|
||
|
infoMap['size'] is int &&
|
||
4 years ago
|
infoMap['size'] < room.client.database!.maxFileSize;
|
||
3 years ago
|
|
||
5 years ago
|
bool get isThumbnailSmallEnough =>
|
||
|
thumbnailInfoMap['size'] is int &&
|
||
4 years ago
|
thumbnailInfoMap['size'] < room.client.database!.maxFileSize;
|
||
5 years ago
|
|
||
5 years ago
|
bool get showThumbnail =>
|
||
4 years ago
|
[MessageTypes.Image, MessageTypes.Sticker, MessageTypes.Video]
|
||
|
.contains(messageType) &&
|
||
5 years ago
|
(kIsWeb ||
|
||
5 years ago
|
isAttachmentSmallEnough ||
|
||
|
isThumbnailSmallEnough ||
|
||
5 years ago
|
(content['url'] is String));
|
||
5 years ago
|
|
||
3 years ago
|
String? get sizeString => content
|
||
|
.tryGetMap<String, dynamic>('info')
|
||
|
?.tryGet<int>('size')
|
||
|
?.sizeString;
|
||
6 years ago
|
}
|