mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-12-23 22:12:34 +01:00
fix: Remove deprecated meomry caching of downloaded files
This commit is contained in:
parent
b368bf31ce
commit
0c38f6a205
@ -60,9 +60,7 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
||||
if (status != AudioPlayerStatus.notDownloaded) return;
|
||||
setState(() => status = AudioPlayerStatus.downloading);
|
||||
try {
|
||||
final matrixFile =
|
||||
await widget.event.downloadAndDecryptAttachmentCached();
|
||||
if (matrixFile == null) throw ('Download failed');
|
||||
final matrixFile = await widget.event.downloadAndDecryptAttachment();
|
||||
final tempDir = await getTemporaryDirectory();
|
||||
final fileName = Uri.encodeComponent(
|
||||
widget.event.attachmentOrThumbnailMxcUrl()!.pathSegments.last);
|
||||
|
@ -1,7 +1,6 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
@ -12,7 +11,7 @@ extension LocalizedBody on Event {
|
||||
Future<LoadingDialogResult<MatrixFile?>> _getFile(BuildContext context) =>
|
||||
showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => downloadAndDecryptAttachmentCached(),
|
||||
future: downloadAndDecryptAttachment,
|
||||
);
|
||||
|
||||
void saveFile(BuildContext context) async {
|
||||
@ -47,39 +46,4 @@ extension LocalizedBody on Event {
|
||||
.tryGetMap<String, dynamic>('info')
|
||||
?.tryGet<int>('size')
|
||||
?.sizeString;
|
||||
|
||||
static final _downloadAndDecryptFutures = <String, Future<MatrixFile>>{};
|
||||
|
||||
Future<bool> isAttachmentCached({bool getThumbnail = false}) async {
|
||||
final mxcUrl = attachmentOrThumbnailMxcUrl(getThumbnail: getThumbnail);
|
||||
if (mxcUrl == null) return false;
|
||||
// check if we have it in-memory
|
||||
if (_downloadAndDecryptFutures.containsKey(mxcUrl)) {
|
||||
return true;
|
||||
}
|
||||
// check if it is stored
|
||||
if (await isAttachmentInLocalStore(getThumbnail: getThumbnail)) {
|
||||
return true;
|
||||
}
|
||||
// check if the url is cached
|
||||
final url = mxcUrl.getDownloadLink(room.client);
|
||||
final file = await DefaultCacheManager().getFileFromCache(url.toString());
|
||||
return file != null;
|
||||
}
|
||||
|
||||
Future<MatrixFile?> downloadAndDecryptAttachmentCached(
|
||||
{bool getThumbnail = false}) async {
|
||||
final mxcUrl =
|
||||
attachmentOrThumbnailMxcUrl(getThumbnail: getThumbnail)?.toString() ??
|
||||
eventId;
|
||||
_downloadAndDecryptFutures[mxcUrl] ??= downloadAndDecryptAttachment(
|
||||
getThumbnail: getThumbnail,
|
||||
downloadCallback: (Uri url) async {
|
||||
final file = await DefaultCacheManager().getSingleFile(url.toString());
|
||||
return await file.readAsBytes();
|
||||
},
|
||||
);
|
||||
final res = await _downloadAndDecryptFutures[mxcUrl];
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user