From 797279d6d75ce493aea1e6a1b28ad668cdf47719 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Thu, 20 Jan 2022 13:59:54 -0800 Subject: [PATCH 1/4] Enable Sender Side Image Previews --- lib/cwtch/cwtchNotifier.dart | 11 +++++++++-- lib/models/profile.dart | 11 +++++++++++ lib/widgets/filebubble.dart | 30 ++++++++++++++++++++---------- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/lib/cwtch/cwtchNotifier.dart b/lib/cwtch/cwtchNotifier.dart index ea93c064..ddad1088 100644 --- a/lib/cwtch/cwtchNotifier.dart +++ b/lib/cwtch/cwtchNotifier.dart @@ -98,8 +98,10 @@ class CwtchNotifier { } if (profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(int.parse(data["ConversationID"])) == null) { profileCN.getProfile(data["ProfileOnion"])?.contactList.add(ContactInfoState(data["ProfileOnion"], int.parse(data["ConversationID"]), data["GroupID"], - blocked: false, // we created - accepted: true, // we created + blocked: false, + // we created + accepted: true, + // we created imagePath: data["PicturePath"], nickname: data["GroupName"], status: status, @@ -244,6 +246,11 @@ class CwtchNotifier { case "UpdatedProfileAttribute": if (data["Key"] == "public.profile.name") { profileCN.getProfile(data["ProfileOnion"])?.nickname = data["Data"]; + } else if (data["Key"].toString().endsWith(".path")) { + // local.conversation.filekey.path + List keyparts = data["Key"].toString().split("."); + String filekey = keyparts[2] + "." + keyparts[3]; + profileCN.getProfile(data["ProfileOnion"])?.downloadSetPathDangerous(filekey, data["Data"]); } else { EnvironmentConfig.debugLog("unhandled set attribute event: ${data['Key']}"); } diff --git a/lib/models/profile.dart b/lib/models/profile.dart index ddca5aba..9ae039ad 100644 --- a/lib/models/profile.dart +++ b/lib/models/profile.dart @@ -253,7 +253,18 @@ class ProfileInfoState extends ChangeNotifier { } } + void downloadSetPathDangerous(String fileKey, String path) { + 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(); + } + String? downloadFinalPath(String fileKey) { + var path = this._downloads[fileKey]; return this._downloads.containsKey(fileKey) ? this._downloads[fileKey]!.downloadedTo : null; } diff --git a/lib/widgets/filebubble.dart b/lib/widgets/filebubble.dart index 1d6c347c..dc0b4cfa 100644 --- a/lib/widgets/filebubble.dart +++ b/lib/widgets/filebubble.dart @@ -52,16 +52,28 @@ class FileBubbleState extends State { var borderRadiousEh = 15.0; var showFileSharing = Provider.of(context, listen: false).isExperimentEnabled(FileSharingExperiment); var prettyDate = DateFormat.yMd(Platform.localeName).add_jm().format(Provider.of(context).timestamp); - var downloadComplete = Provider.of(context).downloadComplete(widget.fileKey()); + 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 (downloadComplete) { - var lpath = path!.toLowerCase(); + + // If we haven't stored the filepath in message attributes then save it + if (downloadComplete && path == null && metadata.attributes["filepath"] != null) { + path = metadata.attributes["filepath"]; + } else if (downloadComplete && path != null && metadata.attributes["filepath"] == null) { + if (metadata.attributes["filepath"] == null) { + Provider.of(context).cwtch.SetMessageAttribute(metadata.profileOnion, metadata.conversationIdentifier, 0, metadata.messageID, "filepath", path); + } + } + + var fileKey = 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")) { if (myFile == null) { setState(() { - myFile = new File(path); + myFile = new File(path!); }); } } @@ -81,6 +93,8 @@ class FileBubbleState extends State { } else { senderDisplayStr = Provider.of(context).senderHandle; } + } else { + senderIsContact = true; } return LayoutBuilder(builder: (bcontext, constraints) { var wdgSender = Visibility( @@ -98,13 +112,9 @@ class FileBubbleState extends State { if (!showFileSharing) { wdgDecorations = Text('\u202F'); - } else if (fromMe) { - wdgDecorations = Visibility( - visible: widget.interactive, - child: MessageBubbleDecoration(ackd: Provider.of(context).ackd, errored: Provider.of(context).error, fromMe: fromMe, prettyDate: prettyDate)); - } else if (downloadComplete) { + } else if (downloadComplete && path != null) { // in this case, whatever marked download.complete would have also set the path - if (Provider.of(context).shouldPreview(path!)) { + if (Provider.of(context).shouldPreview(path)) { isPreview = true; wdgDecorations = Center( child: MouseRegion( From d095971cb3c2965b3c3cdba1e9102ef56bd97d82 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Thu, 20 Jan 2022 14:19:06 -0800 Subject: [PATCH 2/4] Sender side previews - fixing up PR comments --- lib/cwtch/cwtchNotifier.dart | 14 +++++++------- lib/models/profile.dart | 4 ++-- lib/widgets/filebubble.dart | 7 +------ 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/lib/cwtch/cwtchNotifier.dart b/lib/cwtch/cwtchNotifier.dart index ddad1088..f8ac337c 100644 --- a/lib/cwtch/cwtchNotifier.dart +++ b/lib/cwtch/cwtchNotifier.dart @@ -98,10 +98,8 @@ class CwtchNotifier { } if (profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(int.parse(data["ConversationID"])) == null) { profileCN.getProfile(data["ProfileOnion"])?.contactList.add(ContactInfoState(data["ProfileOnion"], int.parse(data["ConversationID"]), data["GroupID"], - blocked: false, - // we created - accepted: true, - // we created + blocked: false, // we created + accepted: true, // we created imagePath: data["PicturePath"], nickname: data["GroupName"], status: status, @@ -246,11 +244,13 @@ class CwtchNotifier { case "UpdatedProfileAttribute": if (data["Key"] == "public.profile.name") { profileCN.getProfile(data["ProfileOnion"])?.nickname = data["Data"]; - } else if (data["Key"].toString().endsWith(".path")) { + } else if (data["Key"].toString().startsWith("local.filesharing.") && data["Key"].toString().endsWith(".path")) { // local.conversation.filekey.path List keyparts = data["Key"].toString().split("."); - String filekey = keyparts[2] + "." + keyparts[3]; - profileCN.getProfile(data["ProfileOnion"])?.downloadSetPathDangerous(filekey, data["Data"]); + if (keyparts.length == 5) { + String filekey = keyparts[2] + "." + keyparts[3]; + profileCN.getProfile(data["ProfileOnion"])?.downloadSetPathForSender(filekey, data["Data"]); + } } else { EnvironmentConfig.debugLog("unhandled set attribute event: ${data['Key']}"); } diff --git a/lib/models/profile.dart b/lib/models/profile.dart index 9ae039ad..f11c9b0b 100644 --- a/lib/models/profile.dart +++ b/lib/models/profile.dart @@ -253,7 +253,8 @@ class ProfileInfoState extends ChangeNotifier { } } - void downloadSetPathDangerous(String fileKey, String path) { + // set the download path for the sender + void downloadSetPathForSender(String fileKey, String path) { this._downloads[fileKey] = FileDownloadProgress(1, DateTime.now()); this._downloads[fileKey]!.timeEnd = DateTime.now(); this._downloads[fileKey]!.chunksDownloaded = 1; @@ -264,7 +265,6 @@ class ProfileInfoState extends ChangeNotifier { } String? downloadFinalPath(String fileKey) { - var path = this._downloads[fileKey]; return this._downloads.containsKey(fileKey) ? this._downloads[fileKey]!.downloadedTo : null; } diff --git a/lib/widgets/filebubble.dart b/lib/widgets/filebubble.dart index dc0b4cfa..a79e884c 100644 --- a/lib/widgets/filebubble.dart +++ b/lib/widgets/filebubble.dart @@ -62,12 +62,9 @@ class FileBubbleState extends State { if (downloadComplete && path == null && metadata.attributes["filepath"] != null) { path = metadata.attributes["filepath"]; } else if (downloadComplete && path != null && metadata.attributes["filepath"] == null) { - if (metadata.attributes["filepath"] == null) { - Provider.of(context).cwtch.SetMessageAttribute(metadata.profileOnion, metadata.conversationIdentifier, 0, metadata.messageID, "filepath", path); - } + Provider.of(context).cwtch.SetMessageAttribute(metadata.profileOnion, metadata.conversationIdentifier, 0, metadata.messageID, "filepath", path); } - var fileKey = 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")) { @@ -93,8 +90,6 @@ class FileBubbleState extends State { } else { senderDisplayStr = Provider.of(context).senderHandle; } - } else { - senderIsContact = true; } return LayoutBuilder(builder: (bcontext, constraints) { var wdgSender = Visibility( From 6364ebffc6b53f93878b564b92c26be451c2c5be Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Thu, 20 Jan 2022 14:32:35 -0800 Subject: [PATCH 3/4] Update lcg --- LIBCWTCH-GO-MACOS.version | 2 +- LIBCWTCH-GO.version | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LIBCWTCH-GO-MACOS.version b/LIBCWTCH-GO-MACOS.version index c0ed5239..124e8a8e 100644 --- a/LIBCWTCH-GO-MACOS.version +++ b/LIBCWTCH-GO-MACOS.version @@ -1 +1 @@ -2022-01-20-12-53-v1.5.4-14-g6865ec1 \ No newline at end of file +2022-01-20-17-22-v1.5.4-16-ge0e1a4b \ No newline at end of file diff --git a/LIBCWTCH-GO.version b/LIBCWTCH-GO.version index ee031103..3513fd2f 100644 --- a/LIBCWTCH-GO.version +++ b/LIBCWTCH-GO.version @@ -1 +1 @@ -2022-01-20-17-53-v1.5.4-14-g6865ec1 \ No newline at end of file +2022-01-20-22-22-v1.5.4-16-ge0e1a4b \ No newline at end of file From 13c1a52442cd4b3a3ac4800ed8e3f5386cbe1f08 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Thu, 20 Jan 2022 14:42:45 -0800 Subject: [PATCH 4/4] Only allow path override for senders --- lib/models/profile.dart | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/models/profile.dart b/lib/models/profile.dart index f11c9b0b..dc1b6c58 100644 --- a/lib/models/profile.dart +++ b/lib/models/profile.dart @@ -255,13 +255,16 @@ class ProfileInfoState extends ChangeNotifier { // set the download path for the sender void downloadSetPathForSender(String fileKey, String path) { - 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(); + // only allow this override if we are the sender... + if (this._downloads.containsKey(fileKey) == false) { + 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(); + } } String? downloadFinalPath(String fileKey) {