Browse Source

change driver

marinofaggiana 5 years ago
parent
commit
4c3d321c2c

+ 1 - 1
Cartfile

@@ -1,4 +1,4 @@
-github "nextcloud/ios-communication-library" "v0.4"
+github "nextcloud/ios-communication-library" "develop"
 github "tilltue/TLPhotoPicker" "2.0.7"
 github "kishikawakatsumi/UICKeyChainStore" "v2.1.2"
 github "danielsaidi/Sheeeeeeeeet" "3.0.9"

+ 1 - 1
Cartfile.resolved

@@ -17,7 +17,7 @@ github "krzyzanowskim/OpenSSL" "1.0.218"
 github "malcommac/SwiftRichString" "3.6.0"
 github "marinofaggiana/AFNetworking" "2967678c3e0e98c9b8d7e06222ad12d1f49c26f2"
 github "marinofaggiana/FastScroll" "81967c2309d29bc2c330d422da612160a30bade8"
-github "nextcloud/ios-communication-library" "v0.4"
+github "nextcloud/ios-communication-library" "da0bdaee5e3b6b3a8ab0ed64dee83fe082a56cef"
 github "realm/realm-cocoa" "v4.1.1"
 github "rechsteiner/Parchment" "v1.7.0"
 github "tilltue/TLPhotoPicker" "2.0.7"

+ 6 - 3
File Provider Extension/FileProviderData.swift

@@ -74,6 +74,7 @@ class fileProviderData: NSObject {
         if domain == nil {
             
             guard let tableAccount = NCManageDatabase.sharedInstance.getAccountActive() else { return false }
+            guard let capabilities = NCManageDatabase.sharedInstance.getCapabilites(account: tableAccount.account) else { return false }
             
             account = tableAccount.account
             accountUser = tableAccount.user
@@ -82,7 +83,7 @@ class fileProviderData: NSObject {
             accountUrl = tableAccount.url
             homeServerUrl = CCUtility.getHomeServerUrlActiveUrl(tableAccount.url)
             
-            NCCommunicationCommon.sharedInstance.setup(username: accountUser, userID: accountUserID,  password: accountPassword, userAgent: CCUtility.getUserAgent(), capabilitiesGroup: NCBrandOptions.sharedInstance.capabilitiesGroups, delegate: NCNetworking.sharedInstance)
+            NCCommunicationCommon.sharedInstance.setup(username: accountUser, userID: accountUserID,  password: accountPassword, userAgent: CCUtility.getUserAgent(), capabilitiesGroup: NCBrandOptions.sharedInstance.capabilitiesGroups, nextcloudVersion: capabilities.versionMajor, delegate: NCNetworking.sharedInstance)
             NCNetworking.sharedInstance.setup(account: tableAccount.account, delegate: providerExtension as? NCNetworkingDelegate)
             
             return true
@@ -96,6 +97,7 @@ class fileProviderData: NSObject {
             guard let host = url.host else { continue }
             let accountDomain = tableAccount.userID + " (" + host + ")"
             if accountDomain == domain {
+                guard let capabilities = NCManageDatabase.sharedInstance.getCapabilites(account: tableAccount.account) else { return false }
                 account = tableAccount.account
                 accountUser = tableAccount.user
                 accountUserID = tableAccount.userID
@@ -104,7 +106,7 @@ class fileProviderData: NSObject {
                 accountUrl = tableAccount.url
                 homeServerUrl = CCUtility.getHomeServerUrlActiveUrl(tableAccount.url)
                 
-                NCCommunicationCommon.sharedInstance.setup(username: accountUser, userID: accountUserID, password: accountPassword, userAgent: CCUtility.getUserAgent(), capabilitiesGroup: NCBrandOptions.sharedInstance.capabilitiesGroups, delegate: NCNetworking.sharedInstance)
+                NCCommunicationCommon.sharedInstance.setup(username: accountUser, userID: accountUserID, password: accountPassword, userAgent: CCUtility.getUserAgent(), capabilitiesGroup: NCBrandOptions.sharedInstance.capabilitiesGroups, nextcloudVersion: capabilities.versionMajor, delegate: NCNetworking.sharedInstance)
                 NCNetworking.sharedInstance.setup(account: tableAccount.account, delegate: providerExtension as? NCNetworkingDelegate)
 
                 foundAccount = true
@@ -125,6 +127,7 @@ class fileProviderData: NSObject {
         
         for tableAccount in tableAccounts {
             if accountFromItemIdentifier == tableAccount.account {
+                guard let capabilities = NCManageDatabase.sharedInstance.getCapabilites(account: tableAccount.account) else { return false }
                 account = tableAccount.account
                 accountUser = tableAccount.user
                 accountUserID = tableAccount.userID
@@ -132,7 +135,7 @@ class fileProviderData: NSObject {
                 accountUrl = tableAccount.url
                 homeServerUrl = CCUtility.getHomeServerUrlActiveUrl(tableAccount.url)
                 
-                NCCommunicationCommon.sharedInstance.setup(username: accountUser, userID: accountUserID, password: accountPassword, userAgent: CCUtility.getUserAgent(), capabilitiesGroup: NCBrandOptions.sharedInstance.capabilitiesGroups, delegate: NCNetworking.sharedInstance)
+                NCCommunicationCommon.sharedInstance.setup(username: accountUser, userID: accountUserID, password: accountPassword, userAgent: CCUtility.getUserAgent(), capabilitiesGroup: NCBrandOptions.sharedInstance.capabilitiesGroups, nextcloudVersion: capabilities.versionMajor, delegate: NCNetworking.sharedInstance)
                 NCNetworking.sharedInstance.setup(account: tableAccount.account, delegate: providerExtension as? NCNetworkingDelegate)
                 
                 foundAccount = true

+ 3 - 1
Share/ShareViewController.m

@@ -61,8 +61,10 @@
         
     } else {
         
+        tableCapabilities *capabilities = [[NCManageDatabase sharedInstance] getCapabilitesWithAccount:tableAccount.account];
+
         // Networking
-        [[NCCommunicationCommon sharedInstance] setupWithUsername:tableAccount.user userID:tableAccount.userID password:[CCUtility getPassword:tableAccount.account] userAgent:[CCUtility getUserAgent] capabilitiesGroup:[NCBrandOptions sharedInstance].capabilitiesGroups delegate:[NCNetworking sharedInstance]];
+        [[NCCommunicationCommon sharedInstance] setupWithUsername:tableAccount.user userID:tableAccount.userID password:[CCUtility getPassword:tableAccount.account] userAgent:[CCUtility getUserAgent] capabilitiesGroup:[NCBrandOptions sharedInstance].capabilitiesGroups nextcloudVersion:capabilities.versionMajor delegate:[NCNetworking sharedInstance]];
        
         _activeAccount = tableAccount.account;
         

+ 8 - 13
iOSClient/Activity/NCActivity.swift

@@ -24,6 +24,7 @@
 import Foundation
 import UIKit
 import SwiftRichString
+import NCCommunication
 
 class NCActivity: UIViewController, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
     
@@ -210,15 +211,14 @@ extension NCActivity: UITableViewDataSource {
                     if let image = UIImage(contentsOfFile: fileNameLocalPath) { cell.icon.image = image }
                 } else {
                     DispatchQueue.global().async {
-                        let encodedString = activity.icon.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
-                        OCNetworking.sharedManager()?.downloadContents(ofUrl: encodedString, completion: { (data, message, errorCode) in
+                        NCCommunication.sharedInstance.downloadContent(urlString: activity.icon, account: self.appDelegate.activeAccount) { (account, data, errorCode, errorMessage) in
                             if errorCode == 0 {
                                 do {
                                     try data!.write(to: NSURL(fileURLWithPath: fileNameLocalPath) as URL, options: .atomic)
                                     if let image = UIImage(contentsOfFile: fileNameLocalPath) { cell.icon.image = image }
                                 } catch { return }
                             }
-                        })
+                        }
                     }
                 }
             }
@@ -236,16 +236,11 @@ extension NCActivity: UITableViewDataSource {
                     }
                 } else {
                     DispatchQueue.global().async {
-                        let url = self.appDelegate.activeUrl + k_avatar + activity.user + "/" + k_avatar_size
-                        let encodedString = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
-                        OCNetworking.sharedManager()?.downloadContents(ofUrl: encodedString, completion: { (data, message, errorCode) in
-                            if errorCode == 0 && UIImage(data: data!) != nil {
-                                do {
-                                    try data!.write(to: NSURL(fileURLWithPath: fileNameLocalPath) as URL, options: .atomic)
-                                } catch { return }
+                        NCCommunication.sharedInstance.downloadAvatar(urlString: self.appDelegate.activeUrl, userID: activity.user, fileNameLocalPath: fileNameLocalPath, size: Int(k_avatar_size), account: self.appDelegate.activeAccount) { (account, data, errorCode, errorMessage) in
+                            if errorCode == 0 && account == self.appDelegate.activeAccount && UIImage(data: data!) != nil {
                                 cell.avatar.image = UIImage(data: data!)
                             }
-                        })
+                        }
                     }
                 }
             }
@@ -458,7 +453,7 @@ extension activityTableViewCell: UICollectionViewDataSource {
                 
                 let source = activityPreview.source
                 
-                NCUtility.sharedInstance.convertSVGtoPNGWriteToUserData(svgUrlString: source, fileName: nil, width: 100, rewrite: false) { (imageNamePath) in
+                NCUtility.sharedInstance.convertSVGtoPNGWriteToUserData(svgUrlString: source, fileName: nil, width: 100, rewrite: false, account: appDelegate.activeAccount) { (imageNamePath) in
                     if imageNamePath != nil {
                         if let image = UIImage(contentsOfFile: imageNamePath!) {
                             cell.imageView.image = image
@@ -472,7 +467,7 @@ extension activityTableViewCell: UICollectionViewDataSource {
                     
                     let source = activityPreview.source
                     
-                    NCUtility.sharedInstance.convertSVGtoPNGWriteToUserData(svgUrlString: source, fileName: nil, width: 100, rewrite: false) { (imageNamePath) in
+                    NCUtility.sharedInstance.convertSVGtoPNGWriteToUserData(svgUrlString: source, fileName: nil, width: 100, rewrite: false, account: appDelegate.activeAccount) { (imageNamePath) in
                         if imageNamePath != nil {
                             if let image = UIImage(contentsOfFile: imageNamePath!) {
                                 cell.imageView.image = image

+ 3 - 2
iOSClient/AppDelegate.m

@@ -430,12 +430,13 @@ PKPushRegistry *pushRegistry;
     self.activeUser = activeUser;
     self.activeUserID = activeUserID;
     self.activePassword = activePassword;
-    
+    tableCapabilities *capabilities = [[NCManageDatabase sharedInstance] getCapabilitesWithAccount:activeAccount];
+
     // Setting Account to Networking
     [CCNetworking sharedNetworking].delegate = [NCNetworkingMain sharedInstance];
     
     [[NCNetworking sharedInstance] setupWithAccount:activeAccount delegate:nil];
-    [[NCCommunicationCommon sharedInstance] setupWithUsername:activeUser userID:activeUserID password:activePassword userAgent:[CCUtility getUserAgent] capabilitiesGroup:[NCBrandOptions sharedInstance].capabilitiesGroups delegate:[NCNetworking sharedInstance]];
+    [[NCCommunicationCommon sharedInstance] setupWithUsername:activeUser userID:activeUserID password:activePassword userAgent:[CCUtility getUserAgent] capabilitiesGroup:[NCBrandOptions sharedInstance].capabilitiesGroups nextcloudVersion:capabilities.versionMajor delegate:[NCNetworking sharedInstance]];
 }
 
 - (void)deleteAccount:(NSString *)account wipe:(BOOL)wipe

+ 1 - 2
iOSClient/CCGlobal.h

@@ -68,8 +68,7 @@
 #define k_flowEndpoint                                  @"/index.php/login/flow"
 
 // Avatar
-#define k_avatar                                        @"/index.php/avatar/"
-#define k_avatar_size                                   "128"
+#define k_avatar_size                                   128
 
 // Passphrase test EndToEnd Encryption
 #define k_passphrase_test                               @"more over television factory tendency independence international intellectual impress interest sentence pony"

+ 12 - 9
iOSClient/Main/NCMainCommon.swift

@@ -24,6 +24,7 @@
 import Foundation
 import TLPhotoPicker
 import ZIPFoundation
+import NCCommunication
 
 //MARK: - Main Common
 
@@ -347,6 +348,12 @@ class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewController
                 } else if FileManager.default.fileExists(atPath: fileNameSource) {
                     cell.shared.image = NCUtility.sharedInstance.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar)
                 } else {
+                    NCCommunication.sharedInstance.downloadAvatar(urlString: appDelegate.activeUrl, userID: metadata.ownerId, fileNameLocalPath: fileNameSource, size: Int(k_avatar_size), account: appDelegate.activeAccount) { (account, data, errorCode, errorMessage) in
+                        if errorCode == 0 && account == self.appDelegate.activeAccount {
+                            cell.shared.image = NCUtility.sharedInstance.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar)
+                        }
+                    }
+                    /*
                     let url = appDelegate.activeUrl + k_avatar + metadata.ownerId + "/" + k_avatar_size
                     let encodedString = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
                     OCNetworking.sharedManager()?.downloadContents(ofUrl: encodedString, completion: { (data, message, errorCode) in
@@ -357,6 +364,7 @@ class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewController
                             } catch {  }
                         }
                     })
+                    */
                 }
             }
             
@@ -672,16 +680,11 @@ class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewController
                         cell.shared.image = avatar
                     }
                 } else {
-                    let url = appDelegate.activeUrl + k_avatar + metadata.ownerId + "/" + k_avatar_size
-                    let encodedString = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
-                    OCNetworking.sharedManager()?.downloadContents(ofUrl: encodedString, completion: { (data, message, errorCode) in
-                        if errorCode == 0 {
-                            do {
-                                try data!.write(to: NSURL(fileURLWithPath: fileNameSource) as URL, options: .atomic)
-                                 cell.shared.image = NCUtility.sharedInstance.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar)
-                            } catch {  }
+                    NCCommunication.sharedInstance.downloadAvatar(urlString: appDelegate.activeUrl, userID: metadata.ownerId, fileNameLocalPath: fileNameSource, size: Int(k_avatar_size), account: appDelegate.activeAccount) { (account, data, errorCode, errorMessage) in
+                        if errorCode == 0 && account == self.appDelegate.activeAccount {
+                            cell.shared.image = NCUtility.sharedInstance.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar)
                         }
-                    })
+                    }
                 }
             }
             

+ 17 - 6
iOSClient/Networking/NCService.swift

@@ -80,6 +80,17 @@ class NCService: NSObject {
                     let avatarUrl = "\(self.appDelegate.activeUrl!)/index.php/avatar/\(self.appDelegate.activeUser!)/\(k_avatar_size)".addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)!
                     let fileNamePath = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(user, activeUrl: url) + "-" + self.appDelegate.activeUser + ".png"
                     
+                    NCCommunication.sharedInstance.downloadContent(urlString: avatarUrl, account: self.appDelegate.activeAccount) { (account, data, errorCode, errorMessage) in
+                        if errorCode == 0 {
+                            if let image = UIImage(data: data!) {
+                                try? FileManager.default.removeItem(atPath: fileNamePath)
+                                if let data = image.pngData() {
+                                    try? data.write(to: URL(fileURLWithPath: fileNamePath))
+                                }
+                            }
+                        }
+                    }
+                    /*
                     OCNetworking.sharedManager()?.downloadContents(ofUrl: avatarUrl, completion: { (data, message, errorCode) in
                         if errorCode == 0 {
                             if let image = UIImage(data: data!) {
@@ -90,6 +101,7 @@ class NCService: NSObject {
                             }
                         }
                     })
+                    */
                     
                     DispatchQueue.main.async {
                         NotificationCenter.default.post(name: NSNotification.Name(rawValue: "changeUserProfile"), object: nil)
@@ -148,14 +160,14 @@ class NCService: NSObject {
                         // Download Logo
                         if NCBrandOptions.sharedInstance.use_themingLogo {
                             let fileNameThemingLogo = CCUtility.getStringUser(self.appDelegate.activeUser, activeUrl: self.appDelegate.activeUrl) + "-themingLogo.png"
-                            NCUtility.sharedInstance.convertSVGtoPNGWriteToUserData(svgUrlString: capabilities!.themingLogo, fileName: fileNameThemingLogo, width: 40, rewrite: true, closure: { (imageNamePath) in })
+                            NCUtility.sharedInstance.convertSVGtoPNGWriteToUserData(svgUrlString: capabilities!.themingLogo, fileName: fileNameThemingLogo, width: 40, rewrite: true, account: self.appDelegate.activeAccount, closure: { (imageNamePath) in })
                         }
                         
                         let backgroundURL = capabilities!.themingBackground!.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)!
                         let fileNamePath = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(self.appDelegate.activeUser, activeUrl: self.appDelegate.activeUrl) + "-themingBackground.png"
                         
-                        OCNetworking.sharedManager()?.downloadContents(ofUrl: backgroundURL, completion: { (data, message, errorCode) in
-                            if errorCode == 0 {
+                        NCCommunication.sharedInstance.downloadContent(urlString: backgroundURL, account: self.appDelegate.activeAccount) { (account, data, errorCode, errorMessage) in
+                            if errorCode == 0 && account == self.appDelegate.activeAccount {
                                 if let image = UIImage(data: data!) {
                                     try? FileManager.default.removeItem(atPath: fileNamePath)
                                     if let data = image.pngData() {
@@ -163,8 +175,7 @@ class NCService: NSObject {
                                     }
                                 }
                             }
-                        })
-                        
+                        }
                         DispatchQueue.main.async {
                             self.appDelegate.settingThemingColorBrand()
                         }
@@ -204,7 +215,7 @@ class NCService: NSObject {
                                     let id = (notification as! OCNotifications).idNotification
                                     if let icon = (notification as! OCNotifications).icon {
                                         
-                                        NCUtility.sharedInstance.convertSVGtoPNGWriteToUserData(svgUrlString: icon, fileName: nil, width: 25, rewrite: false, closure: { (imageNamePath) in })                                        
+                                        NCUtility.sharedInstance.convertSVGtoPNGWriteToUserData(svgUrlString: icon, fileName: nil, width: 25, rewrite: false, account: self.appDelegate.activeAccount, closure: { (imageNamePath) in })                                        
                                     }
                                     new = new + String(describing: id)
                                 }

+ 1 - 1
iOSClient/Networking/OCNetworking.h

@@ -39,7 +39,7 @@
 
 - (void)checkServerUrl:(NSString *)serverUrl user:(NSString *)user userID:(NSString *)userID password:(NSString *)password completion:(void (^)(NSString *message, NSInteger errorCode))completion;
 //- (void)serverStatusUrl:(NSString *)serverUrl completion:(void(^)(NSString *serverProductName, NSInteger versionMajor, NSInteger versionMicro, NSInteger versionMinor, BOOL extendedSupport, NSString *message, NSInteger errorCode))completion;
-- (void)downloadContentsOfUrl:(NSString *)serverUrl completion:(void(^)(NSData *data, NSString *message, NSInteger errorCode))completion;
+//- (void)downloadContentsOfUrl:(NSString *)serverUrl completion:(void(^)(NSData *data, NSString *message, NSInteger errorCode))completion;
 - (void)getAppPassword:(NSString *)serverUrl username:(NSString *)username password:(NSString *)password completion:(void(^)(NSString *token, NSString *message, NSInteger errorCode))completion;
 
 #pragma mark ===== Download / Upload =====

+ 2 - 1
iOSClient/Networking/OCNetworking.m

@@ -231,7 +231,7 @@
     [task resume];
 }
 */
-
+/*
 - (void)downloadContentsOfUrl:(NSString *)serverUrl completion:(void(^)(NSData *data, NSString *message, NSInteger errorCode))completion
 {
     // Remove stored cookies
@@ -276,6 +276,7 @@
     
     [task resume];
 }
+*/
 
 - (void)getAppPassword:(NSString *)serverUrl username:(NSString *)username password:(NSString *)password completion:(void(^)(NSString *token, NSString *message, NSInteger errorCode))completion
 {

+ 13 - 0
iOSClient/Notification/CCNotification.swift

@@ -22,6 +22,7 @@
 //
 
 import UIKit
+import NCCommunication
 
 class CCNotification: UITableViewController, CCNotificationCelllDelegate {
     
@@ -109,6 +110,17 @@ class CCNotification: UITableViewController, CCNotificationCelllDelegate {
                         }
                     } else {
                         DispatchQueue.global().async {
+                            
+                            NCCommunication.sharedInstance.downloadAvatar(urlString: self.appDelegate.activeUrl, userID: name, fileNameLocalPath: fileNameLocalPath, size: Int(k_avatar_size), account: self.appDelegate.activeAccount) { (account, data, errorCode, errorMessage) in
+                                if errorCode == 0 && account == self.appDelegate.activeAccount && UIImage(data: data!) != nil {
+                                    if let image = UIImage(contentsOfFile: fileNameLocalPath) {
+                                        cell.avatar.isHidden = false
+                                        cell.avatarLeadingMargin.constant = 50
+                                        cell.avatar.image = image
+                                    }
+                                }
+                            }
+                            /*
                             let url = self.appDelegate.activeUrl + k_avatar + name + "/" + k_avatar_size
                             let encodedString = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
                             OCNetworking.sharedManager()?.downloadContents(ofUrl: encodedString, completion: { (data, message, errorCode) in
@@ -123,6 +135,7 @@ class CCNotification: UITableViewController, CCNotificationCelllDelegate {
                                     } catch { return }
                                 }
                             })
+                            */
                         }
                     }
                 }

+ 24 - 18
iOSClient/Share/NCShare.swift

@@ -24,6 +24,7 @@
 import Foundation
 import Parchment
 import DropDown
+import NCCommunication
 
 class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDelegate, NCShareUserCellDelegate, NCShareNetworkingDelegate {
    
@@ -81,6 +82,16 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel
             if FileManager.default.fileExists(atPath: fileNameLocalPath) {
                 if let image = UIImage(contentsOfFile: fileNameLocalPath) { sharedWithYouByImage.image = image }
             } else {
+                NCCommunication.sharedInstance.downloadAvatar(urlString: appDelegate.activeUrl, userID: metadata!.ownerId, fileNameLocalPath: fileNameLocalPath, size: Int(k_avatar_size), account: appDelegate.activeAccount) { (account, data, errorCode, errorMessage) in
+                    if errorCode == 0 && account == self.appDelegate.activeAccount && UIImage(data: data!) != nil {
+                        if let image = UIImage(contentsOfFile: fileNameLocalPath) {
+                            self.sharedWithYouByImage.image = image
+                        }
+                    } else {
+                        self.sharedWithYouByImage.image = UIImage(named: "avatar")
+                    }
+                }
+                /*
                 let url = appDelegate.activeUrl + k_avatar + metadata!.ownerId + "/" + k_avatar_size
                 let encodedString = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
                 OCNetworking.sharedManager()?.downloadContents(ofUrl: encodedString, completion: { (data, message, errorCode) in
@@ -93,6 +104,7 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel
                         self.sharedWithYouByImage.image = UIImage(named: "avatar")
                     }
                 })
+                */
             }
         } 
         
@@ -288,18 +300,15 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel
                 if let image = UIImage(contentsOfFile: fileNameLocalPath) { cell.imageItem.image = image }
             } else {
                 DispatchQueue.global().async {
-                    let url = self.appDelegate.activeUrl + k_avatar + item.name + "/" + k_avatar_size
-                    let encodedString = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
-                    OCNetworking.sharedManager()?.downloadContents(ofUrl: encodedString, completion: { (data, message, errorCode) in
-                        if errorCode == 0 && UIImage(data: data!) != nil {
-                            do {
-                                try data!.write(to: NSURL(fileURLWithPath: fileNameLocalPath) as URL, options: .atomic)
-                                if let image = UIImage(contentsOfFile: fileNameLocalPath) { cell.imageItem.image = image }
-                            } catch { return }
+                    NCCommunication.sharedInstance.downloadAvatar(urlString: self.appDelegate.activeUrl, userID: item.name, fileNameLocalPath: fileNameLocalPath, size: Int(k_avatar_size), account: self.appDelegate.activeAccount) { (account, data, errorCode, errorMessage) in
+                        if errorCode == 0 && account == self.appDelegate.activeAccount && UIImage(data: data!) != nil {
+                            if let image = UIImage(contentsOfFile: fileNameLocalPath) {
+                                cell.imageItem.image = image
+                            }
                         } else {
                             cell.imageItem.image = UIImage(named: "avatar")
                         }
-                    })
+                    }
                 }
             }
 
@@ -383,18 +392,15 @@ extension NCShare: UITableViewDataSource {
                     if let image = UIImage(contentsOfFile: fileNameLocalPath) { cell.imageItem.image = image }
                 } else {
                     DispatchQueue.global().async {
-                        let url = self.appDelegate.activeUrl + k_avatar + tableShare.shareWith + "/" + k_avatar_size
-                        let encodedString = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
-                        OCNetworking.sharedManager()?.downloadContents(ofUrl: encodedString, completion: { (data, message, errorCode) in
-                            if errorCode == 0 && UIImage(data: data!) != nil {
-                                do {
-                                    try data!.write(to: NSURL(fileURLWithPath: fileNameLocalPath) as URL, options: .atomic)
-                                    if let image = UIImage(contentsOfFile: fileNameLocalPath) { cell.imageItem.image = image }
-                                } catch { return }
+                        NCCommunication.sharedInstance.downloadAvatar(urlString: self.appDelegate.activeUrl, userID: tableShare.shareWith, fileNameLocalPath: fileNameLocalPath, size: Int(k_avatar_size), account: self.appDelegate.activeAccount) { (account, data, errorCode, errorMessage) in
+                            if errorCode == 0 && account == self.appDelegate.activeAccount && UIImage(data: data!) != nil {
+                                if let image = UIImage(contentsOfFile: fileNameLocalPath) {
+                                    cell.imageItem.image = image
+                                }
                             } else {
                                 cell.imageItem.image = UIImage(named: "avatar")
                             }
-                        })
+                        }
                     }
                 }
                 

+ 8 - 0
iOSClient/Share/NCShareComments.swift

@@ -23,6 +23,7 @@
 
 import Foundation
 import Sheeeeeeeeet
+import NCCommunication
 
 class NCShareComments: UIViewController, NCShareCommentsCellDelegate {
    
@@ -242,6 +243,12 @@ extension NCShareComments: UITableViewDataSource {
                 if let image = UIImage(contentsOfFile: fileNameLocalPath) { cell.imageItem.image = image }
             } else {
                 DispatchQueue.global().async {
+                    NCCommunication.sharedInstance.downloadAvatar(urlString: self.appDelegate.activeUrl, userID: tableComments.actorId, fileNameLocalPath: fileNameLocalPath, size: 128, account: self.appDelegate.activeAccount) { (account, data, errorCode, errorMessage) in
+                        if errorCode == 0 && UIImage(data: data!) != nil {
+                            cell.imageItem.image = UIImage(named: "avatar")
+                        }
+                    }
+                    /*
                     let url = self.appDelegate.activeUrl + k_avatar + tableComments.actorId + "/" + k_avatar_size
                     let encodedString = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
                     OCNetworking.sharedManager()?.downloadContents(ofUrl: encodedString, completion: { (data, message, errorCode) in
@@ -254,6 +261,7 @@ extension NCShareComments: UITableViewDataSource {
                             cell.imageItem.image = UIImage(named: "avatar")
                         }
                     })
+                    */
                 }
             }
             // Username

+ 5 - 4
iOSClient/Utility/NCUtility.swift

@@ -26,6 +26,7 @@ import SVGKit
 import KTVHTTPCache
 import ZIPFoundation
 import Sheeeeeeeeet
+import NCCommunication
 
 class NCUtility: NSObject {
     @objc static let sharedInstance: NCUtility = {
@@ -177,7 +178,7 @@ class NCUtility: NSObject {
     }
     
     
-    func convertSVGtoPNGWriteToUserData(svgUrlString: String, fileName: String?, width: CGFloat?, rewrite: Bool, closure: @escaping (String?) -> ()) {
+    func convertSVGtoPNGWriteToUserData(svgUrlString: String, fileName: String?, width: CGFloat?, rewrite: Bool, account: String, closure: @escaping (String?) -> ()) {
         
         var fileNamePNG = ""
         
@@ -198,8 +199,8 @@ class NCUtility: NSObject {
         
         if !FileManager.default.fileExists(atPath: imageNamePath) || rewrite == true {
             
-            OCNetworking.sharedManager()?.downloadContents(ofUrl: iconURL.absoluteString, completion: { (data, message, errorCode) in
-                
+            NCCommunication.sharedInstance.downloadContent(urlString: iconURL.absoluteString, account: account) { (account, data, errorCode, errorMessage) in
+               
                 if errorCode == 0 && data != nil {
                 
                     if let image = UIImage.init(data: data!) {
@@ -253,7 +254,7 @@ class NCUtility: NSObject {
                 } else {
                     return closure(nil)
                 }
-            })
+            }
             
         } else {
             return closure(imageNamePath)