Skip to content

Commit

Permalink
Merge pull request #2525 from nextcloud/pn
Browse files Browse the repository at this point in the history
Push Notification - twofactor Notification
  • Loading branch information
marinofaggiana authored Jul 11, 2023
2 parents bc6489c + eddc3bf commit d6d2687
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 10 deletions.
3 changes: 2 additions & 1 deletion ExternalResources/NCApplicationHandle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
35 changes: 34 additions & 1 deletion iOSClient/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions iOSClient/NCGlobal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
13 changes: 12 additions & 1 deletion iOSClient/Notification/NCNotification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions iOSClient/Supporting Files/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit d6d2687

Please sign in to comment.