diff --git a/lib/src/providers/api/media_received.dart b/lib/src/providers/api/media_received.dart index a4fde8f..f52d760 100644 --- a/lib/src/providers/api/media_received.dart +++ b/lib/src/providers/api/media_received.dart @@ -21,14 +21,14 @@ import 'package:twonly/src/utils/storage.dart'; Map 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. downloadStartedForMediaReceived = {}; List messages = await twonlyDatabase.messagesDao.getAllMessagesPendingDownloading(); for (Message message in messages) { - await startDownloadMedia(message, false); + await startDownloadMedia(message, force); } } diff --git a/lib/src/views/chats/media_viewer_view.dart b/lib/src/views/chats/media_viewer_view.dart index bacc87b..b14fdc5 100644 --- a/lib/src/views/chats/media_viewer_view.dart +++ b/lib/src/views/chats/media_viewer_view.dart @@ -85,7 +85,7 @@ class _MediaViewerViewState extends State { // to not modify the first message // If the message exists, replace it allMediaFiles[index] = msg; - } else { + } else if (index == -1) { // If the message does not exist, add it allMediaFiles.add(msg); } @@ -143,6 +143,7 @@ class _MediaViewerViewState extends State { }); flutterLocalNotificationsPlugin.cancel(allMediaFiles.first.contactId); + if (allMediaFiles.first.downloadState != DownloadState.downloaded) { setState(() { isDownloading = true; @@ -158,6 +159,8 @@ class _MediaViewerViewState extends State { if (updated.downloadState == DownloadState.downloaded) { downloadStateListener?.cancel(); await handleNextDownloadedMedia(updated, showTwonly); + // start downloading all the other possibile missing media files. + tryDownloadAllMediaFiles(force: true); } } });