From d7a761561607b1ba4d78f6a00f27e98a11e2215e Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Wed, 15 May 2024 10:07:19 +0200 Subject: [PATCH] FIx avatar in conversation list --- Linphone/Contacts/ContactsManager.swift | 9 ++++---- .../Model/ConversationModel.swift | 23 ++++++++----------- .../ViewModel/ConversationViewModel.swift | 10 ++++++-- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Linphone/Contacts/ContactsManager.swift b/Linphone/Contacts/ContactsManager.swift index a228dbb5b..c81f8c0dd 100644 --- a/Linphone/Contacts/ContactsManager.swift +++ b/Linphone/Contacts/ContactsManager.swift @@ -306,13 +306,12 @@ final class ContactsManager: ObservableObject { let clonedAddress = address.clone() clonedAddress!.clean() let sipUri = clonedAddress!.asStringUriOnly() + if friendList != nil { var friend: Friend? - self.coreContext.doOnCoreQueue { _ in - friend = self.friendList!.friends.first(where: {$0.addresses.contains(where: {$0.asStringUriOnly() == sipUri})}) - if friend == nil { - friend = self.linphoneFriendList!.friends.first(where: {$0.addresses.contains(where: {$0.asStringUriOnly() == sipUri})}) - } + friend = self.friendList!.friends.first(where: {$0.addresses.contains(where: {$0.asStringUriOnly() == sipUri})}) + if friend == nil { + friend = self.linphoneFriendList!.friends.first(where: {$0.addresses.contains(where: {$0.asStringUriOnly() == sipUri})}) } return friend diff --git a/Linphone/UI/Main/Conversations/Model/ConversationModel.swift b/Linphone/UI/Main/Conversations/Model/ConversationModel.swift index 8fdc88ef4..0311c4e8e 100644 --- a/Linphone/UI/Main/Conversations/Model/ConversationModel.swift +++ b/Linphone/UI/Main/Conversations/Model/ConversationModel.swift @@ -221,19 +221,15 @@ class ConversationModel: ObservableObject { func refreshAvatarModel() { coreContext.doOnCoreQueue { _ in - let addressFriend = - (self.chatRoom.participants.first != nil && self.chatRoom.participants.first!.address != nil) - ? self.contactsManager.getFriendWithAddress(address: self.chatRoom.participants.first!.address!) - : nil - - if addressFriend != nil && !self.isGroup { - let avatarModelTmp = ContactsManager.shared.avatarListModel.first(where: { - $0.friend!.name == addressFriend!.name - && $0.friend!.address!.asStringUriOnly() == addressFriend!.address!.asStringUriOnly() - }) ?? ContactAvatarModel(friend: nil, name: self.subject, withPresence: false) - - DispatchQueue.main.async { - self.avatarModel = avatarModelTmp + if !self.isGroup { + if self.chatRoom.participants.first != nil && self.chatRoom.participants.first!.address != nil { + let avatarModelTmp = ContactAvatarModel.getAvatarModelFromAddress(address: self.chatRoom.participants.first!.address!) + let subjectTmp = avatarModelTmp.name + + DispatchQueue.main.async { + self.avatarModel = avatarModelTmp + self.subject = subjectTmp + } } } } @@ -242,7 +238,6 @@ class ConversationModel: ObservableObject { func downloadContent(chatMessage: ChatMessage, content: Content) { coreContext.doOnCoreQueue { _ in let result = chatMessage.downloadContent(content: content) - print("resultresult download \(result)") } } diff --git a/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift b/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift index 02d7fdd6c..20fd96d87 100644 --- a/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift +++ b/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift @@ -183,10 +183,16 @@ class ConversationViewModel: ObservableObject { if eventLog.chatMessage != nil && !eventLog.chatMessage!.contents.isEmpty { eventLog.chatMessage!.contents.forEach { content in if content.isText { - print("contentscontents text") contentText = content.utf8Text ?? "" } else { - print("contentscontents \(content.isText)") + if content.filePath == nil || content.filePath!.isEmpty { + self.downloadContent(chatMessage: eventLog.chatMessage!, content: content) + } else { + if URL(string: self.getNewFilePath(name: content.name ?? "")) != nil { + let attachment = Attachment(id: UUID().uuidString, url: URL(string: self.getNewFilePath(name: content.name ?? ""))!, type: (content.name?.lowercased().hasSuffix("gif"))! ? .gif : .image) + attachmentList.append(attachment) + } + } } } }