diff --git a/lib/models/profile.dart b/lib/models/profile.dart index dc1b6c58..d79617ef 100644 --- a/lib/models/profile.dart +++ b/lib/models/profile.dart @@ -174,6 +174,7 @@ class ProfileInfoState extends ChangeNotifier { void downloadInit(String fileKey, int numChunks) { this._downloads[fileKey] = FileDownloadProgress(numChunks, DateTime.now()); + notifyListeners(); } void downloadUpdate(String fileKey, int progress, int numChunks) { @@ -239,6 +240,7 @@ class ProfileInfoState extends ChangeNotifier { void downloadMarkResumed(String fileKey) { if (this._downloads.containsKey(fileKey)) { this._downloads[fileKey]!.interrupted = false; + notifyListeners(); } } @@ -250,21 +252,21 @@ class ProfileInfoState extends ChangeNotifier { void downloadSetPath(String fileKey, String path) { if (this._downloads.containsKey(fileKey)) { this._downloads[fileKey]!.downloadedTo = path; + notifyListeners(); } } // set the download path for the sender void downloadSetPathForSender(String fileKey, String path) { - // only allow this override if we are the sender... - if (this._downloads.containsKey(fileKey) == false) { + // we may trigger this event for auto-downloaded receivers too, + // as such we don't assume anything else about the file...other than that + // it exists. + if (!this._downloads.containsKey(fileKey)) { + // this will be overwritten by download update if the file is being downloaded this._downloads[fileKey] = FileDownloadProgress(1, DateTime.now()); - this._downloads[fileKey]!.timeEnd = DateTime.now(); - this._downloads[fileKey]!.chunksDownloaded = 1; - this._downloads[fileKey]!.gotManifest = true; - this._downloads[fileKey]!.complete = true; - this._downloads[fileKey]!.downloadedTo = path; - notifyListeners(); } + this._downloads[fileKey]!.downloadedTo = path; + notifyListeners(); } String? downloadFinalPath(String fileKey) { diff --git a/lib/widgets/filebubble.dart b/lib/widgets/filebubble.dart index 79b73afd..4d91de6d 100644 --- a/lib/widgets/filebubble.dart +++ b/lib/widgets/filebubble.dart @@ -53,18 +53,19 @@ class FileBubbleState extends State { var showFileSharing = Provider.of(context, listen: false).isExperimentEnabled(FileSharingExperiment); var prettyDate = DateFormat.yMd(Platform.localeName).add_jm().format(Provider.of(context).timestamp); var metadata = Provider.of(context); - var downloadComplete = metadata.attributes["filepath"] != null || Provider.of(context).downloadComplete(widget.fileKey()); - var downloadInterrupted = Provider.of(context).downloadInterrupted(widget.fileKey()); - var path = Provider.of(context).downloadFinalPath(widget.fileKey()); // If we haven't stored the filepath in message attributes then save it - if (downloadComplete && path == null && metadata.attributes["filepath"] != null) { + if (metadata.attributes["filepath"] != null) { path = metadata.attributes["filepath"]; - } else if (downloadComplete && path != null && metadata.attributes["filepath"] == null) { + } else if (path != null && metadata.attributes["filepath"] == null) { Provider.of(context).cwtch.SetMessageAttribute(metadata.profileOnion, metadata.conversationIdentifier, 0, metadata.messageID, "filepath", path); } + // the file is downloaded when it is from the sender AND the path is known OR when we get an explicit downloadComplete + var downloadComplete = (fromMe && path != null) || Provider.of(context).downloadComplete(widget.fileKey()); + var downloadInterrupted = Provider.of(context).downloadInterrupted(widget.fileKey()); + if (downloadComplete && path != null) { var lpath = path.toLowerCase(); if (lpath.endsWith(".jpg") || lpath.endsWith(".jpeg") || lpath.endsWith(".png") || lpath.endsWith(".gif") || lpath.endsWith(".webp") || lpath.endsWith(".bmp")) { @@ -209,7 +210,6 @@ class FileBubbleState extends State { if (Platform.isAndroid) { Provider.of(context, listen: false).downloadInit(widget.fileKey(), (widget.fileSize / 4096).ceil()); Provider.of(context, listen: false).cwtch.SetMessageAttribute(profileOnion, conversation, 0, idx, "file-downloaded", "true"); - //Provider.of(context, listen: false).attributes |= 0x02; ContactInfoState? contact = Provider.of(context).contactList.findContact(Provider.of(context).senderHandle); if (contact != null) { Provider.of(context, listen: false).cwtch.CreateDownloadableFile(profileOnion, contact.identifier, widget.nameSuggestion, widget.fileKey()); @@ -225,7 +225,6 @@ class FileBubbleState extends State { var manifestPath = file.path + ".manifest"; Provider.of(context, listen: false).downloadInit(widget.fileKey(), (widget.fileSize / 4096).ceil()); Provider.of(context, listen: false).cwtch.SetMessageAttribute(profileOnion, conversation, 0, idx, "file-downloaded", "true"); - //Provider.of(context, listen: false).flags |= 0x02; ContactInfoState? contact = Provider.of(context, listen: false).contactList.findContact(Provider.of(context).senderHandle); if (contact != null) { Provider.of(context, listen: false).cwtch.DownloadFile(profileOnion, contact.identifier, file.path, manifestPath, widget.fileKey());