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

jump to messages from notification

cyberta 4 жил өмнө
parent
commit
83f54db100

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

@@ -7,7 +7,6 @@ public let dcNotificationImexProgress = Notification.Name(rawValue: "dcNotificat
 public let dcNotificationConfigureProgress = Notification.Name(rawValue: "MrEventConfigureProgress")
 public let dcNotificationSecureJoinerProgress = Notification.Name(rawValue: "MrEventSecureJoinerProgress")
 public let dcNotificationSecureInviterProgress = Notification.Name(rawValue: "MrEventSecureInviterProgress")
-public let dcNotificationViewChat = Notification.Name(rawValue: "MrEventViewChat")
 public let dcNotificationContactChanged = Notification.Name(rawValue: "MrEventContactsChanged")
 public let dcNotificationChatModified = Notification.Name(rawValue: "dcNotificationChatModified")
 public let dcEphemeralTimerModified =  Notification.Name(rawValue: "dcEphemeralTimerModified")

+ 6 - 10
deltachat-ios/AppDelegate.swift

@@ -413,23 +413,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
     // MARK: - Handle notification banners
 
-    private func userNotificationCenter(_: UNUserNotificationCenter, willPresent _: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
+    func userNotificationCenter(_: UNUserNotificationCenter, willPresent _: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
         logger.info("forground notification")
         completionHandler([.alert, .sound])
     }
 
-    private func userNotificationCenter(_: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
+    func userNotificationCenter(_: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
         if response.notification.request.identifier == Constants.notificationIdentifier {
             logger.info("handling notifications")
             let userInfo = response.notification.request.content.userInfo
-            let nc = NotificationCenter.default
-            DispatchQueue.main.async {
-                nc.post(
-                    name: dcNotificationViewChat,
-                    object: nil,
-                    userInfo: userInfo
-                )
-            }
+             if let chatId = userInfo["chat_id"] as? Int,
+                 let msgId = userInfo["message_id"] as? Int {
+                 appCoordinator.showChat(chatId: chatId, msgId: msgId)
+             }
         }
 
         completionHandler()

+ 0 - 11
deltachat-ios/Controller/ChatListController.swift

@@ -127,14 +127,6 @@ class ChatListController: UITableViewController {
             queue: nil) { [weak self] _ in
                 self?.viewModel.refreshData()
         }
-        viewChatObserver = nc.addObserver(
-            forName: dcNotificationViewChat,
-            object: nil,
-            queue: nil) { [weak self] notification in
-                if let chatId = notification.userInfo?["chat_id"] as? Int {
-                    self?.showChat(chatId: chatId)
-                }
-        }
         foregroundObserver = nc.addObserver(self,
                                             selector: #selector(applicationDidBecomeActive(_:)),
                                             name: UIApplication.didBecomeActiveNotification,
@@ -156,9 +148,6 @@ class ChatListController: UITableViewController {
         if let incomingMsgObserver = self.incomingMsgObserver {
             nc.removeObserver(incomingMsgObserver)
         }
-        if let viewChatObserver = self.viewChatObserver {
-            nc.removeObserver(viewChatObserver)
-        }
         if let msgsNoticedObserver = self.msgsNoticedObserver {
             nc.removeObserver(msgsNoticedObserver)
         }

+ 2 - 2
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -85,10 +85,10 @@ class AppCoordinator {
         tabBarController.selectedIndex = index
     }
 
-    func showChat(chatId: Int, animated: Bool = true) {
+    func showChat(chatId: Int, msgId: Int? = nil, animated: Bool = true) {
         showTab(index: chatsTab)
         if let rootController = self.chatsNavController.viewControllers.first as? ChatListController {
-            rootController.showChat(chatId: chatId, animated: animated)
+            rootController.showChat(chatId: chatId, highlightedMsg: msgId, animated: animated)
         }
     }