Browse Source

change avatar

Marino Faggiana 6 years ago
parent
commit
58a3e9c893

+ 32 - 11
iOSClient/Activity/NCActivity.swift

@@ -140,11 +140,22 @@ class NCActivity: UIViewController, UITableViewDataSource, UITableViewDelegate,
             
             // icon
             if tableActivity.icon.count > 0 {
-                DispatchQueue.global().async {
-                    let encodedString = tableActivity.icon.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
-                    if let data = try? Data(contentsOf: URL(string: encodedString!)!) {
-                        DispatchQueue.main.async {
-                            cell.icon.image = UIImage(data: data)
+                let fileNameIcon = (tableActivity.icon as NSString).lastPathComponent
+                let fileNameLocalPath = CCUtility.getDirectoryUserData() + "/" + fileNameIcon
+                if FileManager.default.fileExists(atPath: fileNameLocalPath) {
+                    if let image = UIImage(contentsOfFile: fileNameLocalPath) {
+                        cell.icon.image = image
+                    }
+                } else {
+                    DispatchQueue.global().async {
+                        let encodedString = tableActivity.icon.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
+                        if let data = try? Data(contentsOf: URL(string: encodedString!)!) {
+                            DispatchQueue.main.async {
+                                do {
+                                    try data.write(to: fileNameLocalPath.url, options: .atomic)
+                                } catch { return }
+                                cell.icon.image = UIImage(data: data)
+                            }
                         }
                     }
                 }
@@ -152,12 +163,22 @@ class NCActivity: UIViewController, UITableViewDataSource, UITableViewDelegate,
     
             // avatar
             if tableActivity.user.count > 0 {
-                DispatchQueue.global().async {
-                    let url = self.appDelegate.activeUrl + k_avatar + tableActivity.user + "/100"
-                    let encodedString = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
-                    if let data = try? Data(contentsOf: URL(string: encodedString!)!) {
-                        DispatchQueue.main.async {
-                            cell.avatar.image = UIImage(data: data)
+                let fileNameLocalPath = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.activeUser, activeUrl: appDelegate.activeUrl) + "-" + tableActivity.user + ".png"
+                if FileManager.default.fileExists(atPath: fileNameLocalPath) {
+                    if let image = UIImage(contentsOfFile: fileNameLocalPath) {
+                        cell.avatar.image = image
+                    }
+                } else {
+                    DispatchQueue.global().async {
+                        let url = self.appDelegate.activeUrl + k_avatar + tableActivity.user + "/128"
+                        let encodedString = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
+                        if let data = try? Data(contentsOf: URL(string: encodedString!)!) {
+                            DispatchQueue.main.async {
+                                do {
+                                    try data.write(to: fileNameLocalPath.url, options: .atomic)
+                                } catch { return }
+                                cell.avatar.image = UIImage(data: data)
+                            }
                         }
                     }
                 }

+ 1 - 0
iOSClient/Library/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m

@@ -929,6 +929,7 @@ NSString const *OCWebDAVModificationDateKey	= @"modificationdate";
     
     _requestMethod = @"GET";
     
+    since = 0;
     serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"?format=json&since=%ld", (long)since]];
     //serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"&previews=true"]];
     

+ 1 - 1
iOSClient/Main/CCMain.m

@@ -2239,7 +2239,7 @@
         item.argument = account;
         
         tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ ", account]];
-        NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@-avatar.png", [CCUtility getDirectoryUserData], [CCUtility getStringUser:tableAccount.user activeUrl:tableAccount.url]];
+        NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@-%@.png", [CCUtility getDirectoryUserData], [CCUtility getStringUser:tableAccount.user activeUrl:tableAccount.url], tableAccount.user];
         
         UIImage *avatar = [UIImage imageWithContentsOfFile:fileNamePath];
         if (avatar) {

+ 1 - 1
iOSClient/Main/CCMore.swift

@@ -230,7 +230,7 @@ class CCMore: UIViewController, UITableViewDelegate, UITableViewDataSource, CCLo
     
     @objc func changeUserProfile() {
      
-        let fileNamePath = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.activeUser, activeUrl: appDelegate.activeUrl) + "-avatar.png"
+        let fileNamePath = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.activeUser, activeUrl: appDelegate.activeUrl) + "-" + appDelegate.activeUser + ".png"
         var quota: String = ""
         
         if let themingAvatarFile = UIImage.init(contentsOfFile: fileNamePath) {

+ 1 - 1
iOSClient/Main/NCMainCommon.swift

@@ -723,7 +723,7 @@ class NCMainCommon: NSObject, PhotoEditorDelegate {
             if metadata.account != appDelegate.activeAccount {
                 let tableAccount = NCManageDatabase.sharedInstance.getAccount(predicate: NSPredicate(format: "account == %@", metadata.account))
                 if tableAccount != nil {
-                    let fileNamePath = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(tableAccount?.user, activeUrl: tableAccount?.url) + "-avatar.png"
+                    let fileNamePath = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(tableAccount!.user, activeUrl: tableAccount!.url) + "-" + tableAccount!.user + ".png"
                     var avatar = UIImage.init(contentsOfFile: fileNamePath)
                     if avatar != nil {
                         let avatarImageView = CCAvatar.init(image: avatar, borderColor: UIColor.black, borderWidth: 0.5)

+ 1 - 1
iOSClient/Networking/NCService.swift

@@ -299,7 +299,7 @@ class NCService: NSObject {
                 DispatchQueue.global(qos: .default).async {
                     
                     let address = "\(self.appDelegate.activeUrl!)/index.php/avatar/\(self.appDelegate.activeUser!)/128".addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)!
-                    let fileNamePath = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(user, activeUrl: url) + "-avatar.png"
+                    let fileNamePath = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(user, activeUrl: url) + "-" + self.appDelegate.activeUser + ".png"
                     
                     guard let imageData = try? Data(contentsOf: URL(string: address)!) else {
                         DispatchQueue.main.async {

+ 1 - 1
iOSClient/Settings/CCManageAccount.m

@@ -326,7 +326,7 @@
     pickerAccount.rowDescriptor.selectorOptions = listAccount;
     pickerAccount.rowDescriptor.value = appDelegate.activeAccount;
     
-    NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@-avatar.png", [CCUtility getDirectoryUserData], [CCUtility getStringUser:appDelegate.activeUser activeUrl:appDelegate.activeUrl]];
+    NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@-%@.png", [CCUtility getDirectoryUserData], [CCUtility getStringUser:appDelegate.activeUser activeUrl:appDelegate.activeUrl], appDelegate.activeUser];
 
     UIImage *avatar = [UIImage imageWithContentsOfFile:fileNamePath];
     if (avatar) {