|
@@ -83,57 +83,54 @@ class NCService: NSObject {
|
|
|
|
|
|
if appDelegate.account == "" { return }
|
|
|
|
|
|
- NCCommunication.shared.getUserProfile() { (account, userProfile, errorCode, errorDescription) in
|
|
|
+ NCCommunication.shared.getUserProfile(queue: NCGlobal.shared.backgroundQueue) { (account, userProfile, errorCode, errorDescription) in
|
|
|
|
|
|
if errorCode == 0 && account == self.appDelegate.account {
|
|
|
|
|
|
- DispatchQueue.global().async {
|
|
|
-
|
|
|
- // Update User (+ userProfile.id) & active account & account network
|
|
|
- guard let tableAccount = NCManageDatabase.shared.setAccountUserProfile(userProfile!) else {
|
|
|
- NCContentPresenter.shared.messageNotification("Account", description: "Internal error : account not found on DB", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: NCGlobal.shared.errorInternalError)
|
|
|
- return
|
|
|
- }
|
|
|
+ // Update User (+ userProfile.id) & active account & account network
|
|
|
+ guard let tableAccount = NCManageDatabase.shared.setAccountUserProfile(userProfile!) else {
|
|
|
+ NCContentPresenter.shared.messageNotification("Account", description: "Internal error : account not found on DB", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: NCGlobal.shared.errorInternalError)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ let user = tableAccount.user
|
|
|
+ let url = tableAccount.urlBase
|
|
|
|
|
|
- let user = tableAccount.user
|
|
|
- let url = tableAccount.urlBase
|
|
|
-
|
|
|
- self.appDelegate.settingAccount(tableAccount.account, urlBase: tableAccount.urlBase, user: tableAccount.user, userId: tableAccount.userId, password: CCUtility.getPassword(tableAccount.account))
|
|
|
-
|
|
|
- // Synchronize favorite
|
|
|
- NCNetworking.shared.listingFavoritescompletion(selector: NCGlobal.shared.selectorReadFile) { (_, _, _, _) in }
|
|
|
+ self.appDelegate.settingAccount(tableAccount.account, urlBase: tableAccount.urlBase, user: tableAccount.user, userId: tableAccount.userId, password: CCUtility.getPassword(tableAccount.account))
|
|
|
+
|
|
|
+ // Synchronize favorite
|
|
|
+ NCNetworking.shared.listingFavoritescompletion(selector: NCGlobal.shared.selectorReadFile) { (_, _, _, _) in }
|
|
|
+
|
|
|
+ // Synchronize Offline
|
|
|
+ self.synchronizeOffline(account: tableAccount.account)
|
|
|
|
|
|
- // Synchronize Offline
|
|
|
- self.synchronizeOffline(account: tableAccount.account)
|
|
|
-
|
|
|
- // Get Avatar
|
|
|
- let fileName = String(CCUtility.getUserUrlBase(user, urlBase: url)) + "-" + self.appDelegate.user + ".png"
|
|
|
- let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
|
|
|
- let etag = NCManageDatabase.shared.getTableAvatar(fileName: fileName)?.etag
|
|
|
+ // Get Avatar
|
|
|
+ let fileName = String(CCUtility.getUserUrlBase(user, urlBase: url)) + "-" + self.appDelegate.user + ".png"
|
|
|
+ let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
|
|
|
+ let etag = NCManageDatabase.shared.getTableAvatar(fileName: fileName)?.etag
|
|
|
|
|
|
- NCCommunication.shared.downloadAvatar(user: tableAccount.userId, fileNameLocalPath: fileNameLocalPath, sizeImage: NCGlobal.shared.avatarSize, avatarSizeRounded: NCGlobal.shared.avatarSizeRounded, etag: etag, queue: NCGlobal.shared.backgroundQueue) { (account, image, imageOriginal, etag, errorCode, errorMessage) in
|
|
|
+ NCCommunication.shared.downloadAvatar(user: tableAccount.userId, fileNameLocalPath: fileNameLocalPath, sizeImage: NCGlobal.shared.avatarSize, avatarSizeRounded: NCGlobal.shared.avatarSizeRounded, etag: etag, queue: NCGlobal.shared.backgroundQueue) { (account, image, imageOriginal, etag, errorCode, errorMessage) in
|
|
|
|
|
|
- if let etag = etag, errorCode == 0, let imageOriginal = imageOriginal {
|
|
|
-
|
|
|
- do {
|
|
|
- if let pngData = imageOriginal.pngData() {
|
|
|
- let fileName = String(CCUtility.getUserUrlBase(user, urlBase: url)) + "-" + self.appDelegate.user + "-original.png"
|
|
|
- let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
|
|
|
- let url = URL.init(fileURLWithPath: fileNameLocalPath)
|
|
|
- try pngData.write(to: url)
|
|
|
- }
|
|
|
- } catch {}
|
|
|
-
|
|
|
- NCManageDatabase.shared.addAvatar(fileName: fileName, etag: etag)
|
|
|
- NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadAvatar, userInfo: nil)
|
|
|
-
|
|
|
- } else if errorCode == NCGlobal.shared.errorNotModified {
|
|
|
-
|
|
|
- NCManageDatabase.shared.setAvatarLoaded(fileName: fileName)
|
|
|
- }
|
|
|
+ if let etag = etag, errorCode == 0, let imageOriginal = imageOriginal {
|
|
|
+
|
|
|
+ do {
|
|
|
+ if let pngData = imageOriginal.pngData() {
|
|
|
+ let fileName = String(CCUtility.getUserUrlBase(user, urlBase: url)) + "-" + self.appDelegate.user + "-original.png"
|
|
|
+ let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
|
|
|
+ let url = URL.init(fileURLWithPath: fileNameLocalPath)
|
|
|
+ try pngData.write(to: url)
|
|
|
+ }
|
|
|
+ } catch {}
|
|
|
+
|
|
|
+ NCManageDatabase.shared.addAvatar(fileName: fileName, etag: etag)
|
|
|
+ NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadAvatar, userInfo: nil)
|
|
|
+
|
|
|
+ } else if errorCode == NCGlobal.shared.errorNotModified {
|
|
|
+
|
|
|
+ NCManageDatabase.shared.setAvatarLoaded(fileName: fileName)
|
|
|
}
|
|
|
- self.requestServerCapabilities()
|
|
|
}
|
|
|
+ self.requestServerCapabilities()
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -146,19 +143,14 @@ class NCService: NSObject {
|
|
|
|
|
|
private func requestServerStatus() {
|
|
|
|
|
|
- NCCommunication.shared.getServerStatus(serverUrl: appDelegate.urlBase) { (serverProductName, serverVersion, versionMajor, versionMinor, versionMicro, extendedSupport, errorCode, errorMessage) in
|
|
|
+ NCCommunication.shared.getServerStatus(serverUrl: appDelegate.urlBase, queue: NCGlobal.shared.backgroundQueue) { (serverProductName, serverVersion, versionMajor, versionMinor, versionMicro, extendedSupport, errorCode, errorMessage) in
|
|
|
|
|
|
- if errorCode == 0 {
|
|
|
-
|
|
|
- DispatchQueue.global().async {
|
|
|
-
|
|
|
- if extendedSupport == false {
|
|
|
- if serverProductName == "owncloud" {
|
|
|
- NCContentPresenter.shared.messageNotification("_warning_", description: "_warning_owncloud_", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info, errorCode: NCGlobal.shared.errorInternalError)
|
|
|
- } else if versionMajor <= NCGlobal.shared.nextcloud_unsupported_version {
|
|
|
- NCContentPresenter.shared.messageNotification("_warning_", description: "_warning_unsupported_", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info, errorCode: NCGlobal.shared.errorInternalError)
|
|
|
- }
|
|
|
- }
|
|
|
+ if errorCode == 0 && extendedSupport == false {
|
|
|
+
|
|
|
+ if serverProductName == "owncloud" {
|
|
|
+ NCContentPresenter.shared.messageNotification("_warning_", description: "_warning_owncloud_", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info, errorCode: NCGlobal.shared.errorInternalError)
|
|
|
+ } else if versionMajor <= NCGlobal.shared.nextcloud_unsupported_version {
|
|
|
+ NCContentPresenter.shared.messageNotification("_warning_", description: "_warning_unsupported_", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info, errorCode: NCGlobal.shared.errorInternalError)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -168,119 +160,117 @@ class NCService: NSObject {
|
|
|
|
|
|
if appDelegate.account == "" { return }
|
|
|
|
|
|
- NCCommunication.shared.getCapabilities() { (account, data, errorCode, errorDescription) in
|
|
|
+ NCCommunication.shared.getCapabilities(queue: NCGlobal.shared.backgroundQueue) { (account, data, errorCode, errorDescription) in
|
|
|
|
|
|
if errorCode == 0 && data != nil {
|
|
|
|
|
|
- DispatchQueue.global().async {
|
|
|
-
|
|
|
- NCManageDatabase.shared.addCapabilitiesJSon(data!, account: account)
|
|
|
+ NCManageDatabase.shared.addCapabilitiesJSon(data!, account: account)
|
|
|
+
|
|
|
+ let serverVersionMajor = NCManageDatabase.shared.getCapabilitiesServerInt(account: account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
|
|
|
|
|
|
- let serverVersionMajor = NCManageDatabase.shared.getCapabilitiesServerInt(account: account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
|
|
|
-
|
|
|
- // Setup communication
|
|
|
- if serverVersionMajor > 0 {
|
|
|
- NCCommunicationCommon.shared.setup(nextcloudVersion: serverVersionMajor)
|
|
|
- }
|
|
|
- NCCommunicationCommon.shared.setup(webDav: NCUtilityFileSystem.shared.getWebDAV(account: account))
|
|
|
-
|
|
|
- // Theming
|
|
|
- NCBrandColor.shared.settingThemingColor(account: account)
|
|
|
+ // Setup communication
|
|
|
+ if serverVersionMajor > 0 {
|
|
|
+ NCCommunicationCommon.shared.setup(nextcloudVersion: serverVersionMajor)
|
|
|
+ }
|
|
|
+ NCCommunicationCommon.shared.setup(webDav: NCUtilityFileSystem.shared.getWebDAV(account: account))
|
|
|
|
|
|
- // File Sharing
|
|
|
- let isFilesSharingEnabled = NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesFileSharingApiEnabled, exists: false)
|
|
|
- if isFilesSharingEnabled {
|
|
|
- NCCommunication.shared.readShares { (account, shares, errorCode, ErrorDescription) in
|
|
|
- if errorCode == 0 {
|
|
|
-
|
|
|
- NCManageDatabase.shared.deleteTableShare(account: account)
|
|
|
- if shares != nil {
|
|
|
- NCManageDatabase.shared.addShare(urlBase: self.appDelegate.urlBase, account: account, shares: shares!)
|
|
|
- }
|
|
|
- self.appDelegate.shares = NCManageDatabase.shared.getTableShares(account: account)
|
|
|
-
|
|
|
- } else {
|
|
|
- NCContentPresenter.shared.messageNotification("_share_", description: ErrorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
|
|
|
+ // Theming
|
|
|
+ NCBrandColor.shared.settingThemingColor(account: account)
|
|
|
+
|
|
|
+ // File Sharing
|
|
|
+ let isFilesSharingEnabled = NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesFileSharingApiEnabled, exists: false)
|
|
|
+ if isFilesSharingEnabled {
|
|
|
+ NCCommunication.shared.readShares { (account, shares, errorCode, ErrorDescription) in
|
|
|
+ if errorCode == 0 {
|
|
|
+
|
|
|
+ NCManageDatabase.shared.deleteTableShare(account: account)
|
|
|
+ if shares != nil {
|
|
|
+ NCManageDatabase.shared.addShare(urlBase: self.appDelegate.urlBase, account: account, shares: shares!)
|
|
|
}
|
|
|
+ self.appDelegate.shares = NCManageDatabase.shared.getTableShares(account: account)
|
|
|
+
|
|
|
+ } else {
|
|
|
+ NCContentPresenter.shared.messageNotification("_share_", description: ErrorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- let comments = NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesFilesComments, exists: false)
|
|
|
- let activity = NCManageDatabase.shared.getCapabilitiesServerArray(account: account, elements: NCElementsJSON.shared.capabilitiesActivity)
|
|
|
-
|
|
|
- if !isFilesSharingEnabled && !comments && activity == nil {
|
|
|
- self.appDelegate.disableSharesView = true
|
|
|
- } else {
|
|
|
- self.appDelegate.disableSharesView = false
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- // Text direct editor detail
|
|
|
- if serverVersionMajor >= NCGlobal.shared.nextcloudVersion18 {
|
|
|
- NCCommunication.shared.NCTextObtainEditorDetails() { (account, editors, creators, errorCode, errorMessage) in
|
|
|
- if errorCode == 0 && account == self.appDelegate.account {
|
|
|
-
|
|
|
- DispatchQueue.global().async {
|
|
|
-
|
|
|
- NCManageDatabase.shared.addDirectEditing(account: account, editors: editors, creators: creators)
|
|
|
- }
|
|
|
+ let comments = NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesFilesComments, exists: false)
|
|
|
+ let activity = NCManageDatabase.shared.getCapabilitiesServerArray(account: account, elements: NCElementsJSON.shared.capabilitiesActivity)
|
|
|
+
|
|
|
+ if !isFilesSharingEnabled && !comments && activity == nil {
|
|
|
+ self.appDelegate.disableSharesView = true
|
|
|
+ } else {
|
|
|
+ self.appDelegate.disableSharesView = false
|
|
|
+ }
|
|
|
+
|
|
|
+ // Text direct editor detail
|
|
|
+ if serverVersionMajor >= NCGlobal.shared.nextcloudVersion18 {
|
|
|
+ NCCommunication.shared.NCTextObtainEditorDetails() { (account, editors, creators, errorCode, errorMessage) in
|
|
|
+ if errorCode == 0 && account == self.appDelegate.account {
|
|
|
+
|
|
|
+ DispatchQueue.global().async {
|
|
|
+
|
|
|
+ NCManageDatabase.shared.addDirectEditing(account: account, editors: editors, creators: creators)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // External file Server
|
|
|
- let isExternalSitesServerEnabled = NCManageDatabase.shared.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.shared.deleteExternalSites(account: account)
|
|
|
- for externalSite in externalSites {
|
|
|
- NCManageDatabase.shared.addExternalSites(externalSite, account: account)
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ // External file Server
|
|
|
+ let isExternalSitesServerEnabled = NCManageDatabase.shared.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.shared.deleteExternalSites(account: account)
|
|
|
+ for externalSite in externalSites {
|
|
|
+ NCManageDatabase.shared.addExternalSites(externalSite, account: account)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- } else {
|
|
|
- NCManageDatabase.shared.deleteExternalSites(account: account)
|
|
|
}
|
|
|
|
|
|
- // User Status
|
|
|
- let userStatus = NCManageDatabase.shared.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.shared.setAccountUserStatus(userStatusClearAt: clearAt, userStatusIcon: icon, userStatusMessage: message, userStatusMessageId: messageId, userStatusMessageIsPredefined: messageIsPredefined, userStatusStatus: status, userStatusStatusIsUserDefined: statusIsUserDefined, account: account)
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ NCManageDatabase.shared.deleteExternalSites(account: account)
|
|
|
+ }
|
|
|
+
|
|
|
+ // User Status
|
|
|
+ let userStatus = NCManageDatabase.shared.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.shared.setAccountUserStatus(userStatusClearAt: clearAt, userStatusIcon: icon, userStatusMessage: message, userStatusMessageId: messageId, userStatusMessageIsPredefined: messageIsPredefined, userStatusStatus: status, userStatusStatusIsUserDefined: statusIsUserDefined, account: account)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- // Added UTI for Collabora
|
|
|
- if let richdocumentsMimetypes = NCManageDatabase.shared.getCapabilitiesServerArray(account: account, elements: NCElementsJSON.shared.capabilitiesRichdocumentsMimetypes) {
|
|
|
- for mimeType in richdocumentsMimetypes {
|
|
|
- NCCommunicationCommon.shared.addInternalTypeIdentifier(typeIdentifier: mimeType, classFile: NCCommunicationCommon.typeClassFile.document.rawValue, editor: NCGlobal.shared.editorCollabora, iconName: NCCommunicationCommon.typeIconFile.document.rawValue, name: "document")
|
|
|
- }
|
|
|
+ // Added UTI for Collabora
|
|
|
+ if let richdocumentsMimetypes = NCManageDatabase.shared.getCapabilitiesServerArray(account: account, elements: NCElementsJSON.shared.capabilitiesRichdocumentsMimetypes) {
|
|
|
+ for mimeType in richdocumentsMimetypes {
|
|
|
+ NCCommunicationCommon.shared.addInternalTypeIdentifier(typeIdentifier: mimeType, classFile: NCCommunicationCommon.typeClassFile.document.rawValue, editor: NCGlobal.shared.editorCollabora, iconName: NCCommunicationCommon.typeIconFile.document.rawValue, name: "document")
|
|
|
}
|
|
|
-
|
|
|
- // Added UTI for ONLYOFFICE & Text
|
|
|
- if let directEditingCreators = NCManageDatabase.shared.getDirectEditingCreators(account: account) {
|
|
|
- for directEditing in directEditingCreators {
|
|
|
- NCCommunicationCommon.shared.addInternalTypeIdentifier(typeIdentifier: directEditing.mimetype, classFile: NCCommunicationCommon.typeClassFile.document.rawValue, editor: directEditing.editor, iconName: NCCommunicationCommon.typeIconFile.document.rawValue, name: "document")
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Added UTI for ONLYOFFICE & Text
|
|
|
+ if let directEditingCreators = NCManageDatabase.shared.getDirectEditingCreators(account: account) {
|
|
|
+ for directEditing in directEditingCreators {
|
|
|
+ NCCommunicationCommon.shared.addInternalTypeIdentifier(typeIdentifier: directEditing.mimetype, classFile: NCCommunicationCommon.typeClassFile.document.rawValue, editor: directEditing.editor, iconName: NCCommunicationCommon.typeIconFile.document.rawValue, name: "document")
|
|
|
}
|
|
|
-
|
|
|
- // Handwerkcloud
|
|
|
- // let isHandwerkcloudEnabled = NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesHWCEnabled, exists: false)
|
|
|
- // if (isHandwerkcloudEnabled) {
|
|
|
- // self.requestHC()
|
|
|
- // }
|
|
|
}
|
|
|
+
|
|
|
+ // Handwerkcloud
|
|
|
+ // let isHandwerkcloudEnabled = NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesHWCEnabled, exists: false)
|
|
|
+ // if (isHandwerkcloudEnabled) {
|
|
|
+ // self.requestHC()
|
|
|
+ // }
|
|
|
+
|
|
|
|
|
|
} else if errorCode != 0 {
|
|
|
|