Explorar o código

Merge pull request #2525 from nextcloud/pn

Push Notification - twofactor Notification
Marino Faggiana hai 1 ano
pai
achega
d6d2687367

+ 2 - 1
ExternalResources/NCApplicationHandle.swift

@@ -32,7 +32,8 @@ class NCApplicationHandle: NSObject {
 
     // class: AppDelegate
     // func nextcloudPushNotificationAction(data: [String: AnyObject])
-    func nextcloudPushNotificationAction(data: [String: AnyObject]) {
+    func nextcloudPushNotificationAction(data: [String: AnyObject], completion: @escaping (_ detected: Bool) -> Void) {
+        completion(false)
     }
 
     // class: AppDelegate

+ 4 - 4
Nextcloud.xcodeproj/project.pbxproj

@@ -4566,7 +4566,7 @@
 				CLANG_WARN_UNREACHABLE_CODE = YES;
 				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
 				COPY_PHASE_STRIP = NO;
-				CURRENT_PROJECT_VERSION = 1;
+				CURRENT_PROJECT_VERSION = 0;
 				DEBUG_INFORMATION_FORMAT = dwarf;
 				DEVELOPMENT_TEAM = NKUJUXUJ3B;
 				ENABLE_STRICT_OBJC_MSGSEND = YES;
@@ -4592,7 +4592,7 @@
 					"@executable_path/Frameworks",
 					"@executable_path/../../Frameworks",
 				);
-				MARKETING_VERSION = 4.8.5;
+				MARKETING_VERSION = 4.8.6;
 				ONLY_ACTIVE_ARCH = YES;
 				OTHER_LDFLAGS = "";
 				SDKROOT = iphoneos;
@@ -4631,7 +4631,7 @@
 				CLANG_WARN_UNREACHABLE_CODE = YES;
 				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
 				COPY_PHASE_STRIP = NO;
-				CURRENT_PROJECT_VERSION = 1;
+				CURRENT_PROJECT_VERSION = 0;
 				DEVELOPMENT_TEAM = NKUJUXUJ3B;
 				ENABLE_STRICT_OBJC_MSGSEND = YES;
 				ENABLE_TESTABILITY = YES;
@@ -4654,7 +4654,7 @@
 					"@executable_path/Frameworks",
 					"@executable_path/../../Frameworks",
 				);
-				MARKETING_VERSION = 4.8.5;
+				MARKETING_VERSION = 4.8.6;
 				ONLY_ACTIVE_ARCH = YES;
 				OTHER_LDFLAGS = "";
 				SDKROOT = iphoneos;

+ 34 - 1
iOSClient/AppDelegate.swift

@@ -440,7 +440,40 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     }
 
     func nextcloudPushNotificationAction(data: [String: AnyObject]) {
-        NCApplicationHandle().nextcloudPushNotificationAction(data: data)
+        NCApplicationHandle().nextcloudPushNotificationAction(data: data) { detected in
+            if !detected {
+
+                var findAccount: Bool = false
+
+                if let accountPush = data["account"] as? String,
+                   let app = data["app"] as? String,
+                   app == NCGlobal.shared.twofactorNotificatioName {
+                    if accountPush == self.account {
+                        findAccount = true
+                    } else {
+                        let accounts = NCManageDatabase.shared.getAllAccount()
+                        for account in accounts {
+                            if account.account == accountPush {
+                                self.changeAccount(account.account)
+                                findAccount = true
+                            }
+                        }
+                    }
+                    if findAccount, let viewController = UIStoryboard(name: "NCNotification", bundle: nil).instantiateInitialViewController() as? NCNotification {
+                        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
+                            let navigationController = UINavigationController(rootViewController: viewController)
+                            navigationController.modalPresentationStyle = .fullScreen
+                            self.window?.rootViewController?.present(navigationController, animated: true)
+                        }
+                    } else if !findAccount {
+                        let message = NSLocalizedString("_the_account_", comment: "") + " " + accountPush + " " + NSLocalizedString("_does_not_exist_", comment: "")
+                        let alertController = UIAlertController(title: NSLocalizedString("_info_", comment: ""), message: message, preferredStyle: .alert)
+                        alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { _ in }))
+                        self.window?.rootViewController?.present(alertController, animated: true, completion: { })
+                    }
+                }
+            }
+        }
     }
 
     // MARK: - Login & checkErrorNetworking

+ 5 - 3
iOSClient/NCGlobal.swift

@@ -88,9 +88,11 @@ class NCGlobal: NSObject {
 
     // Name
     //
-    @objc let appName                               = "files"
-    @objc let talkName                              = "talk-message"
-    @objc let appScheme                             = "nextcloud"
+    let appName                                     = "files"
+    let talkName                                    = "talk-message"
+    let spreedName                                  = "spreed"
+    let twofactorNotificatioName                    = "twofactor_nextcloud_notification"
+    let appScheme                                   = "nextcloud"
 
     // Nextcloud version
     //

+ 12 - 1
iOSClient/Notification/NCNotification.swift

@@ -49,6 +49,13 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
 
         refreshControl?.addTarget(self, action: #selector(getNetwokingNotification), for: .valueChanged)
 
+        // Navigation controller is being presented modally
+        if navigationController?.presentingViewController != nil {
+            navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_cancel_", comment: ""), style: .plain, action: { [weak self] in
+                self?.dismiss(animated: true)
+            })
+        }
+
         // Empty
         let offset = (self.navigationController?.navigationBar.bounds.height ?? 0) - 20
         emptyDataSet = NCEmptyDataSet(view: tableView, offset: -offset, delegate: self)
@@ -258,7 +265,7 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
     }
 
     func tapAction(with notification: NKNotifications, label: String) {
-        if notification.app == "spreed",
+        if notification.app == NCGlobal.shared.spreedName,
            let roomToken = notification.objectId.split(separator: "/").first,
            let talkUrl = URL(string: "nextcloudtalk://open-conversation?server=\(appDelegate.urlBase)&user=\(appDelegate.userId)&withRoomToken=\(roomToken)"),
            UIApplication.shared.canOpenURL(talkUrl) {
@@ -280,11 +287,15 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
                         self.notifications.remove(at: index)
                     }
                     self.tableView.reloadData()
+                    if self.navigationController?.presentingViewController != nil, notification.app == NCGlobal.shared.twofactorNotificatioName {
+                        self.dismiss(animated: true)
+                    }
                 } else if error != .success {
                     NCContentPresenter.shared.showError(error: error)
                 } else {
                     print("[Error] The user has been changed during networking process.")
                 }
+
             }
         } // else: Action not found
     }

+ 2 - 0
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -113,6 +113,8 @@
 "_purchase_"                = "Purchase";
 "_account_not_available_"   = "The account %@ of %@ does not exist, please add it to be able to read the file %@";
 "_account_not_exists_"      = "The account %@ of %@ does not exist";
+"_the_account_"             = "The account";
+"_does_not_exist_"          = "does not exist";
 "_error_parameter_schema_"  = "Wrong parameters, impossible to continue";
 "_comments_"                = "Comments";
 "_sharing_"                 = "Sharing";