Browse Source

only open chat on notification tap, if the chat is not already visible

cyberta 3 years ago
parent
commit
8b38b2c47a
2 changed files with 12 additions and 1 deletions
  1. 3 1
      deltachat-ios/AppDelegate.swift
  2. 9 0
      deltachat-ios/Coordinator/AppCoordinator.swift

+ 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)
+                 }
              }
         }
 

+ 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)