Properly handle image experiment flags when showing sender side images

This commit is contained in:
Sarah Jamie Lewis 2024-02-12 11:59:02 -08:00
parent 88a8ac8cca
commit 4ea0d4261c
1 changed files with 17 additions and 10 deletions

View File

@ -92,10 +92,16 @@ class FileBubbleState extends State<FileBubble> {
var downloadComplete = (fromMe && path != null) || Provider.of<ProfileInfoState>(context).downloadComplete(widget.fileKey());
var downloadInterrupted = Provider.of<ProfileInfoState>(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<FileBubble> {
Provider.of<FlwtchState>(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<FileBubble> {
}
}
// 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<Settings>(context).theme.messageFromMeTextColor),
@ -165,9 +172,7 @@ class FileBubbleState extends State<FileBubble> {
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<Settings>(context).shouldPreview(path)) {
isPreview = true;
@ -181,6 +186,8 @@ class FileBubbleState extends State<FileBubble> {
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<Settings>(context).scaleFonts(defaultTextStyle)));