diff --git a/lib/model.dart b/lib/model.dart index 0b68d15a..c9915d2f 100644 --- a/lib/model.dart +++ b/lib/model.dart @@ -443,10 +443,17 @@ class ProfileInfoState extends ChangeNotifier { // so setting numChunks correctly shouldn't matter this.downloadInit(fileKey, 1); } - this._downloads[fileKey]!.timeEnd = DateTime.now(); - this._downloads[fileKey]!.downloadedTo = finalPath; - this._downloads[fileKey]!.complete = true; - notifyListeners(); + // only update if different + if (!this._downloads[fileKey]!.complete) { + this._downloads[fileKey]!.timeEnd = DateTime.now(); + this._downloads[fileKey]!.downloadedTo = finalPath; + this._downloads[fileKey]!.complete = true; + notifyListeners(); + } + } + + bool downloadKnown(String fileKey) { + return this._downloads.containsKey(fileKey); } bool downloadActive(String fileKey) { diff --git a/lib/models/messages/filemessage.dart b/lib/models/messages/filemessage.dart index 83387ac9..c155ef60 100644 --- a/lib/models/messages/filemessage.dart +++ b/lib/models/messages/filemessage.dart @@ -7,6 +7,7 @@ import 'package:cwtch/widgets/messagerow.dart'; import 'package:flutter/widgets.dart'; import 'package:provider/provider.dart'; +import '../../main.dart'; import '../../model.dart'; class FileMessage extends Message { @@ -29,6 +30,13 @@ class FileMessage extends Message { String rootHash = shareObj['h'] as String; String nonce = shareObj['n'] as String; int fileSize = shareObj['s'] as int; + String fileKey = rootHash + "." + nonce; + + if (metadata.attributes["file-downloaded"] == "true") { + if (!Provider.of(context).downloadKnown(fileKey)) { + Provider.of(context, listen: false).cwtch.CheckDownloadStatus(Provider.of(context, listen: false).onion, fileKey); + } + } if (!validHash(rootHash, nonce)) { return MessageRow(MalformedBubble()); diff --git a/lib/widgets/filebubble.dart b/lib/widgets/filebubble.dart index f25b170e..ea937303 100644 --- a/lib/widgets/filebubble.dart +++ b/lib/widgets/filebubble.dart @@ -53,10 +53,6 @@ class FileBubbleState extends State { var downloadComplete = Provider.of(context).downloadComplete(widget.fileKey()); var downloadInterrupted = Provider.of(context).downloadInterrupted(widget.fileKey()); - /*if (flagStarted && !downloadInterrupted) { - Provider.of(context, listen: false).cwtch.CheckDownloadStatus(Provider.of(context, listen: false).onion, widget.fileKey()); - }*/ - var path = Provider.of(context).downloadFinalPath(widget.fileKey()); if (downloadComplete) { var lpath = path!.toLowerCase();