Browse Source

Tapping a notification should view the associated file (#2590)

* fix

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>

* fix test

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>

---------

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 1 year ago
parent
commit
c85461c831

+ 2 - 1
ExternalResources/NCApplicationHandle.swift

@@ -86,6 +86,7 @@ class NCApplicationHandle: NSObject {
     }
 
     // class: NCNotification
-    func didSelectNotification(_ notification: NKNotifications, viewController: UIViewController) {
+    func didSelectNotification(_ notification: NKNotifications, viewController: UIViewController) -> NKNotifications? {
+        return notification
     }
 }

+ 13 - 6
iOSClient/Notification/NCNotification.swift

@@ -113,12 +113,19 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
 
     override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
 
-        let notification = notifications[indexPath.row]
-
-        if notification.app == "files_sharing" {
-            NCActionCenter.shared.viewerFile(account: appDelegate.account, fileId: notification.objectId, viewController: self)
-        } else {
-            NCApplicationHandle().didSelectNotification(notification, viewController: self)
+        guard let notification = NCApplicationHandle().didSelectNotification(notifications[indexPath.row], viewController: self) else { return }
+
+        do {
+            if let subjectRichParameters = notification.subjectRichParameters,
+               let json = try JSONSerialization.jsonObject(with: subjectRichParameters, options: .mutableContainers) as? [String: Any],
+               let file = json["file"] as? [String: Any],
+               file["type"] as? String == "file" {
+                if let id = file["id"] {
+                    NCActionCenter.shared.viewerFile(account: appDelegate.account, fileId: ("\(id)"), viewController: self)
+                }
+            }
+        } catch {
+            print("Something went wrong")
         }
     }