소스 검색

fix timer registration conditions and call handleChatListUpdate() instead of refreshInBg() (which calls the core and is slow) to refresh the time labels in the chat list

cyberta 3 년 전
부모
커밋
78db953233
1개의 변경된 파일14개의 추가작업 그리고 6개의 파일을 삭제
  1. 14 6
      deltachat-ios/Controller/ChatListController.swift

+ 14 - 6
deltachat-ios/Controller/ChatListController.swift

@@ -250,11 +250,11 @@ class ChatListController: UITableViewController {
     private var isInitial = true
     private var isInitial = true
     @objc func applicationDidBecomeActive(_ notification: NSNotification) {
     @objc func applicationDidBecomeActive(_ notification: NSNotification) {
         if navigationController?.visibleViewController == self {
         if navigationController?.visibleViewController == self {
-            if isInitial {
-                isInitial = false
+            if !isInitial {
                 startTimer()
                 startTimer()
             }
             }
-            refreshInBg()
+            handleChatListUpdate()
+            isInitial = false
         }
         }
     }
     }
 
 
@@ -442,8 +442,16 @@ class ChatListController: UITableViewController {
     }
     }
 
 
     func handleChatListUpdate() {
     func handleChatListUpdate() {
-        tableView.reloadData()
-        handleEmptyStateLabel()
+        if Thread.isMainThread {
+            tableView.reloadData()
+            handleEmptyStateLabel()
+        } else {
+            DispatchQueue.main.async { [weak self] in
+                guard let self = self else { return }
+                self.tableView.reloadData()
+                self.handleEmptyStateLabel()
+            }
+        }
     }
     }
 
 
     private func handleEmptyStateLabel() {
     private func handleEmptyStateLabel() {
@@ -473,7 +481,7 @@ class ChatListController: UITableViewController {
             else { return }
             else { return }
             
             
             if appDelegate.appIsInForeground() {
             if appDelegate.appIsInForeground() {
-                self.refreshInBg()
+                self.handleChatListUpdate()
             } else {
             } else {
                 logger.warning("startTimer() must not be executed in background")
                 logger.warning("startTimer() must not be executed in background")
             }
             }