Only override path for Sender, not any other attributes.
continuous-integration/drone/pr Build is passing
Details
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:
parent
0a3837c8b5
commit
92374ad112
|
@ -255,16 +255,14 @@ class ProfileInfoState extends ChangeNotifier {
|
||||||
|
|
||||||
// set the download path for the sender
|
// set the download path for the sender
|
||||||
void downloadSetPathForSender(String fileKey, String path) {
|
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) {
|
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] = 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) {
|
String? downloadFinalPath(String fileKey) {
|
||||||
|
|
|
@ -53,18 +53,19 @@ class FileBubbleState extends State<FileBubble> {
|
||||||
var showFileSharing = Provider.of<Settings>(context, listen: false).isExperimentEnabled(FileSharingExperiment);
|
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 prettyDate = DateFormat.yMd(Platform.localeName).add_jm().format(Provider.of<MessageMetadata>(context).timestamp);
|
||||||
var metadata = Provider.of<MessageMetadata>(context);
|
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());
|
var path = Provider.of<ProfileInfoState>(context).downloadFinalPath(widget.fileKey());
|
||||||
|
|
||||||
// If we haven't stored the filepath in message attributes then save it
|
// 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"];
|
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);
|
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) {
|
if (downloadComplete && path != null) {
|
||||||
var lpath = path.toLowerCase();
|
var lpath = path.toLowerCase();
|
||||||
if (lpath.endsWith(".jpg") || lpath.endsWith(".jpeg") || lpath.endsWith(".png") || lpath.endsWith(".gif") || lpath.endsWith(".webp") || lpath.endsWith(".bmp")) {
|
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) {
|
if (Platform.isAndroid) {
|
||||||
Provider.of<ProfileInfoState>(context, listen: false).downloadInit(widget.fileKey(), (widget.fileSize / 4096).ceil());
|
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<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);
|
ContactInfoState? contact = Provider.of<ProfileInfoState>(context).contactList.findContact(Provider.of<MessageMetadata>(context).senderHandle);
|
||||||
if (contact != null) {
|
if (contact != null) {
|
||||||
Provider.of<FlwtchState>(context, listen: false).cwtch.CreateDownloadableFile(profileOnion, contact.identifier, widget.nameSuggestion, widget.fileKey());
|
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";
|
var manifestPath = file.path + ".manifest";
|
||||||
Provider.of<ProfileInfoState>(context, listen: false).downloadInit(widget.fileKey(), (widget.fileSize / 4096).ceil());
|
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<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);
|
ContactInfoState? contact = Provider.of<ProfileInfoState>(context, listen: false).contactList.findContact(Provider.of<MessageMetadata>(context).senderHandle);
|
||||||
if (contact != null) {
|
if (contact != null) {
|
||||||
Provider.of<FlwtchState>(context, listen: false).cwtch.DownloadFile(profileOnion, contact.identifier, file.path, manifestPath, widget.fileKey());
|
Provider.of<FlwtchState>(context, listen: false).cwtch.DownloadFile(profileOnion, contact.identifier, file.path, manifestPath, widget.fileKey());
|
||||||
|
|
Loading…
Reference in New Issue