Browse Source

fix notification avatar

marinofaggiana 3 years ago
parent
commit
1dd233e178
1 changed files with 14 additions and 16 deletions
  1. 14 16
      iOSClient/Notification/NCNotification.swift

+ 14 - 16
iOSClient/Notification/NCNotification.swift

@@ -133,25 +133,23 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
         cell.avatar.isHidden = true
         cell.avatarLeadingMargin.constant = 10
         if let subjectRichParameters = notification.subjectRichParameters {
-            if let parameter = JSON(subjectRichParameters).dictionary {
-                if let user = JSON(parameter).dictionary {
-                    if let userId = user["id"]?.string {
-                        
-                        let fileName = String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase)) + "-" + userId + ".png"
-                        let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
-                        
-                        if FileManager.default.fileExists(atPath: fileNameLocalPath) {
-                            if let image = UIImage(contentsOfFile: fileNameLocalPath) {
-                                cell.avatar.isHidden = false
-                                cell.avatarLeadingMargin.constant = 50
-                                cell.avatar.image = image
-                            }
-                        } else {
+            if let json = JSON(subjectRichParameters).dictionary {
+                if let user = json["user"]?["id"].stringValue {
+                    
+                    let fileName = String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase)) + "-" + user + ".png"
+                    let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
+                    
+                    if FileManager.default.fileExists(atPath: fileNameLocalPath) {
+                        if let image = UIImage(contentsOfFile: fileNameLocalPath) {
                             cell.avatar.isHidden = false
                             cell.avatarLeadingMargin.constant = 50
-                            cell.fileUser = userId
-                            NCOperationQueue.shared.downloadAvatar(user: userId, fileName: fileName, placeholder: UIImage(named: "avatar"), cell: cell, view: tableView)
+                            cell.avatar.image = image
                         }
+                    } else {
+                        cell.avatar.isHidden = false
+                        cell.avatarLeadingMargin.constant = 50
+                        cell.fileUser = user
+                        NCOperationQueue.shared.downloadAvatar(user: user, fileName: fileName, placeholder: UIImage(named: "avatar"), cell: cell, view: tableView)
                     }
                 }
             }