Browse Source

Merge pull request #1554 from deltachat/timestamps

always refresh chatlist in background if app became active again
cyBerta 3 years ago
parent
commit
28b2b46c49
1 changed files with 13 additions and 5 deletions
  1. 13 5
      deltachat-ios/Controller/ChatListController.swift

+ 13 - 5
deltachat-ios/Controller/ChatListController.swift

@@ -251,10 +251,10 @@ class ChatListController: UITableViewController {
     @objc func applicationDidBecomeActive(_ notification: NSNotification) {
         if navigationController?.visibleViewController == self {
             if !isInitial {
-                isInitial = false
                 startTimer()
-                refreshInBg()
+                handleChatListUpdate()
             }
+            isInitial = false
         }
     }
 
@@ -442,8 +442,16 @@ class ChatListController: UITableViewController {
     }
 
     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() {
@@ -473,7 +481,7 @@ class ChatListController: UITableViewController {
             else { return }
             
             if appDelegate.appIsInForeground() {
-                self.refreshInBg()
+                self.handleChatListUpdate()
             } else {
                 logger.warning("startTimer() must not be executed in background")
             }