From 92374ad112dff0b332662103d454cd8259060f87 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Fri, 21 Jan 2022 10:12:49 -0800 Subject: [PATCH] Only override path for Sender, not any other attributes. For auto-downloads both the sender and receiver set the path before the UI can set download state. As such we need to be careful about how we let the sender know about the filekey/path. --- lib/models/profile.dart | 12 +++++------- lib/widgets/filebubble.dart | 13 ++++++------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/lib/models/profile.dart b/lib/models/profile.dart index dc1b6c58..98783f12 100644 --- a/lib/models/profile.dart +++ b/lib/models/profile.dart @@ -255,16 +255,14 @@ class ProfileInfoState extends ChangeNotifier { // set the download path for the sender void downloadSetPathForSender(String fileKey, String path) { - // only allow this override if we are the sender... + // 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) == false) { + // 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; } 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());