|
@@ -52,65 +52,70 @@ class NCService: NSObject {
|
|
|
NCCommunication.shared.getUserProfile() { (account, userProfile, errorCode, errorDescription) in
|
|
|
|
|
|
if errorCode == 0 && account == self.appDelegate.account {
|
|
|
-
|
|
|
- // Update User (+ userProfile.id) & active account & account network
|
|
|
- guard let tableAccount = NCManageDatabase.sharedInstance.setAccountUserProfile(userProfile!) else {
|
|
|
- NCContentPresenter.shared.messageNotification("Account", description: "Internal error : account not found on DB", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorInternalError))
|
|
|
-
|
|
|
- return
|
|
|
- }
|
|
|
+
|
|
|
+ DispatchQueue.global().async {
|
|
|
|
|
|
- let user = tableAccount.user
|
|
|
- let url = tableAccount.urlBase
|
|
|
- let stringUser = CCUtility.getStringUser(user, urlBase: url)!
|
|
|
+ // Update User (+ userProfile.id) & active account & account network
|
|
|
+ guard let tableAccount = NCManageDatabase.sharedInstance.setAccountUserProfile(userProfile!) else {
|
|
|
+ NCContentPresenter.shared.messageNotification("Account", description: "Internal error : account not found on DB", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorInternalError))
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- self.appDelegate.settingAccount(tableAccount.account, urlBase: tableAccount.urlBase, user: tableAccount.user, userID: tableAccount.userID, password: CCUtility.getPassword(tableAccount.account))
|
|
|
+ let user = tableAccount.user
|
|
|
+ let url = tableAccount.urlBase
|
|
|
+ let stringUser = CCUtility.getStringUser(user, urlBase: url)!
|
|
|
+
|
|
|
+ self.appDelegate.settingAccount(tableAccount.account, urlBase: tableAccount.urlBase, user: tableAccount.user, userID: tableAccount.userID, password: CCUtility.getPassword(tableAccount.account))
|
|
|
|
|
|
- // Synchronize favorite ---
|
|
|
- var selector = selectorReadFile
|
|
|
- if CCUtility.getFavoriteOffline() {
|
|
|
- selector = selectorDownloadFile
|
|
|
- }
|
|
|
- NCNetworking.shared.listingFavoritescompletion(selector: selector) { (_, _, _, _) in }
|
|
|
+ // Synchronize favorite
|
|
|
+ var selector = selectorReadFile
|
|
|
+ if CCUtility.getFavoriteOffline() {
|
|
|
+ selector = selectorDownloadFile
|
|
|
+ }
|
|
|
+ NCNetworking.shared.listingFavoritescompletion(selector: selector) { (_, _, _, _) in }
|
|
|
|
|
|
- // Synchronize Offline Directory ---
|
|
|
- if let directories = NCManageDatabase.sharedInstance.getTablesDirectory(predicate: NSPredicate(format: "account == %@ AND offline == true", tableAccount.account), sorted: "serverUrl", ascending: true) {
|
|
|
- for directory: tableDirectory in directories {
|
|
|
- guard let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(directory.ocId) else {
|
|
|
- continue
|
|
|
+ // Synchronize Offline Directory
|
|
|
+ if let directories = NCManageDatabase.sharedInstance.getTablesDirectory(predicate: NSPredicate(format: "account == %@ AND offline == true", tableAccount.account), sorted: "serverUrl", ascending: true) {
|
|
|
+ for directory: tableDirectory in directories {
|
|
|
+ guard let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(directory.ocId) else {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ NCOperationQueue.shared.synchronizationMetadata(metadata, selector: selectorDownloadFile)
|
|
|
}
|
|
|
- NCOperationQueue.shared.synchronizationMetadata(metadata, selector: selectorDownloadFile)
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- // Synchronize Offline Files ---
|
|
|
- let files = NCManageDatabase.sharedInstance.getTableLocalFiles(predicate: NSPredicate(format: "account == %@ AND offline == true", tableAccount.account), sorted: "fileName", ascending: true)
|
|
|
- for file: tableLocalFile in files {
|
|
|
- guard let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(file.ocId) else {
|
|
|
- continue
|
|
|
+ // Synchronize Offline Files
|
|
|
+ let files = NCManageDatabase.sharedInstance.getTableLocalFiles(predicate: NSPredicate(format: "account == %@ AND offline == true", tableAccount.account), sorted: "fileName", ascending: true)
|
|
|
+ for file: tableLocalFile in files {
|
|
|
+ guard let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(file.ocId) else {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ NCOperationQueue.shared.synchronizationMetadata(metadata, selector: selectorDownloadFile)
|
|
|
}
|
|
|
- NCOperationQueue.shared.synchronizationMetadata(metadata, selector: selectorDownloadFile)
|
|
|
- }
|
|
|
-
|
|
|
- let avatarUrl = "\(self.appDelegate.urlBase!)/index.php/avatar/\(self.appDelegate.user!)/\(k_avatar_size)".addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)!
|
|
|
- let fileNamePath = CCUtility.getDirectoryUserData() + "/" + stringUser + "-" + self.appDelegate.user + ".png"
|
|
|
+
|
|
|
+ // Get Avatar
|
|
|
+ let avatarUrl = "\(self.appDelegate.urlBase!)/index.php/avatar/\(self.appDelegate.user!)/\(k_avatar_size)".addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)!
|
|
|
+ let fileNamePath = CCUtility.getDirectoryUserData() + "/" + stringUser + "-" + self.appDelegate.user + ".png"
|
|
|
+ NCCommunication.shared.downloadContent(serverUrl: avatarUrl) { (account, data, errorCode, errorMessage) in
|
|
|
|
|
|
- NCCommunication.shared.downloadContent(serverUrl: avatarUrl) { (account, data, errorCode, errorMessage) in
|
|
|
- if errorCode == 0 {
|
|
|
- DispatchQueue.global().async {
|
|
|
- if let image = UIImage(data: data!) {
|
|
|
- try? FileManager.default.removeItem(atPath: fileNamePath)
|
|
|
- if let data = image.pngData() {
|
|
|
- try? data.write(to: URL(fileURLWithPath: fileNamePath))
|
|
|
+ if errorCode == 0 {
|
|
|
+
|
|
|
+ DispatchQueue.global().async {
|
|
|
+
|
|
|
+ if let image = UIImage(data: data!) {
|
|
|
+ try? FileManager.default.removeItem(atPath: fileNamePath)
|
|
|
+ if let data = image.pngData() {
|
|
|
+ try? data.write(to: URL(fileURLWithPath: fileNamePath))
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ NotificationCenter.default.postOnMainThread(name: k_notificationCenter_changeUserProfile)
|
|
|
+
|
|
|
+ self.requestServerCapabilities()
|
|
|
}
|
|
|
-
|
|
|
- NotificationCenter.default.postOnMainThread(name: k_notificationCenter_changeUserProfile)
|
|
|
-
|
|
|
- self.requestServerCapabilities()
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -124,12 +129,17 @@ class NCService: NSObject {
|
|
|
private func requestServerStatus() {
|
|
|
|
|
|
NCCommunication.shared.getServerStatus(serverUrl: appDelegate.urlBase) { (serverProductName, serverVersion, versionMajor, versionMinor, versionMicro, extendedSupport, errorCode, errorMessage) in
|
|
|
+
|
|
|
if errorCode == 0 {
|
|
|
- if extendedSupport == false {
|
|
|
- if serverProductName == "owncloud" {
|
|
|
- NCContentPresenter.shared.messageNotification("_warning_", description: "_warning_owncloud_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.info, errorCode: Int(k_dismissAfterSecondLong))
|
|
|
- } else if versionMajor <= k_nextcloud_unsupported {
|
|
|
- NCContentPresenter.shared.messageNotification("_warning_", description: "_warning_unsupported_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.info, errorCode: Int(k_dismissAfterSecondLong))
|
|
|
+
|
|
|
+ DispatchQueue.global().async {
|
|
|
+
|
|
|
+ if extendedSupport == false {
|
|
|
+ if serverProductName == "owncloud" {
|
|
|
+ NCContentPresenter.shared.messageNotification("_warning_", description: "_warning_owncloud_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.info, errorCode: Int(k_dismissAfterSecondLong))
|
|
|
+ } else if versionMajor <= k_nextcloud_unsupported {
|
|
|
+ NCContentPresenter.shared.messageNotification("_warning_", description: "_warning_unsupported_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.info, errorCode: Int(k_dismissAfterSecondLong))
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -144,69 +154,92 @@ class NCService: NSObject {
|
|
|
|
|
|
if errorCode == 0 && data != nil {
|
|
|
|
|
|
- NCManageDatabase.sharedInstance.addCapabilitiesJSon(data!, account: account)
|
|
|
-
|
|
|
- // Setup communication
|
|
|
- self.appDelegate.settingSetupCommunication(account)
|
|
|
-
|
|
|
- // Theming
|
|
|
- NCBrandColor.sharedInstance.settingThemingColor()
|
|
|
-
|
|
|
- // File Sharing
|
|
|
- let isFilesSharingEnabled = NCManageDatabase.sharedInstance.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesFileSharingApiEnabled, exists: false)
|
|
|
- if isFilesSharingEnabled {
|
|
|
- NCCommunication.shared.readShares { (account, shares, errorCode, ErrorDescription) in
|
|
|
- if errorCode == 0 {
|
|
|
- NCManageDatabase.sharedInstance.deleteTableShare(account: account)
|
|
|
- if shares != nil {
|
|
|
- NCManageDatabase.sharedInstance.addShare(urlBase: self.appDelegate.urlBase, account: account, shares: shares!)
|
|
|
+ DispatchQueue.global().async {
|
|
|
+
|
|
|
+ NCManageDatabase.sharedInstance.addCapabilitiesJSon(data!, account: account)
|
|
|
+
|
|
|
+ // Setup communication
|
|
|
+ self.appDelegate.settingSetupCommunication(account)
|
|
|
+
|
|
|
+ // Theming
|
|
|
+ NCBrandColor.sharedInstance.settingThemingColor()
|
|
|
+
|
|
|
+ // File Sharing
|
|
|
+ let isFilesSharingEnabled = NCManageDatabase.sharedInstance.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesFileSharingApiEnabled, exists: false)
|
|
|
+ if isFilesSharingEnabled {
|
|
|
+ NCCommunication.shared.readShares { (account, shares, errorCode, ErrorDescription) in
|
|
|
+ if errorCode == 0 {
|
|
|
+
|
|
|
+ DispatchQueue.global().async {
|
|
|
+
|
|
|
+ NCManageDatabase.sharedInstance.deleteTableShare(account: account)
|
|
|
+ if shares != nil {
|
|
|
+ NCManageDatabase.sharedInstance.addShare(urlBase: self.appDelegate.urlBase, account: account, shares: shares!)
|
|
|
+ }
|
|
|
+ self.appDelegate.shares = NCManageDatabase.sharedInstance.getTableShares(account: account)
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ NCContentPresenter.shared.messageNotification("_share_", description: ErrorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
|
|
|
}
|
|
|
- self.appDelegate.shares = NCManageDatabase.sharedInstance.getTableShares(account: account)
|
|
|
- } else {
|
|
|
- NCContentPresenter.shared.messageNotification("_share_", description: ErrorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- // NCTextObtainEditorDetails
|
|
|
- let serverVersionMajor = NCManageDatabase.sharedInstance.getCapabilitiesServerInt(account: account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
|
|
|
- if serverVersionMajor >= k_nextcloud_version_18_0 {
|
|
|
- NCCommunication.shared.NCTextObtainEditorDetails() { (account, editors, creators, errorCode, errorMessage) in
|
|
|
- if errorCode == 0 && account == self.appDelegate.account {
|
|
|
- NCManageDatabase.sharedInstance.addDirectEditing(account: account, editors: editors, creators: creators)
|
|
|
+
|
|
|
+ // Text direct editor detail
|
|
|
+ let serverVersionMajor = NCManageDatabase.sharedInstance.getCapabilitiesServerInt(account: account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
|
|
|
+ if serverVersionMajor >= k_nextcloud_version_18_0 {
|
|
|
+ NCCommunication.shared.NCTextObtainEditorDetails() { (account, editors, creators, errorCode, errorMessage) in
|
|
|
+ if errorCode == 0 && account == self.appDelegate.account {
|
|
|
+
|
|
|
+ DispatchQueue.global().async {
|
|
|
+
|
|
|
+ NCManageDatabase.sharedInstance.addDirectEditing(account: account, editors: editors, creators: creators)
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- // External Site
|
|
|
- let isExternalSitesServerEnabled = NCManageDatabase.sharedInstance.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesExternalSitesExists, exists: true)
|
|
|
- if (isExternalSitesServerEnabled) {
|
|
|
- NCCommunication.shared.getExternalSite() { (account, externalSites, errorCode, errorDescription) in
|
|
|
- if errorCode == 0 && account == self.appDelegate.account {
|
|
|
- NCManageDatabase.sharedInstance.deleteExternalSites(account: account)
|
|
|
- for externalSite in externalSites {
|
|
|
- NCManageDatabase.sharedInstance.addExternalSites(externalSite, account: account)
|
|
|
+
|
|
|
+ // External file Server
|
|
|
+ let isExternalSitesServerEnabled = NCManageDatabase.sharedInstance.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesExternalSitesExists, exists: true)
|
|
|
+ if (isExternalSitesServerEnabled) {
|
|
|
+ NCCommunication.shared.getExternalSite() { (account, externalSites, errorCode, errorDescription) in
|
|
|
+ if errorCode == 0 && account == self.appDelegate.account {
|
|
|
+
|
|
|
+ DispatchQueue.global().async {
|
|
|
+
|
|
|
+ NCManageDatabase.sharedInstance.deleteExternalSites(account: account)
|
|
|
+ for externalSite in externalSites {
|
|
|
+ NCManageDatabase.sharedInstance.addExternalSites(externalSite, account: account)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ } else {
|
|
|
+ NCManageDatabase.sharedInstance.deleteExternalSites(account: account)
|
|
|
}
|
|
|
- } else {
|
|
|
- NCManageDatabase.sharedInstance.deleteExternalSites(account: account)
|
|
|
- }
|
|
|
-
|
|
|
- // User Status
|
|
|
- let userStatus = NCManageDatabase.sharedInstance.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesUserStatusEnabled, exists: false)
|
|
|
- if userStatus {
|
|
|
- NCCommunication.shared.getUserStatus { (account, clearAt, icon, message, messageId, messageIsPredefined, status, statusIsUserDefined, userId, errorCode, errorDescription) in
|
|
|
- if errorCode == 0 && account == self.appDelegate.account && userId == self.appDelegate.userID {
|
|
|
- NCManageDatabase.sharedInstance.setAccountUserStatus(userStatusClearAt: clearAt, userStatusIcon: icon, userStatusMessage: message, userStatusMessageId: messageId, userStatusMessageIsPredefined: messageIsPredefined, userStatusStatus: status, userStatusStatusIsUserDefined: statusIsUserDefined, account: account)
|
|
|
+
|
|
|
+ // User Status
|
|
|
+ let userStatus = NCManageDatabase.sharedInstance.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesUserStatusEnabled, exists: false)
|
|
|
+ if userStatus {
|
|
|
+ NCCommunication.shared.getUserStatus { (account, clearAt, icon, message, messageId, messageIsPredefined, status, statusIsUserDefined, userId, errorCode, errorDescription) in
|
|
|
+ if errorCode == 0 && account == self.appDelegate.account && userId == self.appDelegate.userID {
|
|
|
+
|
|
|
+ DispatchQueue.global().async {
|
|
|
+
|
|
|
+ NCManageDatabase.sharedInstance.setAccountUserStatus(userStatusClearAt: clearAt, userStatusIcon: icon, userStatusMessage: message, userStatusMessageId: messageId, userStatusMessageIsPredefined: messageIsPredefined, userStatusStatus: status, userStatusStatusIsUserDefined: statusIsUserDefined, account: account)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- // Handwerkcloud
|
|
|
- let isHandwerkcloudEnabled = NCManageDatabase.sharedInstance.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesHWCEnabled, exists: false)
|
|
|
- if (isHandwerkcloudEnabled) {
|
|
|
- self.requestHC()
|
|
|
+
|
|
|
+ // Handwerkcloud
|
|
|
+ let isHandwerkcloudEnabled = NCManageDatabase.sharedInstance.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesHWCEnabled, exists: false)
|
|
|
+ if (isHandwerkcloudEnabled) {
|
|
|
+ self.requestHC()
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
} else if errorCode != 0 {
|