浏览代码

Fix loading avatars

Don't save originals
Use display name to make local initials avatar if avatar image can't be loaded

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 3 年之前
父节点
当前提交
dd2041166c

+ 3 - 3
iOSClient/Activity/NCActivity.swift

@@ -249,7 +249,7 @@ extension NCActivity: UITableViewDataSource {
         
         
         // Image
         // Image
         let fileName = String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase)) + "-" + comment.actorId + ".png"
         let fileName = String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase)) + "-" + comment.actorId + ".png"
-        NCOperationQueue.shared.downloadAvatar(user: comment.actorId, fileName: fileName, cell: cell, view: tableView)
+        NCOperationQueue.shared.downloadAvatar(user: comment.actorId, dispalyName: comment.actorDisplayName, fileName: fileName, cell: cell, view: tableView)
         // Username
         // Username
         cell.labelUser.text = comment.actorDisplayName
         cell.labelUser.text = comment.actorDisplayName
         cell.labelUser.textColor = NCBrandColor.shared.label
         cell.labelUser.textColor = NCBrandColor.shared.label
@@ -277,7 +277,7 @@ extension NCActivity: UITableViewDataSource {
         var orderKeysId: [String] = []
         var orderKeysId: [String] = []
         
         
         cell.idActivity = activity.idActivity
         cell.idActivity = activity.idActivity
-        cell.account = activity.account
+        
         cell.avatar.image = nil
         cell.avatar.image = nil
         cell.avatar.isHidden = true
         cell.avatar.isHidden = true
         cell.subjectTrailingConstraint.constant = 10
         cell.subjectTrailingConstraint.constant = 10
@@ -315,7 +315,7 @@ extension NCActivity: UITableViewDataSource {
             
             
             let fileName = String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase)) + "-" + activity.user + ".png"
             let fileName = String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase)) + "-" + activity.user + ".png"
             
             
-            NCOperationQueue.shared.downloadAvatar(user: activity.user, fileName: fileName, cell: cell, view: tableView)
+            NCOperationQueue.shared.downloadAvatar(user: activity.user, dispalyName: nil, fileName: fileName, cell: cell, view: tableView)
         }
         }
         
         
         // subject
         // subject

+ 1 - 1
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -1342,7 +1342,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
            appDelegate.account == metadata.account,
            appDelegate.account == metadata.account,
            let cell = cell as? NCCellProtocol {
            let cell = cell as? NCCellProtocol {
             let fileName = String(CCUtility.getUserUrlBase(metadata.user, urlBase: metadata.urlBase)) + "-" + metadata.ownerId + ".png"
             let fileName = String(CCUtility.getUserUrlBase(metadata.user, urlBase: metadata.urlBase)) + "-" + metadata.ownerId + ".png"
-            NCOperationQueue.shared.downloadAvatar(user: metadata.ownerId, fileName: fileName, cell: cell, view: collectionView)
+            NCOperationQueue.shared.downloadAvatar(user: metadata.ownerId, dispalyName: metadata.ownerDisplayName, fileName: fileName, cell: cell, view: collectionView)
         }
         }
     }
     }
     
     

+ 2 - 2
iOSClient/Networking/NCOperationQueue.swift

@@ -161,7 +161,7 @@ import NCCommunication
     
     
     // Download Avatar
     // Download Avatar
     
     
-    func downloadAvatar(user: String, fileName: String, cell: NCCellProtocol, view: UIView?) {
+    func downloadAvatar(user: String, dispalyName: String?, fileName: String, cell: NCCellProtocol, view: UIView?) {
 
 
         let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
         let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
         
         
@@ -173,7 +173,7 @@ import NCCommunication
         if let account = NCManageDatabase.shared.getActiveAccount() {
         if let account = NCManageDatabase.shared.getActiveAccount() {
             cell.fileAvatarImageView?.image = NCUtility.shared.loadUserImage(
             cell.fileAvatarImageView?.image = NCUtility.shared.loadUserImage(
                 for: user,
                 for: user,
-                   displayName: nil,
+                   displayName: dispalyName,
                    userUrlBase: String(CCUtility.getUserUrlBase(account.user, urlBase: account.urlBase)))
                    userUrlBase: String(CCUtility.getUserUrlBase(account.user, urlBase: account.urlBase)))
         }
         }
 
 

+ 1 - 12
iOSClient/Networking/NCService.swift

@@ -111,20 +111,9 @@ class NCService: NSObject {
 
 
                 NCCommunication.shared.downloadAvatar(user: tableAccount.userId, fileNameLocalPath: fileNameLocalPath, sizeImage: NCGlobal.shared.avatarSize, avatarSizeRounded: NCGlobal.shared.avatarSizeRounded, etag: etag, queue: NCCommunicationCommon.shared.backgroundQueue) { (account, image, imageOriginal, etag, errorCode, errorMessage) in
                 NCCommunication.shared.downloadAvatar(user: tableAccount.userId, fileNameLocalPath: fileNameLocalPath, sizeImage: NCGlobal.shared.avatarSize, avatarSizeRounded: NCGlobal.shared.avatarSizeRounded, etag: etag, queue: NCCommunicationCommon.shared.backgroundQueue) { (account, image, imageOriginal, etag, errorCode, errorMessage) in
 
 
-                    if let etag = etag, errorCode == 0, let imageOriginal = imageOriginal {
-                        
-                        do {
-                            if let pngData = imageOriginal.pngData() {
-                                let fileName = String(CCUtility.getUserUrlBase(user, urlBase: url)) + "-" + self.appDelegate.user + "-original.png"
-                                let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
-                                let url = URL.init(fileURLWithPath: fileNameLocalPath)
-                                try pngData.write(to: url)
-                            }
-                        } catch {}
-                        
+                    if let etag = etag, errorCode == 0 {
                         NCManageDatabase.shared.addAvatar(fileName: fileName, etag: etag)
                         NCManageDatabase.shared.addAvatar(fileName: fileName, etag: etag)
                         NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadAvatar, userInfo: nil)
                         NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadAvatar, userInfo: nil)
-                        
                     } else if errorCode == NCGlobal.shared.errorNotModified {
                     } else if errorCode == NCGlobal.shared.errorNotModified {
                         
                         
                         NCManageDatabase.shared.setAvatarLoaded(fileName: fileName)
                         NCManageDatabase.shared.setAvatarLoaded(fileName: fileName)

+ 1 - 1
iOSClient/Notification/NCNotification.swift

@@ -150,7 +150,7 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
                         cell.avatar.isHidden = false
                         cell.avatar.isHidden = false
                         cell.avatarLeadingMargin.constant = 50
                         cell.avatarLeadingMargin.constant = 50
                         cell.fileUser = user
                         cell.fileUser = user
-                        NCOperationQueue.shared.downloadAvatar(user: user, fileName: fileName, cell: cell, view: tableView)
+                        NCOperationQueue.shared.downloadAvatar(user: user, dispalyName: nil, fileName: fileName, cell: cell, view: tableView)
                     }
                     }
                 }
                 }
             }
             }

+ 1 - 1
iOSClient/Select/NCSelect.swift

@@ -420,7 +420,7 @@ extension NCSelect: UICollectionViewDataSource {
            activeAccount.account == metadata.account,
            activeAccount.account == metadata.account,
            let cell = cell as? NCCellProtocol {
            let cell = cell as? NCCellProtocol {
             let fileName = String(CCUtility.getUserUrlBase(metadata.user, urlBase: metadata.urlBase)) + "-" + metadata.ownerId + ".png"
             let fileName = String(CCUtility.getUserUrlBase(metadata.user, urlBase: metadata.urlBase)) + "-" + metadata.ownerId + ".png"
-            NCOperationQueue.shared.downloadAvatar(user: metadata.ownerId, fileName: fileName, cell: cell, view: collectionView)
+            NCOperationQueue.shared.downloadAvatar(user: metadata.ownerId, dispalyName: metadata.ownerDisplayName, fileName: fileName, cell: cell, view: collectionView)
         }
         }
     }
     }
     
     

+ 1 - 1
iOSClient/Share/NCShare.swift

@@ -430,7 +430,7 @@ extension NCShare: UITableViewDataSource {
                 
                 
                 let fileName = String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase)) + "-" + tableShare.shareWith + ".png"
                 let fileName = String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase)) + "-" + tableShare.shareWith + ".png"
                
                
-                NCOperationQueue.shared.downloadAvatar(user: tableShare.shareWith, fileName: fileName, cell: cell, view: tableView)
+                NCOperationQueue.shared.downloadAvatar(user: tableShare.shareWith, dispalyName: tableShare.shareWithDisplayname, fileName: fileName, cell: cell, view: tableView)
                 
                 
                 // If the initiator or the recipient is not the current user, show the list of sharees without any options to edit it.
                 // If the initiator or the recipient is not the current user, show the list of sharees without any options to edit it.
                 if tableShare.uidOwner != self.appDelegate.userId && tableShare.uidFileOwner != self.appDelegate.userId {
                 if tableShare.uidOwner != self.appDelegate.userId && tableShare.uidFileOwner != self.appDelegate.userId {

+ 3 - 5
iOSClient/Utility/NCUtility.swift

@@ -499,12 +499,10 @@ class NCUtility: NSObject {
     @objc func loadUserImage(for user: String, displayName: String?, userUrlBase: String, original: Bool = false) -> UIImage {
     @objc func loadUserImage(for user: String, displayName: String?, userUrlBase: String, original: Bool = false) -> UIImage {
 
 
         let fileName = userUrlBase + "-" + user + ".png"
         let fileName = userUrlBase + "-" + user + ".png"
-        let originalFilePath = userUrlBase + "-" + user + "-original.png"
-        let locaFilelPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
+        let localFilePath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
 
 
-        if let localImage = UIImage(contentsOfFile: locaFilelPath) { return localImage }
-        else if let originalImage = UIImage(contentsOfFile: originalFilePath) {
-            return NCUtility.shared.createAvatar(image: originalImage, size: 30)
+        if let localImage = UIImage(contentsOfFile: localFilePath) {
+            return NCUtility.shared.createAvatar(image: localImage, size: 30)
         } else if let loadedAvatar = NCManageDatabase.shared.getImageAvatarLoaded(fileName: fileName) {
         } else if let loadedAvatar = NCManageDatabase.shared.getImageAvatarLoaded(fileName: fileName) {
             return loadedAvatar
             return loadedAvatar
         } else if let displayName = displayName, !displayName.isEmpty, let avatarImg = createAvatar(displayName: displayName, size: 30) {
         } else if let displayName = displayName, !displayName.isEmpty, let avatarImg = createAvatar(displayName: displayName, size: 30) {