diff --git a/Linphone/UI/Main/ContentView.swift b/Linphone/UI/Main/ContentView.swift index 83eb74a19..f41f07872 100644 --- a/Linphone/UI/Main/ContentView.swift +++ b/Linphone/UI/Main/ContentView.swift @@ -405,7 +405,7 @@ struct ContentView: View { } else if index == 1 { historyListViewModel.resetFilterCallLogs() } else if index == 2 { - //TODO Conversations List reset + conversationsListViewModel.resetFilterConversations() } else if index == 3 { meetingsListViewModel.currentFilter = "" meetingsListViewModel.computeMeetingsList() @@ -455,7 +455,11 @@ struct ContentView: View { historyListViewModel.filterCallLogs(filter: text) } } else if index == 2 { - //TODO Conversations List reset + if text.isEmpty { + conversationsListViewModel.resetFilterConversations() + } else { + conversationsListViewModel.filterConversations(filter: text) + } } else if index == 3 { meetingsListViewModel.currentFilter = text meetingsListViewModel.computeMeetingsList() @@ -490,7 +494,7 @@ struct ContentView: View { } else if index == 1 { historyListViewModel.filterCallLogs(filter: text) } else if index == 2 { - //TODO Conversations List reset + conversationsListViewModel.filterConversations(filter: text) } else if index == 3 { meetingsListViewModel.currentFilter = text meetingsListViewModel.computeMeetingsList() diff --git a/Linphone/UI/Main/Conversations/Model/ConversationModel.swift b/Linphone/UI/Main/Conversations/Model/ConversationModel.swift index f2f3e27eb..b222a532c 100644 --- a/Linphone/UI/Main/Conversations/Model/ConversationModel.swift +++ b/Linphone/UI/Main/Conversations/Model/ConversationModel.swift @@ -37,6 +37,7 @@ class ConversationModel: ObservableObject { let isGroup: Bool let isReadOnly: Bool @Published var subject: String + @Published var participantsAddress: [String] = [] @Published var isComposing: Bool @Published var lastUpdateTime: time_t @Published var isMuted: Bool @@ -158,15 +159,17 @@ class ConversationModel: ObservableObject { ? self.contactsManager.getFriendWithAddress(address: self.chatRoom.participants.first?.address) : nil + var subjectTmp = "" + if self.isGroup { - self.subject = self.chatRoom.subject! + subjectTmp = self.chatRoom.subject! } else if addressFriend != nil { - self.subject = addressFriend!.name! + subjectTmp = addressFriend!.name! } else { if self.chatRoom.participants.first != nil && self.chatRoom.participants.first!.address != nil { - self.subject = self.chatRoom.participants.first!.address!.displayName != nil + subjectTmp = self.chatRoom.participants.first!.address!.displayName != nil ? self.chatRoom.participants.first!.address!.displayName! : self.chatRoom.participants.first!.address!.username! @@ -182,19 +185,27 @@ class ConversationModel: ObservableObject { }) ?? ContactAvatarModel( friend: nil, - name: self.subject, + name: subjectTmp, address: addressTmp, withPresence: false ) : ContactAvatarModel( friend: nil, - name: self.subject, + name: subjectTmp, address: addressTmp, withPresence: false ) + var participantsAddressTmp: [String] = [] + + self.chatRoom.participants.forEach { participant in + participantsAddressTmp.append(participant.address?.asStringUriOnly() ?? "") + } + DispatchQueue.main.async { + self.subject = subjectTmp self.avatarModel = avatarModelTmp + self.participantsAddress = participantsAddressTmp } } } diff --git a/Linphone/UI/Main/Conversations/ViewModel/ConversationsListViewModel.swift b/Linphone/UI/Main/Conversations/ViewModel/ConversationsListViewModel.swift index 71d92dac4..f5caace40 100644 --- a/Linphone/UI/Main/Conversations/ViewModel/ConversationsListViewModel.swift +++ b/Linphone/UI/Main/Conversations/ViewModel/ConversationsListViewModel.swift @@ -29,6 +29,8 @@ class ConversationsListViewModel: ObservableObject { private var mCoreSuscriptions = Set() @Published var conversationsList: [ConversationModel] = [] + var conversationsListTmp: [ConversationModel] = [] + @Published var unreadMessages: Int = 0 var selectedConversation: ConversationModel? @@ -43,17 +45,17 @@ class ConversationsListViewModel: ObservableObject { let account = core.defaultAccount let chatRooms = account?.chatRooms != nil ? account!.chatRooms : core.chatRooms - var conversationsListTmp: [ConversationModel] = [] + self.conversationsListTmp = [] chatRooms.forEach { chatRoom in if filter.isEmpty { let model = ConversationModel(chatRoom: chatRoom) - conversationsListTmp.append(model) + self.conversationsListTmp.append(model) } } DispatchQueue.main.async { - self.conversationsList = conversationsListTmp + self.conversationsList = self.conversationsListTmp } self.updateUnreadMessagesCount() @@ -198,4 +200,17 @@ class ConversationsListViewModel: ObservableObject { } } } + + func filterConversations(filter: String) { + conversationsList.removeAll() + conversationsListTmp.forEach { conversation in + if conversation.subject.lowercased().contains(filter.lowercased()) || !conversation.participantsAddress.filter({ $0.lowercased().contains(filter.lowercased()) }).isEmpty { + conversationsList.append(conversation) + } + } + } + + func resetFilterConversations() { + conversationsList = conversationsListTmp + } } diff --git a/Linphone/UI/Main/History/ViewModel/HistoryListViewModel.swift b/Linphone/UI/Main/History/ViewModel/HistoryListViewModel.swift index 3fb1db0f8..036365ef2 100644 --- a/Linphone/UI/Main/History/ViewModel/HistoryListViewModel.swift +++ b/Linphone/UI/Main/History/ViewModel/HistoryListViewModel.swift @@ -195,7 +195,7 @@ class HistoryListViewModel: ObservableObject { func filterCallLogs(filter: String) { callLogs.removeAll() callLogsTmp.forEach { callLog in - if callLog.addressName.contains(filter) { + if callLog.addressName.lowercased().contains(filter.lowercased()) { callLogs.append(callLog) } }