mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-01-15 13:48:41 +00:00
fix #153
This commit is contained in:
parent
7e7ac832e8
commit
f6ce7c83db
2 changed files with 6 additions and 3 deletions
|
|
@ -21,14 +21,14 @@ import 'package:twonly/src/utils/storage.dart';
|
|||
|
||||
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.
|
||||
downloadStartedForMediaReceived = {};
|
||||
List<Message> messages =
|
||||
await twonlyDatabase.messagesDao.getAllMessagesPendingDownloading();
|
||||
|
||||
for (Message message in messages) {
|
||||
await startDownloadMedia(message, false);
|
||||
await startDownloadMedia(message, force);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ class _MediaViewerViewState extends State<MediaViewerView> {
|
|||
// 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<MediaViewerView> {
|
|||
});
|
||||
|
||||
flutterLocalNotificationsPlugin.cancel(allMediaFiles.first.contactId);
|
||||
|
||||
if (allMediaFiles.first.downloadState != DownloadState.downloaded) {
|
||||
setState(() {
|
||||
isDownloading = true;
|
||||
|
|
@ -158,6 +159,8 @@ class _MediaViewerViewState extends State<MediaViewerView> {
|
|||
if (updated.downloadState == DownloadState.downloaded) {
|
||||
downloadStateListener?.cancel();
|
||||
await handleNextDownloadedMedia(updated, showTwonly);
|
||||
// start downloading all the other possibile missing media files.
|
||||
tryDownloadAllMediaFiles(force: true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue