Эх сурвалжийг харах

Merge pull request #1424 from deltachat/fix_drafts_on_notification_tap

Fix drafts on notification tap
cyBerta 3 жил өмнө
parent
commit
2e1263f9b4

+ 3 - 1
deltachat-ios/AppDelegate.swift

@@ -457,7 +457,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
             let userInfo = response.notification.request.content.userInfo
              if let chatId = userInfo["chat_id"] as? Int,
                  let msgId = userInfo["message_id"] as? Int {
-                 appCoordinator.showChat(chatId: chatId, msgId: msgId, animated: false, clearViewControllerStack: true)
+                 if !appCoordinator.isShowingChat(chatId: chatId) {
+                     appCoordinator.showChat(chatId: chatId, msgId: msgId, animated: false, clearViewControllerStack: true)
+                 }
              }
         }
 

+ 2 - 1
deltachat-ios/Chat/ChatViewController.swift

@@ -478,6 +478,7 @@ class ChatViewController: UITableViewController {
         if parent == nil {
             // logger.debug("chat observer: remove")
             removeObservers()
+            draft.save(context: dcContext)
         } else {
             // logger.debug("chat observer: setup")
             setupObservers()
@@ -622,6 +623,7 @@ class ChatViewController: UITableViewController {
     @objc func applicationWillResignActive(_ notification: NSNotification) {
         if navigationController?.visibleViewController == self {
             handleUserVisibility(isVisible: false)
+            draft.save(context: dcContext)
         }
     }
     
@@ -632,7 +634,6 @@ class ChatViewController: UITableViewController {
             markSeenMessagesInVisibleArea()
         } else {
             stopTimer()
-            draft.save(context: dcContext)
         }
     }
 

+ 9 - 0
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -94,6 +94,15 @@ class AppCoordinator {
         }
     }
 
+    func isShowingChat(chatId: Int) -> Bool {
+        if let rootController = self.tabBarController.selectedViewController as? UINavigationController,
+           let chatViewController = rootController.viewControllers.last as? ChatViewController,
+           chatViewController.chatId == chatId {
+            return true
+        }
+        return false
+    }
+
     func showChat(chatId: Int, msgId: Int? = nil, animated: Bool = true, clearViewControllerStack: Bool = false) {
         showTab(index: chatsTab)