Only override path for Sender, not any other attributes.
continuous-integration/drone/pr Build is passing Details

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.
This commit is contained in:
Sarah Jamie Lewis 2022-01-21 10:12:49 -08:00
parent 0a3837c8b5
commit 92374ad112
2 changed files with 11 additions and 14 deletions

View File

@ -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) {

View File

@ -53,18 +53,19 @@ class FileBubbleState extends State<FileBubble> {
var showFileSharing = Provider.of<Settings>(context, listen: false).isExperimentEnabled(FileSharingExperiment);
var prettyDate = DateFormat.yMd(Platform.localeName).add_jm().format(Provider.of<MessageMetadata>(context).timestamp);
var metadata = Provider.of<MessageMetadata>(context);
var downloadComplete = metadata.attributes["filepath"] != null || Provider.of<ProfileInfoState>(context).downloadComplete(widget.fileKey());
var downloadInterrupted = Provider.of<ProfileInfoState>(context).downloadInterrupted(widget.fileKey());
var path = Provider.of<ProfileInfoState>(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<FlwtchState>(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<ProfileInfoState>(context).downloadComplete(widget.fileKey());
var downloadInterrupted = Provider.of<ProfileInfoState>(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<FileBubble> {
if (Platform.isAndroid) {
Provider.of<ProfileInfoState>(context, listen: false).downloadInit(widget.fileKey(), (widget.fileSize / 4096).ceil());
Provider.of<FlwtchState>(context, listen: false).cwtch.SetMessageAttribute(profileOnion, conversation, 0, idx, "file-downloaded", "true");
//Provider.of<MessageMetadata>(context, listen: false).attributes |= 0x02;
ContactInfoState? contact = Provider.of<ProfileInfoState>(context).contactList.findContact(Provider.of<MessageMetadata>(context).senderHandle);
if (contact != null) {
Provider.of<FlwtchState>(context, listen: false).cwtch.CreateDownloadableFile(profileOnion, contact.identifier, widget.nameSuggestion, widget.fileKey());
@ -225,7 +225,6 @@ class FileBubbleState extends State<FileBubble> {
var manifestPath = file.path + ".manifest";
Provider.of<ProfileInfoState>(context, listen: false).downloadInit(widget.fileKey(), (widget.fileSize / 4096).ceil());
Provider.of<FlwtchState>(context, listen: false).cwtch.SetMessageAttribute(profileOnion, conversation, 0, idx, "file-downloaded", "true");
//Provider.of<MessageMetadata>(context, listen: false).flags |= 0x02;
ContactInfoState? contact = Provider.of<ProfileInfoState>(context, listen: false).contactList.findContact(Provider.of<MessageMetadata>(context).senderHandle);
if (contact != null) {
Provider.of<FlwtchState>(context, listen: false).cwtch.DownloadFile(profileOnion, contact.identifier, file.path, manifestPath, widget.fileKey());