Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 32 additions & 29 deletions iOSClient/Notification/NCNotification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,39 +250,42 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate {
}

func tapAction(with notification: NKNotifications, label: String, sender: Any?) {
if notification.app == NCGlobal.shared.spreedName,
let roomToken = notification.objectId.split(separator: "/").first,
let talkUrl = URL(string: "nextcloudtalk://open-conversation?server=\(session.urlBase)&user=\(session.userId)&withRoomToken=\(roomToken)"),
UIApplication.shared.canOpenURL(talkUrl) {
UIApplication.shared.open(talkUrl)
} else if let actions = notification.actions,
let jsonActions = JSON(actions).array,
let action = jsonActions.first(where: { $0["label"].string == label }) {
let serverUrl = action["link"].stringValue
let method = action["type"].stringValue

if method == "WEB", let url = action["link"].url {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
return
guard let actions = notification.actions,
let jsonActions = JSON(actions).array,
let action = jsonActions.first(where: { $0["label"].string == label })
else { return }

let serverUrl = action["link"].stringValue
let method = action["type"].stringValue

if method == "WEB", var url = action["link"].url {
if notification.app == NCGlobal.shared.spreedName,
let roomToken = notification.objectId.split(separator: "/").first,
let talkUrl = URL(string: "nextcloudtalk://open-conversation?server=\(session.urlBase)&user=\(session.userId)&withRoomToken=\(roomToken)"),
UIApplication.shared.canOpenURL(talkUrl) {

url = talkUrl
}

NextcloudKit.shared.setNotification(serverUrl: serverUrl, idNotification: 0, method: method, account: session.account) { _, _, error in
if error == .success {
if let index = self.notifications.firstIndex(where: { $0.idNotification == notification.idNotification }) {
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().showError(error: error)
} else {
print("[Error] The user has been changed during networking process.")
}
UIApplication.shared.open(url)
return
}

NextcloudKit.shared.setNotification(serverUrl: serverUrl, idNotification: 0, method: method, account: session.account) { _, _, error in
if error == .success {
if let index = self.notifications.firstIndex(where: { $0.idNotification == notification.idNotification }) {
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().showError(error: error)
} else {
print("[Error] The user has been changed during networking process.")
}
} // else: Action not found
}
}

func tapMore(with notification: NKNotifications, sender: Any?) {
Expand Down
Loading