marinofaggiana 3 жил өмнө
parent
commit
6245ab70be

+ 1 - 1
Nextcloud.xcodeproj/project.pbxproj

@@ -2939,7 +2939,7 @@
 			repositoryURL = "https://github.com/nextcloud/ios-communication-library/";
 			requirement = {
 				kind = revision;
-				revision = 4b2b71daf4dea7b66d68cac5af67ec4aaf7d9281;
+				revision = 19e9266a5bb47453dd9568cf13f84883d27d4a49;
 			};
 		};
 		F788ECC5263AAAF900ADC67F /* XCRemoteSwiftPackageReference "MarkdownKit" */ = {

+ 1 - 1
Nextcloud.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

@@ -105,7 +105,7 @@
         "repositoryURL": "https://github.com/nextcloud/ios-communication-library/",
         "state": {
           "branch": null,
-          "revision": "4b2b71daf4dea7b66d68cac5af67ec4aaf7d9281",
+          "revision": "19e9266a5bb47453dd9568cf13f84883d27d4a49",
           "version": null
         }
       },

+ 3 - 2
Share/NCShareExtension.swift

@@ -583,8 +583,9 @@ extension NCShareExtension: UICollectionViewDataSource {
             cell.imageShared.image = NCBrandColor.cacheImages.canShare
         }
         if metadata.ownerId.count > 0 && metadata.ownerId != activeAccount.userId {
-            let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + String(CCUtility.getStringUser(activeAccount.user, urlBase: activeAccount.urlBase)) + "-" + metadata.ownerId + ".png"
-            NCOperationQueue.shared.downloadAvatar(user: metadata.ownerId, fileNameLocalPath: fileNameLocalPath, placeholder: nil, cell: cell, view: collectionView)
+            let userUrlBase = String(CCUtility.getStringUser(activeAccount.user, urlBase: activeAccount.urlBase))
+            let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + userUrlBase + "-" + metadata.ownerId + ".png"
+            NCOperationQueue.shared.downloadAvatar(user: metadata.ownerId, userUrlBase: userUrlBase, fileNameLocalPath: fileNameLocalPath, placeholder: nil, cell: cell, view: collectionView)
         }
         
         cell.imageSelect.isHidden = true

+ 3 - 2
iOSClient/Activity/NCActivity.swift

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

+ 12 - 0
iOSClient/Data/NCDatabase.swift

@@ -476,6 +476,18 @@ 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 - 0
iOSClient/Data/NCManageDatabase.swift

@@ -2960,6 +2960,42 @@ 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 getUser(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
     

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

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

+ 1 - 1
iOSClient/NCGlobal.swift

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

+ 11 - 6
iOSClient/Networking/NCOperationQueue.swift

@@ -161,7 +161,7 @@ import NCCommunication
     
     // Download Avatar
     
-    func downloadAvatar(user: String, fileNameLocalPath: String, placeholder: UIImage?, cell: UIView, view: UIView?) {
+    func downloadAvatar(user: String, userUrlBase: String, fileNameLocalPath: String, placeholder: UIImage?, cell: UIView, view: UIView?) {
 
         let cell: NCCellProtocol = cell as! NCCellProtocol
 
@@ -176,8 +176,8 @@ import NCCommunication
         if let image = UIImage(contentsOfFile: fileNameLocalPath) {
             cell.fileAvatarImageView?.image = NCUtility.shared.createAvatar(image: image, size: 30)
         }
-    
-        downloadAvatarQueue.addOperation(NCOperationDownloadAvatar.init(user: user, fileNameLocalPath: fileNameLocalPath, cell: cell, view: view))
+        
+        downloadAvatarQueue.addOperation(NCOperationDownloadAvatar.init(user: user, userUrlBase: userUrlBase, fileNameLocalPath: fileNameLocalPath, cell: cell, view: view))
     }
     
     func cancelDownloadAvatar(user: String) {
@@ -442,15 +442,19 @@ class NCOperationDownloadThumbnail: ConcurrentOperation {
 class NCOperationDownloadAvatar: ConcurrentOperation {
 
     var user: String
+    var userUrlBase: String
+    var etag: String?
     var fileNameLocalPath: String
     var cell: NCCellProtocol!
     var view: UIView?
 
-    init(user: String, fileNameLocalPath: String, cell: NCCellProtocol, view: UIView?) {
+    init(user: String, userUrlBase: String, fileNameLocalPath: String, cell: NCCellProtocol, view: UIView?) {
         self.user = user
+        self.userUrlBase = userUrlBase
         self.fileNameLocalPath = fileNameLocalPath
         self.cell = cell
         self.view = view
+        etag = NCManageDatabase.shared.getUser(userUrlBase: userUrlBase)?.etag
     }
     
     override func start() {
@@ -458,11 +462,12 @@ class NCOperationDownloadAvatar: ConcurrentOperation {
         if isCancelled {
             self.finish()
         } else {
-            NCCommunication.shared.downloadAvatar(user: user, fileNameLocalPath: fileNameLocalPath, size: NCGlobal.shared.avatarSize) { (account, data, errorCode, errorMessage) in
+            NCCommunication.shared.downloadAvatar(user: user, fileNameLocalPath: fileNameLocalPath, size: NCGlobal.shared.avatarSize, etag: etag) { (account, data, etag, errorCode, errorMessage) in
                 
-                if errorCode == 0 && data != nil {
+                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!)
                         #if !EXTENSION
                         (UIApplication.shared.delegate as! AppDelegate).avatars[self.user] = image
                         #endif

+ 1 - 1
iOSClient/Networking/NCService.swift

@@ -109,7 +109,7 @@ class NCService: NSObject {
                     // Get Avatar
                     let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + stringUser + "-" + self.appDelegate.user + ".png"
                     let oldData = try? Data(contentsOf: URL(fileURLWithPath: fileNameLocalPath))
-                    NCCommunication.shared.downloadAvatar(user: user, fileNameLocalPath: fileNameLocalPath, size: NCGlobal.shared.avatarSize) { (account, data, errorCode, errorMessage) in
+                    NCCommunication.shared.downloadAvatar(user: user, fileNameLocalPath: fileNameLocalPath, size: NCGlobal.shared.avatarSize, etag: nil) { (account, data, etag, errorCode, errorMessage) in
                         if let data = data, let oldData = oldData {
                             do {
                                 let isEqual = try NCUtility.shared.compare(tolerance: 95, expected: data, observed: oldData)

+ 3 - 2
iOSClient/Notification/NCNotification.swift

@@ -136,7 +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 fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + String(CCUtility.getStringUser(appDelegate.user, urlBase: appDelegate.urlBase)) + "-" + userId + ".png"
+                        let userUrlBase = String(CCUtility.getStringUser(appDelegate.user, urlBase: appDelegate.urlBase))
+                        let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + userUrlBase + "-" + userId + ".png"
                         if FileManager.default.fileExists(atPath: fileNameLocalPath) {
                             if let image = UIImage(contentsOfFile: fileNameLocalPath) {
                                 cell.avatar.isHidden = false
@@ -147,7 +148,7 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
                             cell.avatar.isHidden = false
                             cell.avatarLeadingMargin.constant = 50
                             cell.fileUser = userId
-                            NCOperationQueue.shared.downloadAvatar(user: userId, fileNameLocalPath: fileNameLocalPath, placeholder: UIImage(named: "avatar"), cell: cell, view: tableView)
+                            NCOperationQueue.shared.downloadAvatar(user: userId, userUrlBase: userUrlBase, fileNameLocalPath: fileNameLocalPath, placeholder: UIImage(named: "avatar"), cell: cell, view: tableView)
                         }
                     }
                 }

+ 3 - 2
iOSClient/Select/NCSelect.swift

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

+ 7 - 5
iOSClient/Share/NCShare.swift

@@ -102,7 +102,7 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel
                     sharedWithYouByImage.image = NCUtility.shared.createAvatar(image: image, size: 40)
                 }
             } else {
-                NCCommunication.shared.downloadAvatar(user: metadata!.ownerId, fileNameLocalPath: fileNameLocalPath, size: NCGlobal.shared.avatarSize) { (account, data, errorCode, errorMessage) in
+                NCCommunication.shared.downloadAvatar(user: metadata!.ownerId, fileNameLocalPath: fileNameLocalPath, size: NCGlobal.shared.avatarSize, etag: nil) { (account, data, etag, errorCode, errorMessage) in
                     if errorCode == 0 && account == self.appDelegate.account && UIImage(data: data!) != nil {
                         if let image = UIImage(contentsOfFile: fileNameLocalPath) {
                             self.sharedWithYouByImage.image = NCUtility.shared.createAvatar(image: image, size: 40)
@@ -333,8 +333,9 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel
             } else {
                 cell.centerTitle.constant = 0
             }
-            let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + String(CCUtility.getStringUser(self.appDelegate.user, urlBase: self.appDelegate.urlBase)) + "-" + sharee.label + ".png"
-            NCOperationQueue.shared.downloadAvatar(user: sharee.shareWith, fileNameLocalPath: fileNameLocalPath, placeholder: UIImage(named: "avatar"), cell: cell, view: nil)
+            let userUrlBase = String(CCUtility.getStringUser(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)
             cell.imageShareeType.image = NCShareCommon.shared.getImageShareType(shareType: sharee.shareType)
         }
         
@@ -411,8 +412,9 @@ extension NCShare: UITableViewDataSource {
                 cell.imageStatus.image = status.onlineStatus
                 cell.status.text = status.statusMessage
                 
-                let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + String(CCUtility.getStringUser(appDelegate.user, urlBase: appDelegate.urlBase)) + "-" + tableShare.shareWith + ".png"
-                NCOperationQueue.shared.downloadAvatar(user: tableShare.shareWith, fileNameLocalPath: fileNameLocalPath, placeholder: UIImage(named: "avatar"), cell: cell, view: tableView)
+                let userUrlBase = String(CCUtility.getStringUser(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)
                 
                 // 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 {

+ 3 - 2
iOSClient/Share/NCShareComments.swift

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