From 39363f109604e7e73937ed96f2c002641b014f1e Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Tue, 16 Jul 2024 14:17:31 +0200 Subject: [PATCH] Fix downloaded image crash and display error image instead --- Linphone/Core/CoreContext.swift | 1 + .../ViewModel/ConversationViewModel.swift | 41 +++++++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Linphone/Core/CoreContext.swift b/Linphone/Core/CoreContext.swift index 5e749d05c..120aeab2b 100644 --- a/Linphone/Core/CoreContext.swift +++ b/Linphone/Core/CoreContext.swift @@ -125,6 +125,7 @@ final class CoreContext: ObservableObject { self.mCore.videoPreviewEnabled = false self.mCore.fecEnabled = true self.mCore.friendListSubscriptionEnabled = true + self.mCore.maxSizeForAutoDownloadIncomingFiles = 0 self.mCore.config!.setBool(section: "sip", key: "auto_answer_replacing_calls", value: false) self.mCoreSuscriptions.insert(self.mCore.publisher?.onGlobalStateChanged?.postOnCoreQueue { (cbVal: (core: Core, state: GlobalState, message: String)) in diff --git a/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift b/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift index 8e416ccbe..e59068dc7 100644 --- a/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift +++ b/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift @@ -135,7 +135,18 @@ class ConversationViewModel: ObservableObject { contentText = content.utf8Text ?? "" } else if content.name != nil && !content.name!.isEmpty { if content.filePath == nil || content.filePath!.isEmpty { - self.downloadContent(chatMessage: eventLog.chatMessage!, content: content) + //self.downloadContent(chatMessage: eventLog.chatMessage!, content: content) + let path = URL(string: self.getNewFilePath(name: content.name ?? "")) + + if path != nil { + let attachment = + Attachment( + id: UUID().uuidString, + url: path!, + type: .image + ) + attachmentList.append(attachment) + } } else { if content.type != "video" { let path = URL(string: self.getNewFilePath(name: content.name ?? "")) @@ -238,7 +249,18 @@ class ConversationViewModel: ObservableObject { contentText = content.utf8Text ?? "" } else if content.name != nil && !content.name!.isEmpty { if content.filePath == nil || content.filePath!.isEmpty { - self.downloadContent(chatMessage: eventLog.chatMessage!, content: content) + //self.downloadContent(chatMessage: eventLog.chatMessage!, content: content) + let path = URL(string: self.getNewFilePath(name: content.name ?? "")) + + if path != nil { + let attachment = + Attachment( + id: UUID().uuidString, + url: path!, + type: .image + ) + attachmentList.append(attachment) + } } else { if content.type != "video" { let path = URL(string: self.getNewFilePath(name: content.name ?? "")) @@ -339,7 +361,18 @@ class ConversationViewModel: ObservableObject { contentText = content.utf8Text ?? "" } else { if content.filePath == nil || content.filePath!.isEmpty { - self.downloadContent(chatMessage: eventLog.chatMessage!, content: content) + //self.downloadContent(chatMessage: eventLog.chatMessage!, content: content) + let path = URL(string: self.getNewFilePath(name: content.name ?? "")) + + if path != nil { + let attachment = + Attachment( + id: UUID().uuidString, + url: path!, + type: .image + ) + attachmentList.append(attachment) + } } else if content.name != nil && !content.name!.isEmpty { if content.type != "video" { let path = URL(string: self.getNewFilePath(name: content.name ?? "")) @@ -601,7 +634,7 @@ class ConversationViewModel: ObservableObject { func downloadContent(chatMessage: ChatMessage, content: Content) { //Log.debug("[ConversationViewModel] Starting downloading content for file \(model.fileName)") - if content.filePath == nil || content.filePath!.isEmpty { + if !chatMessage.isFileTransferInProgress && (content.filePath == nil || content.filePath!.isEmpty) { let contentName = content.name if contentName != nil { let isImage = FileUtil.isExtensionImage(path: contentName!)