From 0eb1b95811e8cd2a8f189f77fe1efb4834284525 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Mon, 12 Feb 2024 11:28:46 -0800 Subject: [PATCH 1/4] Fix Sender Preview for Image Files --- lib/widgets/filebubble.dart | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/widgets/filebubble.dart b/lib/widgets/filebubble.dart index 2e790cab..02605c3a 100644 --- a/lib/widgets/filebubble.dart +++ b/lib/widgets/filebubble.dart @@ -75,6 +75,7 @@ class FileBubbleState extends State { var flagStarted = Provider.of(context).attributes["file-downloaded"] == "true"; var borderRadius = 15.0; var showFileSharing = Provider.of(context).isExperimentEnabled(FileSharingExperiment); + var showImages = Provider.of(context).isExperimentEnabled(ImagePreviewsExperiment); DateTime messageDate = Provider.of(context).timestamp; var metadata = Provider.of(context); @@ -91,13 +92,13 @@ class FileBubbleState extends State { var downloadComplete = (fromMe && path != null) || Provider.of(context).downloadComplete(widget.fileKey()); var downloadInterrupted = Provider.of(context).downloadInterrupted(widget.fileKey()); + var previewable = widget.isPreview && myFile != null; 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 || myFile?.path != path) { setState(() { myFile = new File(path!); - // reset if (myFile?.existsSync() == false) { myFile = null; @@ -113,6 +114,8 @@ class FileBubbleState extends State { Provider.of(context).cwtch.SetMessageAttribute(metadata.profileOnion, metadata.conversationIdentifier, 0, metadata.messageID, "file-missing", "false"); } }); + } else if (myFile != null && fromMe) { + previewable = true; // allow previewing of images... } } } @@ -136,9 +139,9 @@ class FileBubbleState extends State { } // we don't preview a non downloaded file... - if (widget.isPreview && myFile != null) { + if (showImages && previewable) { return getPreview(context); - } else if (widget.isPreview && myFile == null) { + } else if (showFileSharing && (previewable || (widget.isPreview && myFile == null))) { return Row( children: [ Icon(CwtchIcons.attached_file_3, size: 32, color: Provider.of(context).theme.messageFromMeTextColor), From 88a8ac8ccadd45f7dffa6b657257114ceb5bbbf8 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Mon, 12 Feb 2024 11:37:40 -0800 Subject: [PATCH 2/4] Fix Height on Invitation Widgets --- lib/widgets/contactrow.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/widgets/contactrow.dart b/lib/widgets/contactrow.dart index c50ece85..1f4b85da 100644 --- a/lib/widgets/contactrow.dart +++ b/lib/widgets/contactrow.dart @@ -120,7 +120,7 @@ class _ContactRowState extends State { )), Container( padding: EdgeInsets.all(0), - height: Provider.of(context).fontScaling * 14.0 + 5.0, + height: contact.isInvitation ? Provider.of(context).fontScaling * 14.0 + 35.0 : Provider.of(context).fontScaling * 14.0 + 5.0, child: contact.isInvitation == true ? Wrap(alignment: WrapAlignment.start, direction: Axis.vertical, children: [ Padding( From 4ea0d4261c3cb4e36c56c188285ea828016b7f1b Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Mon, 12 Feb 2024 11:59:02 -0800 Subject: [PATCH 3/4] Properly handle image experiment flags when showing sender side images --- lib/widgets/filebubble.dart | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/widgets/filebubble.dart b/lib/widgets/filebubble.dart index 02605c3a..2879d721 100644 --- a/lib/widgets/filebubble.dart +++ b/lib/widgets/filebubble.dart @@ -92,10 +92,16 @@ class FileBubbleState extends State { var downloadComplete = (fromMe && path != null) || Provider.of(context).downloadComplete(widget.fileKey()); var downloadInterrupted = Provider.of(context).downloadInterrupted(widget.fileKey()); - var previewable = widget.isPreview && myFile != null; - if (downloadComplete && path != null) { + var isImagePreview = false; + if (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")) { + isImagePreview = true; + } + } + + if (downloadComplete && path != null) { + if (isImagePreview) { if (myFile == null || myFile?.path != path) { setState(() { myFile = new File(path!); @@ -114,8 +120,6 @@ class FileBubbleState extends State { Provider.of(context).cwtch.SetMessageAttribute(metadata.profileOnion, metadata.conversationIdentifier, 0, metadata.messageID, "file-missing", "false"); } }); - } else if (myFile != null && fromMe) { - previewable = true; // allow previewing of images... } } } @@ -138,10 +142,13 @@ class FileBubbleState extends State { } } - // we don't preview a non downloaded file... - if (showImages && previewable) { + // if we should show a preview i.e. we are in a quote bubble + // then do that here... + if (showImages && isImagePreview && widget.isPreview && myFile != null) { + // if the image exists then just show the image as a preview return getPreview(context); - } else if (showFileSharing && (previewable || (widget.isPreview && myFile == null))) { + } else if (showFileSharing && widget.isPreview) { + // otherwise just show a summary... return Row( children: [ Icon(CwtchIcons.attached_file_3, size: 32, color: Provider.of(context).theme.messageFromMeTextColor), @@ -165,9 +172,7 @@ class FileBubbleState extends State { if (!showFileSharing) { wdgDecorations = Text('\u202F'); - } else if (fromMe) { - wdgDecorations = Text('\u202F'); - } else if (downloadComplete && path != null) { + } else if ((fromMe || downloadComplete) && path != null) { // in this case, whatever marked download.complete would have also set the path if (myFile != null && Provider.of(context).shouldPreview(path)) { isPreview = true; @@ -181,6 +186,8 @@ class FileBubbleState extends State { pop(context, myFile!, widget.nameSuggestion); }, ))); + } else if (fromMe) { + wdgDecorations = Text('\u202F'); } else { wdgDecorations = Visibility( visible: widget.interactive, child: SelectableText(AppLocalizations.of(context)!.fileSavedTo + ': ' + path + '\u202F', style: Provider.of(context).scaleFonts(defaultTextStyle))); From 6ba6f76ee1111a8e81538fe9277e9d60c04df3cb Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Mon, 12 Feb 2024 12:03:21 -0800 Subject: [PATCH 4/4] Formatting and Consolidate Image Check --- lib/settings.dart | 7 +++- lib/views/globalsettingsexperimentsview.dart | 42 ++++++++++---------- lib/widgets/filebubble.dart | 5 +-- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/lib/settings.dart b/lib/settings.dart index ee75f6b5..786171ac 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -404,9 +404,12 @@ class Settings extends ChangeNotifier { // checks experiment settings and file extension for image previews // (ignores file size; if the user manually accepts the file, assume it's okay to preview) bool shouldPreview(String path) { + return isExperimentEnabled(ImagePreviewsExperiment) && isImage(path); + } + + bool isImage(String path) { var lpath = path.toLowerCase(); - return isExperimentEnabled(ImagePreviewsExperiment) && - (lpath.endsWith(".jpg") || lpath.endsWith(".jpeg") || lpath.endsWith(".png") || lpath.endsWith(".gif") || lpath.endsWith(".webp") || lpath.endsWith(".bmp")); + return (lpath.endsWith(".jpg") || lpath.endsWith(".jpeg") || lpath.endsWith(".png") || lpath.endsWith(".gif") || lpath.endsWith(".webp") || lpath.endsWith(".bmp")); } String get downloadPath => _downloadPath; diff --git a/lib/views/globalsettingsexperimentsview.dart b/lib/views/globalsettingsexperimentsview.dart index 2cd1bf34..9aa69275 100644 --- a/lib/views/globalsettingsexperimentsview.dart +++ b/lib/views/globalsettingsexperimentsview.dart @@ -163,28 +163,28 @@ class _GlobalSettingsExperimentsViewState extends State(context, listen: false).cwtch.IsBlodeuweddSupported(), - child: SwitchListTile( - title: Text(AppLocalizations.of(context)!.blodeuweddExperimentEnable), - subtitle: Provider.of(context, listen: false).cwtch.IsBlodeuweddSupported() - ? Text(AppLocalizations.of(context)!.blodeuweddDescription) - : Text(AppLocalizations.of(context)!.blodeuweddNotSupported), - value: Provider.of(context, listen: false).cwtch.IsBlodeuweddSupported() && settings.isExperimentEnabled(BlodeuweddExperiment), - onChanged: Provider.of(context, listen: false).cwtch.IsBlodeuweddSupported() - ? (bool value) { - if (value) { - settings.enableExperiment(BlodeuweddExperiment); - } else { - settings.disableExperiment(BlodeuweddExperiment); + visible: Provider.of(context, listen: false).cwtch.IsBlodeuweddSupported(), + child: SwitchListTile( + title: Text(AppLocalizations.of(context)!.blodeuweddExperimentEnable), + subtitle: Provider.of(context, listen: false).cwtch.IsBlodeuweddSupported() + ? Text(AppLocalizations.of(context)!.blodeuweddDescription) + : Text(AppLocalizations.of(context)!.blodeuweddNotSupported), + value: Provider.of(context, listen: false).cwtch.IsBlodeuweddSupported() && settings.isExperimentEnabled(BlodeuweddExperiment), + onChanged: Provider.of(context, listen: false).cwtch.IsBlodeuweddSupported() + ? (bool value) { + if (value) { + settings.enableExperiment(BlodeuweddExperiment); + } else { + settings.disableExperiment(BlodeuweddExperiment); + } + saveSettings(context); } - saveSettings(context); - } - : null, - activeTrackColor: settings.theme.defaultButtonColor, - inactiveTrackColor: settings.theme.defaultButtonDisabledColor, - inactiveThumbColor: settings.theme.defaultButtonDisabledColor, - secondary: Icon(Icons.assistant, color: settings.current().mainTextColor), - )), + : null, + activeTrackColor: settings.theme.defaultButtonColor, + inactiveTrackColor: settings.theme.defaultButtonDisabledColor, + inactiveThumbColor: settings.theme.defaultButtonDisabledColor, + secondary: Icon(Icons.assistant, color: settings.current().mainTextColor), + )), Visibility( visible: Provider.of(context, listen: false).cwtch.IsBlodeuweddSupported() && settings.isExperimentEnabled(BlodeuweddExperiment), child: CwtchFolderPicker( diff --git a/lib/widgets/filebubble.dart b/lib/widgets/filebubble.dart index 2879d721..df27041d 100644 --- a/lib/widgets/filebubble.dart +++ b/lib/widgets/filebubble.dart @@ -94,10 +94,7 @@ class FileBubbleState extends State { var isImagePreview = false; if (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")) { - isImagePreview = true; - } + isImagePreview = Provider.of(context).isImage(path); } if (downloadComplete && path != null) {