|
@@ -41,9 +41,17 @@ class NCService: NSObject {
|
|
|
NCManageDatabase.shared.clearAllAvatarLoaded()
|
|
|
guard !appDelegate.account.isEmpty else { return }
|
|
|
|
|
|
- addInternalTypeIdentifier()
|
|
|
- requestServerStatus()
|
|
|
- requestUserProfile()
|
|
|
+ Task {
|
|
|
+ addInternalTypeIdentifier()
|
|
|
+ let result = await requestServerStatus()
|
|
|
+ if result.serverStatus, let tableAccount = result.tableAccount {
|
|
|
+ synchronize(tableAccount: tableAccount)
|
|
|
+ getAvatar(tableAccount: tableAccount)
|
|
|
+ requestServerCapabilities()
|
|
|
+ requestDashboardWidget()
|
|
|
+ NCNetworkingE2EE.shared.unlockAll(account: tableAccount.account)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// MARK: -
|
|
@@ -81,91 +89,76 @@ class NCService: NSObject {
|
|
|
|
|
|
// MARK: -
|
|
|
|
|
|
- private func requestServerStatus() {
|
|
|
+ private func requestServerStatus() async -> (serverStatus: Bool, tableAccount: tableAccount?) {
|
|
|
|
|
|
let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)
|
|
|
|
|
|
- NextcloudKit.shared.getServerStatus(serverUrl: appDelegate.urlBase, options: options) { serverProductName, _, versionMajor, _, _, extendedSupport, data, error in
|
|
|
- guard error == .success, extendedSupport == false else {
|
|
|
- return
|
|
|
- }
|
|
|
+ let resultServerStatus = await NextcloudKit.shared.getServerStatus(serverUrl: appDelegate.urlBase, options: options)
|
|
|
+ let resultUserProfile = await NextcloudKit.shared.getUserProfile(options: options)
|
|
|
|
|
|
- if serverProductName == "owncloud" {
|
|
|
- let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_warning_owncloud_")
|
|
|
- NCContentPresenter.shared.showWarning(error: error, priority: .max)
|
|
|
- } else if versionMajor <= NCGlobal.shared.nextcloud_unsupported_version {
|
|
|
- let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_warning_unsupported_")
|
|
|
- NCContentPresenter.shared.showWarning(error: error, priority: .max)
|
|
|
- }
|
|
|
+ if resultServerStatus.maintenance {
|
|
|
+ let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_maintenance_mode_")
|
|
|
+ NCContentPresenter.shared.showWarning(error: error, priority: .max)
|
|
|
+ return (false, nil)
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- // MARK: -
|
|
|
|
|
|
- private func requestUserProfile() {
|
|
|
- guard !appDelegate.account.isEmpty else { return }
|
|
|
-
|
|
|
- let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)
|
|
|
+ if let serverProductName = resultServerStatus.serverProductName, serverProductName.contains("owncloud") {
|
|
|
+ let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_warning_owncloud_")
|
|
|
+ NCContentPresenter.shared.showWarning(error: error, priority: .max)
|
|
|
+ }
|
|
|
|
|
|
- NextcloudKit.shared.getUserProfile(options: options) { account, userProfile, data, error in
|
|
|
- guard error == .success, let userProfile = userProfile else {
|
|
|
-
|
|
|
- // Ops the server has Unauthorized
|
|
|
- NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] The server has response with Unauthorized \(error.errorCode)")
|
|
|
-
|
|
|
- DispatchQueue.main.async {
|
|
|
- if (UIApplication.shared.applicationState == .active) &&
|
|
|
- (NCNetworking.shared.networkReachability != NKCommon.TypeReachability.notReachable) &&
|
|
|
- (error.errorCode == NCGlobal.shared.errorNCUnauthorized || error.errorCode == NCGlobal.shared.errorUnauthorized || error.errorCode == NCGlobal.shared.errorForbidden) {
|
|
|
-
|
|
|
- NCBrandColor.shared.settingThemingColor(account: account)
|
|
|
- NCNetworkingCheckRemoteUser().checkRemoteUser(account: account, error: error)
|
|
|
- }
|
|
|
- }
|
|
|
- return
|
|
|
- }
|
|
|
+ if resultServerStatus.versionMajor <= NCGlobal.shared.nextcloud_unsupported_version {
|
|
|
+ let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_warning_unsupported_")
|
|
|
+ NCContentPresenter.shared.showWarning(error: error, priority: .max)
|
|
|
+ }
|
|
|
|
|
|
- // Update User (+ userProfile.id) & active account & account network
|
|
|
- guard let tableAccount = NCManageDatabase.shared.setAccountUserProfile(account: account, userProfile: userProfile) else {
|
|
|
+ if resultUserProfile.error == .success, let userProfile = resultUserProfile.userProfile {
|
|
|
+ guard let tableAccount = NCManageDatabase.shared.setAccountUserProfile(account: resultUserProfile.account, userProfile: userProfile) else {
|
|
|
let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "Internal error : account not found on DB")
|
|
|
NCContentPresenter.shared.showError(error: error, priority: .max)
|
|
|
- return
|
|
|
+ return (false, nil)
|
|
|
+ }
|
|
|
+ await self.appDelegate.settingAccount(tableAccount.account, urlBase: tableAccount.urlBase, user: tableAccount.user, userId: tableAccount.userId, password: CCUtility.getPassword(tableAccount.account))
|
|
|
+ return (true, tableAccount)
|
|
|
+ } else if resultUserProfile.error.errorCode == NCGlobal.shared.errorUnauthorized {
|
|
|
+ // Ops the server has Unauthorized
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ if UIApplication.shared.applicationState == .active && NCNetworking.shared.networkReachability != NKCommon.TypeReachability.notReachable {
|
|
|
+ NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] The server has response with Unauthorized \(resultUserProfile.error.errorCode)")
|
|
|
+ NCNetworkingCheckRemoteUser().checkRemoteUser(account: resultUserProfile.account, error: resultUserProfile.error)
|
|
|
+ }
|
|
|
}
|
|
|
+ return (false, nil)
|
|
|
+ }
|
|
|
|
|
|
- self.appDelegate.settingAccount(tableAccount.account, urlBase: tableAccount.urlBase, user: tableAccount.user, userId: tableAccount.userId, password: CCUtility.getPassword(tableAccount.account))
|
|
|
+ return (false, nil)
|
|
|
+ }
|
|
|
|
|
|
- // Synchronize favorite
|
|
|
- NCNetworking.shared.listingFavoritescompletion(selector: NCGlobal.shared.selectorReadFile) { _, _, _ in }
|
|
|
+ func synchronize(tableAccount: tableAccount) {
|
|
|
|
|
|
- // Synchronize Offline
|
|
|
- self.synchronizeOffline(account: tableAccount.account)
|
|
|
+ NCNetworking.shared.listingFavoritescompletion(selector: NCGlobal.shared.selectorReadFile) { _, _, _ in }
|
|
|
+ self.synchronizeOffline(account: tableAccount.account)
|
|
|
+ }
|
|
|
|
|
|
- // Get Avatar
|
|
|
- let fileName = tableAccount.userBaseUrl + "-" + self.appDelegate.user + ".png"
|
|
|
- let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
|
|
|
- let etag = NCManageDatabase.shared.getTableAvatar(fileName: fileName)?.etag
|
|
|
- let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)
|
|
|
+ func getAvatar(tableAccount: tableAccount) {
|
|
|
|
|
|
- NextcloudKit.shared.downloadAvatar(user: tableAccount.userId, fileNameLocalPath: fileNameLocalPath, sizeImage: NCGlobal.shared.avatarSize, avatarSizeRounded: NCGlobal.shared.avatarSizeRounded, etag: etag, options: options) { _, _, _, etag, error in
|
|
|
- guard let etag = etag, error == .success else {
|
|
|
- if error.errorCode == NCGlobal.shared.errorNotModified {
|
|
|
- NCManageDatabase.shared.setAvatarLoaded(fileName: fileName)
|
|
|
- }
|
|
|
- return
|
|
|
+ let fileName = tableAccount.userBaseUrl + "-" + self.appDelegate.user + ".png"
|
|
|
+ let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
|
|
|
+ let etag = NCManageDatabase.shared.getTableAvatar(fileName: fileName)?.etag
|
|
|
+ let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)
|
|
|
+
|
|
|
+ NextcloudKit.shared.downloadAvatar(user: tableAccount.userId, fileNameLocalPath: fileNameLocalPath, sizeImage: NCGlobal.shared.avatarSize, avatarSizeRounded: NCGlobal.shared.avatarSizeRounded, etag: etag, options: options) { _, _, _, etag, error in
|
|
|
+ guard let etag = etag, error == .success else {
|
|
|
+ if error.errorCode == NCGlobal.shared.errorNotModified {
|
|
|
+ NCManageDatabase.shared.setAvatarLoaded(fileName: fileName)
|
|
|
}
|
|
|
- NCManageDatabase.shared.addAvatar(fileName: fileName, etag: etag)
|
|
|
- NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadAvatar, userInfo: nil)
|
|
|
+ return
|
|
|
}
|
|
|
-
|
|
|
- self.requestServerCapabilities()
|
|
|
- self.requestDashboardWidget()
|
|
|
- // Unlock E2EE
|
|
|
- NCNetworkingE2EE.shared.unlockAll(account: account)
|
|
|
+ NCManageDatabase.shared.addAvatar(fileName: fileName, etag: etag)
|
|
|
+ NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadAvatar, userInfo: nil)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // MARK: -
|
|
|
-
|
|
|
private func requestServerCapabilities() {
|
|
|
guard !appDelegate.account.isEmpty else { return }
|
|
|
|