fluffychat/lib/utils/matrix_sdk_extensions/event_extension.dart
dependabot[bot] 3a6d18038e
build: (deps): bump matrix from 4.1.0 to 5.0.0
Bumps [matrix](https://github.com/famedly/matrix-dart-sdk) from 4.1.0 to 5.0.0.
- [Release notes](https://github.com/famedly/matrix-dart-sdk/releases)
- [Changelog](https://github.com/famedly/matrix-dart-sdk/blob/main/CHANGELOG.md)
- [Commits](https://github.com/famedly/matrix-dart-sdk/compare/v4.1.0...v5.0.0)

---
updated-dependencies:
- dependency-name: matrix
  dependency-version: 5.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-01-15 16:12:58 +01:00

65 lines
1.8 KiB
Dart

import 'dart:developer';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:async/async.dart' as async;
import 'package:matrix/matrix.dart';
import 'package:fluffychat/utils/size_string.dart';
import 'package:fluffychat/widgets/future_loading_dialog.dart';
import 'matrix_file_extension.dart';
extension LocalizedBody on Event {
Future<async.Result<MatrixFile?>> _getFile(BuildContext context) =>
showFutureLoadingDialog(
context: context,
futureWithProgress: (onProgress) {
final fileSize = infoMap['size'] is int
? infoMap['size'] as int
: null;
return downloadAndDecryptAttachment(
onDownloadProgress: fileSize == null
? null
: (bytes) => onProgress(bytes / fileSize),
);
},
);
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'] as int) < room.client.database.maxFileSize;
bool get isThumbnailSmallEnough =>
thumbnailInfoMap['size'] is int &&
(thumbnailInfoMap['size'] as int) < 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;
}