Fix Sender Preview for Image Files

This commit is contained in:
Sarah Jamie Lewis 2024-02-12 11:28:46 -08:00
parent e0546eb502
commit 0eb1b95811
1 changed files with 6 additions and 3 deletions

View File

@ -75,6 +75,7 @@ class FileBubbleState extends State<FileBubble> {
var flagStarted = Provider.of<MessageMetadata>(context).attributes["file-downloaded"] == "true";
var borderRadius = 15.0;
var showFileSharing = Provider.of<Settings>(context).isExperimentEnabled(FileSharingExperiment);
var showImages = Provider.of<Settings>(context).isExperimentEnabled(ImagePreviewsExperiment);
DateTime messageDate = Provider.of<MessageMetadata>(context).timestamp;
var metadata = Provider.of<MessageMetadata>(context);
@ -91,13 +92,13 @@ 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 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<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...
}
}
}
@ -136,9 +139,9 @@ class FileBubbleState extends State<FileBubble> {
}
// 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<Settings>(context).theme.messageFromMeTextColor),