This commit is contained in:
otsmr 2025-05-01 23:13:33 +02:00
parent 7e7ac832e8
commit f6ce7c83db
2 changed files with 6 additions and 3 deletions

View file

@ -21,14 +21,14 @@ import 'package:twonly/src/utils/storage.dart';
Map<int, DateTime> downloadStartedForMediaReceived = {}; Map<int, DateTime> downloadStartedForMediaReceived = {};
Future tryDownloadAllMediaFiles() async { Future tryDownloadAllMediaFiles({bool force = false}) async {
// this is called when websocket is newly connected, so allow all downloads to be restarted. // this is called when websocket is newly connected, so allow all downloads to be restarted.
downloadStartedForMediaReceived = {}; downloadStartedForMediaReceived = {};
List<Message> messages = List<Message> messages =
await twonlyDatabase.messagesDao.getAllMessagesPendingDownloading(); await twonlyDatabase.messagesDao.getAllMessagesPendingDownloading();
for (Message message in messages) { for (Message message in messages) {
await startDownloadMedia(message, false); await startDownloadMedia(message, force);
} }
} }

View file

@ -85,7 +85,7 @@ class _MediaViewerViewState extends State<MediaViewerView> {
// to not modify the first message // to not modify the first message
// If the message exists, replace it // If the message exists, replace it
allMediaFiles[index] = msg; allMediaFiles[index] = msg;
} else { } else if (index == -1) {
// If the message does not exist, add it // If the message does not exist, add it
allMediaFiles.add(msg); allMediaFiles.add(msg);
} }
@ -143,6 +143,7 @@ class _MediaViewerViewState extends State<MediaViewerView> {
}); });
flutterLocalNotificationsPlugin.cancel(allMediaFiles.first.contactId); flutterLocalNotificationsPlugin.cancel(allMediaFiles.first.contactId);
if (allMediaFiles.first.downloadState != DownloadState.downloaded) { if (allMediaFiles.first.downloadState != DownloadState.downloaded) {
setState(() { setState(() {
isDownloading = true; isDownloading = true;
@ -158,6 +159,8 @@ class _MediaViewerViewState extends State<MediaViewerView> {
if (updated.downloadState == DownloadState.downloaded) { if (updated.downloadState == DownloadState.downloaded) {
downloadStateListener?.cancel(); downloadStateListener?.cancel();
await handleNextDownloadedMedia(updated, showTwonly); await handleNextDownloadedMedia(updated, showTwonly);
// start downloading all the other possibile missing media files.
tryDownloadAllMediaFiles(force: true);
} }
} }
}); });