Merge pull request 'Only override path for Sender, not any other attributes.' (#329) from sender_size into trunk
continuous-integration/drone/push Build is passing Details

Reviewed-on: #329
Reviewed-by: erinn <erinn@openprivacy.ca>
This commit is contained in:
erinn 2022-01-21 20:12:54 +00:00
commit 508592f80c
2 changed files with 16 additions and 15 deletions

View File

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

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());