Pārlūkot izejas kodu

Merge pull request #972 from deltachat/async-markseen

fix micro-hangs
cyBerta 4 gadi atpakaļ
vecāks
revīzija
bc0c6da2de

+ 3 - 0
DcCore/DcCore/DC/events.swift

@@ -105,6 +105,9 @@ public func handleEvent(event: DcEvent) {
                     "chat_id": Int(data1),
                 ]
             )
+
+            let array = DcContext.shared.getFreshMessages()
+            UIApplication.shared.applicationIconBadgeNumber = array.count
         }
 
     case DC_EVENT_CHAT_MODIFIED:

+ 14 - 6
deltachat-ios/Chat/ChatViewController.swift

@@ -265,11 +265,13 @@ class ChatViewController: UITableViewController {
     override func viewDidAppear(_ animated: Bool) {
         super.viewDidAppear(animated)
         AppStateRestorer.shared.storeLastActiveChat(chatId: chatId)
+
         // things that do not affect the chatview
         // and are delayed after the view is displayed
-        dcContext.marknoticedChat(chatId: chatId)
-        let array = dcContext.getFreshMessages()
-        UIApplication.shared.applicationIconBadgeNumber = array.count
+        DispatchQueue.global(qos: .background).async { [weak self] in
+            guard let self = self else { return }
+            self.dcContext.marknoticedChat(chatId: self.chatId)
+        }
         startTimer()
     }
 
@@ -395,7 +397,9 @@ class ChatViewController: UITableViewController {
         if let indexPaths = tableView.indexPathsForVisibleRows {
             let visibleMessagesIds = indexPaths.map { UInt32(messageIds[$0.row]) }
             if !visibleMessagesIds.isEmpty {
-                dcContext.markSeenMessages(messageIds: visibleMessagesIds)
+                DispatchQueue.global(qos: .background).async { [weak self] in
+                    self?.dcContext.markSeenMessages(messageIds: visibleMessagesIds)
+                }
             }
         }
     }
@@ -861,7 +865,9 @@ class ChatViewController: UITableViewController {
 
     func updateMessage(_ messageId: Int) {
         if messageIds.firstIndex(where: { $0 == messageId }) != nil {
-            dcContext.markSeenMessages(messageIds: [UInt32(messageId)])
+            DispatchQueue.global(qos: .background).async { [weak self] in
+                self?.dcContext.markSeenMessages(messageIds: [UInt32(messageId)])
+            }
             let wasLastSectionVisible = self.isLastRowVisible()
             tableView.reloadData()
             if wasLastSectionVisible {
@@ -876,7 +882,9 @@ class ChatViewController: UITableViewController {
     }
 
     func insertMessage(_ message: DcMsg) {
-        dcContext.markSeenMessages(messageIds: [UInt32(message.id)])
+        DispatchQueue.global(qos: .background).async { [weak self] in
+            self?.dcContext.markSeenMessages(messageIds: [UInt32(message.id)])
+        }
         messageIds.append(message.id)
         emptyStateView.isHidden = true
 

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

@@ -348,10 +348,14 @@ class ChatListController: UITableViewController {
             self.showChat(chatId: chat.id)
         }))
         alert.addAction(UIAlertAction(title: String.localized("not_now"), style: .default, handler: { _ in
-            dcContact.marknoticed()
+            DispatchQueue.global(qos: .background).async {
+                dcContact.marknoticed()
+            }
         }))
         alert.addAction(UIAlertAction(title: String.localized("menu_block_contact"), style: .destructive, handler: { _ in
-            dcContact.block()
+            DispatchQueue.global(qos: .background).async {
+                dcContact.block()
+            }
         }))
         alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel))
         present(alert, animated: true, completion: nil)