Эх сурвалжийг харах

getContacts now takes optional querystring for filtering - used in chatsSearch

nayooti 5 жил өмнө
parent
commit
f7dafeddd5

+ 2 - 2
deltachat-ios/DC/Wrapper.swift

@@ -26,8 +26,8 @@ class DcContext {
         return dc_delete_contact(self.contextPointer, UInt32(contactId)) == 1
     }
 
-    func getContacts(flags: Int32) -> [Int] {
-        let cContacts = dc_get_contacts(self.contextPointer, UInt32(flags), nil)
+    func getContacts(flags: Int32, queryString: String? = nil) -> [Int] {
+        let cContacts = dc_get_contacts(self.contextPointer, UInt32(flags), queryString)
         return Utils.copyAndFreeArray(inputArray: cContacts)
     }
 

+ 11 - 13
deltachat-ios/ViewModel/ChatListViewModel.swift

@@ -211,14 +211,14 @@ extension ChatListViewModel: UISearchResultsUpdating {
                 titleHighlightIndexes: chatTitleIndexes
             )
             filteredChatCellViewModels.append(viewModel)
-            
+
         }
 
         filteredChats.cellData = filteredChatCellViewModels
 
         // #2 contacts with searchPattern in name or in email
         var filteredContactCellViewModels: [ContactCellViewModel] = []
-        let contactIds: [Int] = dcContext.getContacts(flags: DC_GCL_ADD_SELF)
+        let contactIds: [Int] = dcContext.getContacts(flags: DC_GCL_ADD_SELF, queryString: searchText)
 
         let contacts = contactIds.map { return DcContact(id: $0) }
 
@@ -226,17 +226,15 @@ extension ChatListViewModel: UISearchResultsUpdating {
             let nameIndexes = contact.displayName.containsExact(subSequence: searchText)
             let emailIndexes = contact.email.containsExact(subSequence: searchText)
 
-            if !nameIndexes.isEmpty || !emailIndexes.isEmpty {
-                // contact contains searchText
-                let viewModel = ContactCellViewModel(
-                    contactData: ContactCellData(
-                        contactId: contact.id
-                    ),
-                    titleHighlightIndexes: nameIndexes,
-                    subtitleHighlightIndexes: emailIndexes
-                )
-                filteredContactCellViewModels.append(viewModel)
-            }
+            // contact contains searchText
+            let viewModel = ContactCellViewModel(
+                contactData: ContactCellData(
+                    contactId: contact.id
+                ),
+                titleHighlightIndexes: nameIndexes,
+                subtitleHighlightIndexes: emailIndexes
+            )
+            filteredContactCellViewModels.append(viewModel)
         }
         filteredContacts.cellData = filteredContactCellViewModels