From ffe8c0fd458afd2697176ae09746a0a570547a48 Mon Sep 17 00:00:00 2001 From: QuentinArguillere Date: Mon, 24 Jun 2024 17:45:58 +0200 Subject: [PATCH] Add filtering for conferences --- Linphone/UI/Main/ContentView.swift | 21 ++++++++++---- .../ViewModel/MeetingsListViewModel.swift | 29 +++++++++++++++---- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/Linphone/UI/Main/ContentView.swift b/Linphone/UI/Main/ContentView.swift index c09d8a1e6..6fd3e2e32 100644 --- a/Linphone/UI/Main/ContentView.swift +++ b/Linphone/UI/Main/ContentView.swift @@ -355,7 +355,7 @@ struct ContentView: View { } } } label: { - Image(index == 0 ? "funnel" : "dots-three-vertical") + Image(index == 0 ? "funnel" : (index == 3 ? "calendar" : "dots-three-vertical")) .renderingMode(.template) .resizable() .foregroundStyle(.white) @@ -390,8 +390,11 @@ struct ContentView: View { sourceFlags: MagicSearch.Source.Friends.rawValue | MagicSearch.Source.LdapServers.rawValue) } else if index == 1 { historyListViewModel.resetFilterCallLogs() - } else { + } else if index == 2 { //TODO Conversations List reset + } else if index == 3 { + meetingsListViewModel.currentFilter = "" + meetingsListViewModel.computeMeetingsList() } } label: { Image("caret-left") @@ -431,8 +434,11 @@ struct ContentView: View { sourceFlags: MagicSearch.Source.Friends.rawValue | MagicSearch.Source.LdapServers.rawValue) } else if index == 1 { historyListViewModel.filterCallLogs(filter: text) - } else { - //TODO Conversations List Filter + } else if index == 2 { + //TODO Conversations List reset + } else if index == 3 { + meetingsListViewModel.currentFilter = text + meetingsListViewModel.computeMeetingsList() } } } else { @@ -461,8 +467,11 @@ struct ContentView: View { sourceFlags: MagicSearch.Source.Friends.rawValue | MagicSearch.Source.LdapServers.rawValue) } else if index == 1 { historyListViewModel.filterCallLogs(filter: text) - } else { - //TODO Conversations List Filter + } else if index == 2 { + //TODO Conversations List reset + } else if index == 3 { + meetingsListViewModel.currentFilter = text + meetingsListViewModel.computeMeetingsList() } } } diff --git a/Linphone/UI/Main/Meetings/ViewModel/MeetingsListViewModel.swift b/Linphone/UI/Main/Meetings/ViewModel/MeetingsListViewModel.swift index 069fb18fd..d48b7578c 100644 --- a/Linphone/UI/Main/Meetings/ViewModel/MeetingsListViewModel.swift +++ b/Linphone/UI/Main/Meetings/ViewModel/MeetingsListViewModel.swift @@ -30,6 +30,7 @@ class MeetingsListViewModel: ObservableObject { @Published var meetingsList: [MeetingsListItemModel] = [] @Published var currentFilter = "" + @Published var todayIdx = 0 init() { coreContext.doOnCoreQueue { core in @@ -42,7 +43,8 @@ class MeetingsListViewModel: ObservableObject { } func computeMeetingsList() { - let filter = self.currentFilter + let filter = self.currentFilter.uppercased() + let isFiltering = !filter.isEmpty coreContext.doOnCoreQueue { core in var confInfoList: [ConferenceInfo] = [] @@ -55,8 +57,9 @@ class MeetingsListViewModel: ObservableObject { } var meetingsListTmp: [MeetingsListItemModel] = [] - var previousModel: MeetingModel? var meetingForTodayFound = false + var currentIdx = 0 + var todayIdx = 0 for confInfo in confInfoList { if confInfo.duration == 0 { continue }// This isn't a scheduled conference, don't display it var add = true @@ -72,24 +75,40 @@ class MeetingsListViewModel: ObservableObject { if add { let model = MeetingModel(conferenceInfo: confInfo) - if !meetingForTodayFound { + if !meetingForTodayFound && !isFiltering { if model.isToday { meetingForTodayFound = true + todayIdx = currentIdx } else if model.isAfterToday { // If no meeting was found for today, insert "Today" fake model before the next meeting to come meetingsListTmp.append(MeetingsListItemModel(meetingModel: nil)) meetingForTodayFound = true + todayIdx = currentIdx } } - meetingsListTmp.append(MeetingsListItemModel(meetingModel: model)) - previousModel = model + var matchFilter = !isFiltering + if isFiltering { + matchFilter = matchFilter || confInfo.subject?.uppercased().contains(filter) ?? false + matchFilter = matchFilter || confInfo.description?.uppercased().contains(filter) ?? false + matchFilter = matchFilter || confInfo.organizer?.asStringUriOnly().uppercased().contains(filter) ?? false + for pInfo in confInfo.participantInfos { + matchFilter = matchFilter || pInfo.address?.asStringUriOnly().uppercased().contains(filter) ?? false + } + } + + if matchFilter { + meetingsListTmp.append(MeetingsListItemModel(meetingModel: model)) + currentIdx += 1 + } } } DispatchQueue.main.sync { + self.todayIdx = todayIdx self.meetingsList = meetingsListTmp } } } + }