marinofaggiana пре 3 година
родитељ
комит
e1f62331ab

+ 2 - 3
iOSClient/Activity/NCActivity.swift

@@ -254,9 +254,8 @@ extension NCActivity: UITableViewDataSource {
                 cell.avatar.isHidden = false
                 cell.fileUser = activity.user
                 
-                let userUrlBase = String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase))
-                let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + userUrlBase + "-" + activity.user + ".png"
-                NCOperationQueue.shared.downloadAvatar(user: activity.user, userUrlBase: userUrlBase, fileNameLocalPath: fileNameLocalPath, placeholder: UIImage(named: "avatar"), cell: cell, view: tableView)
+                let fileName = String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase)) + "-" + activity.user + ".png"
+                NCOperationQueue.shared.downloadAvatar(user: activity.user, fileName: fileName, placeholder: UIImage(named: "avatar"), cell: cell, view: tableView)
             }
             
             // subject

+ 11 - 12
iOSClient/Data/NCDatabase.swift

@@ -166,6 +166,17 @@ class tableActivitySubjectRich: Object {
     }
 }
 
+class tableAvatar: Object {
+    
+    @objc dynamic var date = NSDate()
+    @objc dynamic var etag = ""
+    @objc dynamic var fileName = ""
+
+    override static func primaryKey() -> String {
+        return "fileName"
+    }
+}
+
 class tableCapabilities: Object {
     
     @objc dynamic var account = ""
@@ -476,18 +487,6 @@ class tableTrash: Object {
     }
 }
 
-class tableUser: Object {
-    
-    @objc dynamic var date = NSDate()
-    @objc dynamic var etag = ""
-    @objc dynamic var user = ""
-    @objc dynamic var userUrlBase = ""
-
-    override static func primaryKey() -> String {
-        return "userUrlBase"
-    }
-}
-
 class tableUserStatus: Object {
     
     @objc dynamic var account = ""

+ 36 - 37
iOSClient/Data/NCManageDatabase.swift

@@ -116,7 +116,7 @@ class NCManageDatabase: NSObject {
                         }
                     }
                     
-                    if oldSchemaVersion < 199 {
+                    if oldSchemaVersion < 200 {
                         migration.deleteData(forType: tableDirectory.className())
                         migration.deleteData(forType: tableE2eEncryption.className())
                         migration.deleteData(forType: tableE2eEncryptionLock.className())
@@ -894,6 +894,41 @@ class NCManageDatabase: NSObject {
         return 0
     }
     
+    //MARK: -
+    //MARK: Table Avatar
+    
+    @objc func addAvatar(fileName: String, etag: String) {
+        
+        let realm = try! Realm()
+        
+        do {
+            try realm.safeWrite {
+                
+                // Add new
+                let addObject = tableAvatar()
+                    
+                addObject.date = NSDate()
+                addObject.etag = etag
+                addObject.fileName = fileName
+
+                realm.add(addObject, update: .all)
+            }
+        } catch let error {
+            NCCommunicationCommon.shared.writeLog("Could not write to database: \(error)")
+        }
+    }
+    
+    @objc func getTableAvatar(fileName: String) -> tableAvatar? {
+        
+        let realm = try! Realm()
+        
+        guard let result = realm.objects(tableAvatar.self).filter("fileName == %@", fileName).first else {
+            return nil
+        }
+        
+        return tableAvatar.init(value: result)
+    }
+    
     //MARK: -
     //MARK: Table Capabilities
     
@@ -2960,42 +2995,6 @@ class NCManageDatabase: NSObject {
         return tableTrash.init(value: result)
     }
     
-    //MARK: -
-    //MARK: Table User
-    
-    @objc func addUser(_ user: String, userUrlBase: String ,etag: String) {
-        
-        let realm = try! Realm()
-        
-        do {
-            try realm.safeWrite {
-                
-                // Add new
-                let addObject = tableUser()
-                    
-                addObject.date = NSDate()
-                addObject.etag = etag
-                addObject.user = user
-                addObject.userUrlBase = userUrlBase
-
-                realm.add(addObject, update: .all)
-            }
-        } catch let error {
-            NCCommunicationCommon.shared.writeLog("Could not write to database: \(error)")
-        }
-    }
-    
-    @objc func getTableUser(userUrlBase: String) -> tableUser? {
-        
-        let realm = try! Realm()
-        
-        guard let result = realm.objects(tableUser.self).filter("userUrlBase == %@", userUrlBase).first else {
-            return nil
-        }
-        
-        return tableUser.init(value: result)
-    }
-    
     //MARK: -
     //MARK: Table UserStatus
     

+ 2 - 3
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -1372,9 +1372,8 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
         
         // Avatar
         if metadata.ownerId.count > 0 && metadata.ownerId != appDelegate.userId && appDelegate.account == metadata.account {
-            let userUrlBase = String(CCUtility.getUserUrlBase(metadata.user, urlBase: metadata.urlBase))
-            let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + userUrlBase + "-" + metadata.ownerId + ".png"
-            NCOperationQueue.shared.downloadAvatar(user: metadata.ownerId, userUrlBase: userUrlBase, fileNameLocalPath: fileNameLocalPath, placeholder: NCBrandColor.cacheImages.shared, cell: cell, view: collectionView)
+            let fileName = String(CCUtility.getUserUrlBase(metadata.user, urlBase: metadata.urlBase)) + "-" + metadata.ownerId + ".png"
+            NCOperationQueue.shared.downloadAvatar(user: metadata.ownerId, fileName: fileName, placeholder: NCBrandColor.cacheImages.shared, cell: cell, view: collectionView)
         }
     }
     

+ 1 - 1
iOSClient/NCGlobal.swift

@@ -79,7 +79,7 @@ class NCGlobal: NSObject {
     // Database Realm
     //
     let databaseDefault                             = "nextcloud.realm"
-    let databaseSchemaVersion: UInt64               = 199
+    let databaseSchemaVersion: UInt64               = 200
     
     // Intro selector
     //

+ 8 - 8
iOSClient/Networking/NCOperationQueue.swift

@@ -161,9 +161,10 @@ import NCCommunication
     
     // Download Avatar
     
-    func downloadAvatar(user: String, userUrlBase: String, fileNameLocalPath: String, placeholder: UIImage?, cell: UIView, view: UIView?) {
+    func downloadAvatar(user: String, fileName: String, placeholder: UIImage?, cell: UIView, view: UIView?) {
 
         let cell: NCCellProtocol = cell as! NCCellProtocol
+        let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
 
         #if !EXTENSION
         if let image = (UIApplication.shared.delegate as! AppDelegate).avatars[user] {
@@ -177,7 +178,7 @@ import NCCommunication
             cell.fileAvatarImageView?.image = NCUtility.shared.createAvatar(image: image, size: 30)
         }
         
-        downloadAvatarQueue.addOperation(NCOperationDownloadAvatar.init(user: user, userUrlBase: userUrlBase, fileNameLocalPath: fileNameLocalPath, cell: cell, view: view))
+        downloadAvatarQueue.addOperation(NCOperationDownloadAvatar.init(user: user, fileName: fileName, fileNameLocalPath: fileNameLocalPath, cell: cell, view: view))
     }
     
     func cancelDownloadAvatar(user: String) {
@@ -442,20 +443,19 @@ class NCOperationDownloadThumbnail: ConcurrentOperation {
 class NCOperationDownloadAvatar: ConcurrentOperation {
 
     var user: String
-    var userUrlBase: String
+    var fileName: String
     var etag: String?
-    var userFile: String = ""
     var fileNameLocalPath: String
     var cell: NCCellProtocol!
     var view: UIView?
 
-    init(user: String, userUrlBase: String, fileNameLocalPath: String, cell: NCCellProtocol, view: UIView?) {
+    init(user: String, fileName: String, fileNameLocalPath: String, cell: NCCellProtocol, view: UIView?) {
         self.user = user
-        self.userUrlBase = userUrlBase
+        self.fileName = fileName
         self.fileNameLocalPath = fileNameLocalPath
         self.cell = cell
         self.view = view
-        self.etag = NCManageDatabase.shared.getTableUser(userUrlBase: userUrlBase)?.etag
+        self.etag = NCManageDatabase.shared.getTableAvatar(fileName: fileName)?.etag
     }
     
     override func start() {
@@ -468,7 +468,7 @@ class NCOperationDownloadAvatar: ConcurrentOperation {
                 if errorCode == 0 && data != nil && etag != nil {
                     if var image = UIImage.init(data: data!) {
                         image = NCUtility.shared.createAvatar(image: image, size: 30)
-                        NCManageDatabase.shared.addUser(self.user, userUrlBase: self.userUrlBase, etag: etag!)
+                        NCManageDatabase.shared.addAvatar(fileName: self.fileName, etag: etag!)
                         #if !EXTENSION
                         (UIApplication.shared.delegate as! AppDelegate).avatars[self.user] = image
                         #endif

+ 3 - 3
iOSClient/Notification/NCNotification.swift

@@ -136,8 +136,8 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
             if let parameter = JSON(subjectRichParameters).dictionary {
                 if let user = JSON(parameter).dictionary {
                     if let userId = user["id"]?.string {
-                        let userUrlBase = String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase))
-                        let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + userUrlBase + "-" + userId + ".png"
+                        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
@@ -148,7 +148,7 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
                             cell.avatar.isHidden = false
                             cell.avatarLeadingMargin.constant = 50
                             cell.fileUser = userId
-                            NCOperationQueue.shared.downloadAvatar(user: userId, userUrlBase: userUrlBase, fileNameLocalPath: fileNameLocalPath, placeholder: UIImage(named: "avatar"), cell: cell, view: tableView)
+                            NCOperationQueue.shared.downloadAvatar(user: userId, fileName: fileName, placeholder: UIImage(named: "avatar"), cell: cell, view: tableView)
                         }
                     }
                 }

+ 2 - 3
iOSClient/Select/NCSelect.swift

@@ -416,9 +416,8 @@ extension NCSelect: UICollectionViewDataSource {
         
         // Avatar
         if metadata.ownerId.count > 0 && metadata.ownerId != activeAccount.userId && activeAccount.account == metadata.account {
-            let userUrlBase = String(CCUtility.getUserUrlBase(metadata.user, urlBase: metadata.urlBase))
-            let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + userUrlBase + "-" + metadata.ownerId + ".png"
-            NCOperationQueue.shared.downloadAvatar(user: metadata.ownerId, userUrlBase: userUrlBase, fileNameLocalPath: fileNameLocalPath, placeholder: NCBrandColor.cacheImages.shared, cell: cell, view: collectionView)
+            let fileName = String(CCUtility.getUserUrlBase(metadata.user, urlBase: metadata.urlBase)) + "-" + metadata.ownerId + ".png"
+            NCOperationQueue.shared.downloadAvatar(user: metadata.ownerId, fileName: fileName, placeholder: NCBrandColor.cacheImages.shared, cell: cell, view: collectionView)
         }
     }
     

+ 4 - 6
iOSClient/Share/NCShare.swift

@@ -333,9 +333,8 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel
             } else {
                 cell.centerTitle.constant = 0
             }
-            let userUrlBase = String(CCUtility.getUserUrlBase(self.appDelegate.user, urlBase: self.appDelegate.urlBase))
-            let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + userUrlBase + "-" + sharee.label + ".png"
-            NCOperationQueue.shared.downloadAvatar(user: sharee.shareWith, userUrlBase: userUrlBase, fileNameLocalPath: fileNameLocalPath, placeholder: UIImage(named: "avatar"), cell: cell, view: nil)
+            let fileName = String(CCUtility.getUserUrlBase(self.appDelegate.user, urlBase: self.appDelegate.urlBase)) + "-" + sharee.label + ".png"
+            NCOperationQueue.shared.downloadAvatar(user: sharee.shareWith, fileName: fileName, placeholder: UIImage(named: "avatar"), cell: cell, view: nil)
             cell.imageShareeType.image = NCShareCommon.shared.getImageShareType(shareType: sharee.shareType)
         }
         
@@ -412,9 +411,8 @@ extension NCShare: UITableViewDataSource {
                 cell.imageStatus.image = status.onlineStatus
                 cell.status.text = status.statusMessage
                 
-                let userUrlBase = String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase))
-                let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + userUrlBase + "-" + tableShare.shareWith + ".png"
-                NCOperationQueue.shared.downloadAvatar(user: tableShare.shareWith, userUrlBase: userUrlBase, fileNameLocalPath: fileNameLocalPath, placeholder: UIImage(named: "avatar"), cell: cell, view: tableView)
+                let fileName = String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase)) + "-" + tableShare.shareWith + ".png"
+                NCOperationQueue.shared.downloadAvatar(user: tableShare.shareWith, fileName: fileName, placeholder: UIImage(named: "avatar"), 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 tableShare.uidOwner != self.appDelegate.userId && tableShare.uidFileOwner != self.appDelegate.userId {

+ 2 - 3
iOSClient/Share/NCShareComments.swift

@@ -180,9 +180,8 @@ extension NCShareComments: UITableViewDataSource {
             cell.sizeToFit()
             
             // Image
-            let userUrlBase = String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase))
-            let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + userUrlBase + "-" + tableComments.actorId + ".png"
-            NCOperationQueue.shared.downloadAvatar(user: tableComments.actorId, userUrlBase: userUrlBase, fileNameLocalPath: fileNameLocalPath, placeholder: UIImage(named: "avatar"), cell: cell, view: tableView)
+            let fileName = String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase)) + "-" + tableComments.actorId + ".png"
+            NCOperationQueue.shared.downloadAvatar(user: tableComments.actorId, fileName: fileName, placeholder: UIImage(named: "avatar"), cell: cell, view: tableView)
             // Username
             cell.labelUser.text = tableComments.actorDisplayName
             cell.labelUser.textColor = NCBrandColor.shared.label