Fix downloaded image crash and display error image instead

This commit is contained in:
Benoit Martins 2024-07-16 14:17:31 +02:00
parent 00eb9c4f7c
commit 39363f1096
2 changed files with 38 additions and 4 deletions

View file

@ -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

View file

@ -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!)