소스 검색

remove message observers before deleting contact requests to avoid careless calls to dcContext

cyberta 4 년 전
부모
커밋
969617a5f6
1개의 변경된 파일10개의 추가작업 그리고 4개의 파일을 삭제
  1. 10 4
      deltachat-ios/Chat/ChatViewController.swift

+ 10 - 4
deltachat-ios/Chat/ChatViewController.swift

@@ -464,6 +464,14 @@ class ChatViewController: UITableViewController {
         AppStateRestorer.shared.resetLastActiveChat()
         handleUserVisibility(isVisible: false)
         
+        removeMessageObservers()
+        let nc = NotificationCenter.default
+        nc.removeObserver(self, name: UIApplication.didBecomeActiveNotification, object: nil)
+        nc.removeObserver(self, name: UIApplication.willResignActiveNotification, object: nil)
+        audioController.stopAnyOngoingPlaying()
+    }
+    
+    private func removeMessageObservers() {
         let nc = NotificationCenter.default
         if let msgChangedObserver = self.msgChangedObserver {
             nc.removeObserver(msgChangedObserver)
@@ -474,9 +482,6 @@ class ChatViewController: UITableViewController {
         if let ephemeralTimerModifiedObserver = self.ephemeralTimerModifiedObserver {
             nc.removeObserver(ephemeralTimerModifiedObserver)
         }
-        nc.removeObserver(self, name: UIApplication.didBecomeActiveNotification, object: nil)
-        nc.removeObserver(self, name: UIApplication.willResignActiveNotification, object: nil)
-        audioController.stopAnyOngoingPlaying()
     }
 
     override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
@@ -1059,8 +1064,9 @@ class ChatViewController: UITableViewController {
         confirmationAlert(title: title, actionTitle: String.localized("delete"), actionStyle: .destructive,
                           actionHandler: { [weak self] _ in
                             guard let self = self else { return }
+                            // remove message observers early to avoid careless calls to dcContext methods
+                            self.removeMessageObservers()
                             self.dcContext.deleteChat(chatId: self.chatId)
-
                             self.navigationController?.popViewController(animated: true)
                           })
     }