forked from mirrors/linphone-iphone
Add a search filter for the conversation list
This commit is contained in:
parent
8f8877b759
commit
4ec30c477d
4 changed files with 42 additions and 12 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ class ConversationsListViewModel: ObservableObject {
|
|||
private var mCoreSuscriptions = Set<AnyCancellable?>()
|
||||
|
||||
@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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue