Parcourir la source

refresh chatlist in bg

B. Petersen il y a 4 ans
Parent
commit
da8525051c

+ 3 - 1
deltachat-ios/Controller/ChatListController.swift

@@ -173,7 +173,9 @@ class ChatListController: UITableViewController {
     @objc func applicationDidBecomeActive(_ notification: NSNotification) {
         if navigationController?.visibleViewController == self {
             startTimer()
-            viewModel.refreshData()
+            DispatchQueue.global(qos: .userInteractive).async { [weak self] in
+                self?.viewModel.refreshData()
+            }
         }
     }
 

+ 8 - 2
deltachat-ios/ViewModel/ChatListViewModel.swift

@@ -79,8 +79,14 @@ class ChatListViewModel: NSObject, ChatListViewModelProtocol {
             gclFlags |= DC_GCL_FOR_FORWARDING
         }
         self.chatList = dcContext.getChatlist(flags: gclFlags, queryString: nil, queryId: 0)
-        if notifyListener {
-            onChatListUpdate?()
+        if notifyListener, let onChatListUpdate = onChatListUpdate {
+            if Thread.isMainThread {
+                onChatListUpdate()
+            } else {
+                DispatchQueue.main.async {
+                    onChatListUpdate()
+                }
+            }
         }
     }