From 75588af0e28deeb225358e1ac01c9b917e1a0ef6 Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Wed, 6 Nov 2024 15:57:44 +0100 Subject: [PATCH] Add nil check for self.displayedConversation in ComputeComposingLabel --- .../ViewModel/ConversationViewModel.swift | 78 ++++++++++--------- 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift b/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift index 055e358d6..4b71fad8d 100644 --- a/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift +++ b/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift @@ -1862,48 +1862,50 @@ class ConversationViewModel: ObservableObject { } func computeComposingLabel() { - let composing = self.displayedConversation!.chatRoom.isRemoteComposing - - if !composing { - DispatchQueue.main.async { - withAnimation { - self.composingLabel = "" + if self.displayedConversation != nil { + let composing = self.displayedConversation!.chatRoom.isRemoteComposing + + if !composing { + DispatchQueue.main.async { + withAnimation { + self.composingLabel = "" + } + } + return + } + + var composingFriends: [String] = [] + var label = "" + + for address in self.displayedConversation!.chatRoom.composingAddresses { + if let addressCleaned = address.clone() { + addressCleaned.clean() + + if let avatar = self.participantConversationModel.first(where: {$0.address == addressCleaned.asStringUriOnly()}) { + let name = avatar.name + composingFriends.append(name) + label += "\(name), " + } } } - return - } - - var composingFriends: [String] = [] - var label = "" - - for address in self.displayedConversation!.chatRoom.composingAddresses { - if let addressCleaned = address.clone() { - addressCleaned.clean() + + if !composingFriends.isEmpty { + label = String(label.dropLast(2)) - if let avatar = self.participantConversationModel.first(where: {$0.address == addressCleaned.asStringUriOnly()}) { - let name = avatar.name - composingFriends.append(name) - label += "\(name), " + let format = composingFriends.count > 1 + ? String(format: NSLocalizedString("conversation_composing_label_multiple", comment: ""), label) + : String(format: NSLocalizedString("conversation_composing_label_single", comment: ""), label) + + DispatchQueue.main.async { + withAnimation { + self.composingLabel = format + } } - } - } - - if !composingFriends.isEmpty { - label = String(label.dropLast(2)) - - let format = composingFriends.count > 1 - ? String(format: NSLocalizedString("conversation_composing_label_multiple", comment: ""), label) - : String(format: NSLocalizedString("conversation_composing_label_single", comment: ""), label) - - DispatchQueue.main.async { - withAnimation { - self.composingLabel = format - } - } - } else { - DispatchQueue.main.async { - withAnimation { - self.composingLabel = "" + } else { + DispatchQueue.main.async { + withAnimation { + self.composingLabel = "" + } } } }