mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-12-05 02:39:26 +01:00
53 lines
1.5 KiB
Dart
53 lines
1.5 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
|
import 'package:matrix/matrix.dart';
|
|
|
|
import 'package:fluffychat/utils/size_string.dart';
|
|
import 'matrix_file_extension.dart';
|
|
|
|
extension LocalizedBody on Event {
|
|
Future<LoadingDialogResult<MatrixFile?>> _getFile(BuildContext context) =>
|
|
showFutureLoadingDialog(
|
|
context: context,
|
|
future: downloadAndDecryptAttachment,
|
|
);
|
|
|
|
void saveFile(BuildContext context) async {
|
|
final matrixFile = await _getFile(context);
|
|
|
|
matrixFile.result?.save(context);
|
|
}
|
|
|
|
void shareFile(BuildContext context) async {
|
|
final matrixFile = await _getFile(context);
|
|
inspect(matrixFile);
|
|
|
|
matrixFile.result?.share(context);
|
|
}
|
|
|
|
bool get isAttachmentSmallEnough =>
|
|
infoMap['size'] is int &&
|
|
infoMap['size'] < room.client.database!.maxFileSize;
|
|
|
|
bool get isThumbnailSmallEnough =>
|
|
thumbnailInfoMap['size'] is int &&
|
|
thumbnailInfoMap['size'] < room.client.database!.maxFileSize;
|
|
|
|
bool get showThumbnail =>
|
|
[MessageTypes.Image, MessageTypes.Sticker, MessageTypes.Video]
|
|
.contains(messageType) &&
|
|
(kIsWeb ||
|
|
isAttachmentSmallEnough ||
|
|
isThumbnailSmallEnough ||
|
|
(content['url'] is String));
|
|
|
|
String? get sizeString => content
|
|
.tryGetMap<String, dynamic>('info')
|
|
?.tryGet<int>('size')
|
|
?.sizeString;
|
|
}
|