Skip to content

Commit

Permalink
Improvements code
Browse files Browse the repository at this point in the history
Signed-off-by: Marino Faggiana <[email protected]>
  • Loading branch information
marinofaggiana committed Oct 2, 2023
1 parent f38f847 commit 01b74e5
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 114 deletions.
4 changes: 2 additions & 2 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -4670,7 +4670,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 13;
CURRENT_PROJECT_VERSION = 14;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = NKUJUXUJ3B;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down Expand Up @@ -4735,7 +4735,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 13;
CURRENT_PROJECT_VERSION = 14;
DEVELOPMENT_TEAM = NKUJUXUJ3B;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand Down
28 changes: 20 additions & 8 deletions iOSClient/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
var documentPickerViewController: NCDocumentPickerViewController?
var timerErrorNetworking: Timer?

var isAppRefresh: Bool = false
var isAppProcessing: Bool = false

private var privacyProtectionWindow: UIWindow?

var isUiTestingEnabled: Bool {
Expand Down Expand Up @@ -323,32 +326,41 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
func handleAppRefresh(_ task: BGTask) {
scheduleAppRefresh()

guard !account.isEmpty else {
task.setTaskCompleted(success: true)
return
guard !account.isEmpty, !isAppProcessing else {
return task.setTaskCompleted(success: true)
}

isAppRefresh = true
NextcloudKit.shared.setup(delegate: NCNetworking.shared)

NCAutoUpload.shared.initAutoUpload(viewController: nil) { items in
NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Refresh task auto upload with \(items) uploads")
NCNetworkingProcessUpload.shared.start { items in
NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Refresh task upload process with \(items) uploads")
task.setTaskCompleted(success: true)
self.isAppRefresh = false
}
}
}

func handleProcessingTask(_ task: BGTask) {
scheduleAppProcessing()

guard !account.isEmpty else {
task.setTaskCompleted(success: true)
return
guard !account.isEmpty, !isAppRefresh else {
return task.setTaskCompleted(success: true)
}

NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Processing task: none")
task.setTaskCompleted(success: true)
isAppProcessing = true
NextcloudKit.shared.setup(delegate: NCNetworking.shared)

NCAutoUpload.shared.initAutoUpload(viewController: nil) { items in
NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Processing task auto upload with \(items) uploads")
NCNetworkingProcessUpload.shared.start { items in
NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Processing task upload process with \(items) uploads")
task.setTaskCompleted(success: true)
self.isAppProcessing = false
}
}
}

// MARK: - Background Networking Session
Expand Down
38 changes: 17 additions & 21 deletions iOSClient/Favorites/NCFavorite.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class NCFavorite: NCCollectionViewCommon {
layoutKey = NCGlobal.shared.layoutViewFavorite
enableSearchBar = false
headerMenuButtonsView = true
headerRichWorkspaceDisable = true
headerRichWorkspaceDisable = false
emptyImage = UIImage(named: "star.fill")?.image(color: NCBrandColor.shared.yellowFavorite, size: UIScreen.main.bounds.width)
emptyTitle = "_favorite_no_files_"
emptyDescription = "_tutorial_favorite_view_"
Expand Down Expand Up @@ -93,37 +93,33 @@ class NCFavorite: NCCollectionViewCommon {

if serverUrl.isEmpty {

NCNetworking.shared.listingFavoritescompletion(selector: NCGlobal.shared.selectorListingFavorite) { _, _, error in
if error != .success {
NCContentPresenter.shared.showError(error: error)
}
NextcloudKit.shared.listingFavorites(showHiddenFiles: CCUtility.getShowHiddenFiles(),
options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { account, files, _, error in

DispatchQueue.main.async {
self.refreshControl.endRefreshing()
self.isReloadDataSourceNetworkInProgress = false
self.isReloadDataSourceNetworkInProgress = false
if error == .success {
NCManageDatabase.shared.convertFilesToMetadatas(files, useMetadataFolder: false) { _, _, metadatas in
NCManageDatabase.shared.updateMetadatasFavorite(account: account, metadatas: metadatas)
self.reloadDataSource()
}
} else {
NCContentPresenter.shared.showError(error: error)
self.reloadDataSource()
}
}

} else {

networkReadFolder(isForced: isForced) { tableDirectory, metadatas, metadatasUpdate, metadatasDelete, error in
if error == .success, let metadatas = metadatas {
networkReadFolder(isForced: isForced) { tableDirectory, metadatas, _, _, error in

self.isReloadDataSourceNetworkInProgress = false
if error == .success, let metadatas {
for metadata in metadatas where (!metadata.directory && NCManageDatabase.shared.isDownloadMetadata(metadata, download: false)) {
NCOperationQueue.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorDownloadFile)
}
}

DispatchQueue.main.async {
self.refreshControl.endRefreshing()
self.isReloadDataSourceNetworkInProgress = false
self.richWorkspaceText = tableDirectory?.richWorkspace
if metadatasUpdate?.count ?? 0 > 0 || metadatasDelete?.count ?? 0 > 0 || isForced {
self.reloadDataSource()
} else {
self.collectionView?.reloadData()
}
}
self.richWorkspaceText = tableDirectory?.richWorkspace
self.reloadDataSource()
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions iOSClient/Groupfolders/NCGroupfolders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,8 @@ class NCGroupfolders: NCCollectionViewCommon {
if serverUrl.isEmpty {

let homeServerUrl = NCUtilityFileSystem.shared.getHomeServer(urlBase: self.appDelegate.urlBase, userId: self.appDelegate.userId)
let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)

NextcloudKit.shared.getGroupfolders(options: options) { account, results, _, error in
NextcloudKit.shared.getGroupfolders(options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { account, results, _, error in

if error == .success, let groupfolders = results {

Expand Down
2 changes: 1 addition & 1 deletion iOSClient/Main/NCActionCenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec
}
} else if metadata.directory {
NCManageDatabase.shared.setDirectory(serverUrl: serverUrl, offline: true, account: appDelegate.account)
NCNetworking.shared.synchronizationServerUrl(serverUrl, account: metadata.account, selector: NCGlobal.shared.selectorDownloadFile)
NCNetworking.shared.synchronizationServerUrl(serverUrl, account: metadata.account, selector: NCGlobal.shared.selectorSynchronizationOffline)
} else {
NCNetworking.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorLoadOffline) { _, _ in }
if let metadataLivePhoto = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata) {
Expand Down
4 changes: 3 additions & 1 deletion iOSClient/NCGlobal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class NCGlobal: NSObject {
// E2EE
//
let e2eePassphraseTest = "more over television factory tendency independence international intellectual impress interest sentence pony"
@objc let e2eeVersions = ["1.1", "1.2", "2.0"]
@objc let e2eeVersions = ["1.1", "1.2"] // ["1.1", "1.2", "2.0"]
let e2eeVersionV11 = "1.1"
let e2eeVersionV12 = "1.2"
let e2eeVersionV20 = "2.0"
Expand Down Expand Up @@ -304,6 +304,8 @@ class NCGlobal: NSObject {
let selectorSaveAlbumLivePhotoMOV = "saveAlbumLivePhotoMOV"
let selectorSaveAsScan = "saveAsScan"
let selectorOpenDetail = "openDetail"
let selectorSynchronizationOffline = "synchronizationOffline"
let selectorSynchronizationFavorite = "synchronizationFavorite"

// Metadata : Status
//
Expand Down
64 changes: 25 additions & 39 deletions iOSClient/Networking/NCNetworking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -839,9 +839,12 @@ class NCNetworking: NSObject, NKCommonDelegate {

func readFolder(serverUrl: String, account: String, completion: @escaping (_ account: String, _ metadataFolder: tableMetadata?, _ metadatas: [tableMetadata]?, _ metadatasUpdate: [tableMetadata]?, _ metadatasLocalUpdate: [tableMetadata]?, _ metadatasDelete: [tableMetadata]?, _ error: NKError) -> Void) {

let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)
NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrl,
depth: "1",
showHiddenFiles: CCUtility.getShowHiddenFiles(),
includeHiddenFiles: NCGlobal.shared.includeHiddenFiles,
options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { account, files, _, error in

NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrl, depth: "1", showHiddenFiles: CCUtility.getShowHiddenFiles(), includeHiddenFiles: NCGlobal.shared.includeHiddenFiles, options: options) { account, files, _, error in
guard error == .success else {
completion(account, nil, nil, nil, nil, nil, error)
return
Expand Down Expand Up @@ -912,9 +915,12 @@ class NCNetworking: NSObject, NKCommonDelegate {
<d:prop></d:prop>
</d:propfind>
"""
let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)

NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrlFileName, depth: "0", requestBody: requestBody.data(using: .utf8), options: options) { account, files, _, error in
NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrlFileName,
depth: "0",
requestBody: requestBody.data(using: .utf8),
options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { account, files, _, error in

if error == .success, let file = files.first {
completion(account, true, file, error)
} else if error.errorCode == NCGlobal.shared.errorResourceNotFound {
Expand All @@ -927,12 +933,15 @@ class NCNetworking: NSObject, NKCommonDelegate {

// MARK: - Synchronization ServerUrl

#if !EXTENSION

func synchronizationServerUrl(_ serverUrl: String, account: String, selector: String) {

let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)
#if !EXTENSION
NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrl,
depth: "infinity",
showHiddenFiles: CCUtility.getShowHiddenFiles(),
options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { account, files, _, error in

NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrl, depth: "infinity", showHiddenFiles: CCUtility.getShowHiddenFiles(), options: options) { account, files, _, error in
if error == .success {
NCManageDatabase.shared.convertFilesToMetadatas(files, useMetadataFolder: true) { metadataFolder, metadatasFolder, metadatas in
NCManageDatabase.shared.addDirectory(encrypted: metadataFolder.e2eEncrypted, favorite: metadataFolder.favorite, ocId: metadataFolder.ocId, fileId: metadataFolder.fileId, etag: metadataFolder.etag, permissions: metadataFolder.permissions, serverUrl: metadataFolder.serverUrl + "/" + metadataFolder.fileName, account: metadataFolder.account)
Expand All @@ -942,24 +951,28 @@ class NCNetworking: NSObject, NKCommonDelegate {
if metadata.directory {
let serverUrl = metadata.serverUrl + "/" + metadata.fileName
NCManageDatabase.shared.addDirectory(encrypted: metadata.e2eEncrypted, favorite: metadata.favorite, ocId: metadata.ocId, fileId: metadata.fileId, etag: metadata.etag, permissions: metadata.permissions, serverUrl: serverUrl, account: metadata.account)
} else if selector == NCGlobal.shared.selectorDownloadFile, NCManageDatabase.shared.isDownloadMetadata(metadata, download: true) {
} else if selector == NCGlobal.shared.selectorSynchronizationOffline, NCManageDatabase.shared.isDownloadMetadata(metadata, download: true) {
NCOperationQueue.shared.download(metadata: metadata, selector: selector)
}
}
}
}
}
}
#endif
}


// MARK: - Search

/// WebDAV search
func searchFiles(urlBase: NCUserBaseUrl, literal: String, completion: @escaping (_ metadatas: [tableMetadata]?, _ error: NKError) -> Void) {

let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)
NextcloudKit.shared.searchLiteral(serverUrl: urlBase.urlBase,
depth: "infinity",
literal: literal,
showHiddenFiles: CCUtility.getShowHiddenFiles(),
options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { account, files, _, error in

NextcloudKit.shared.searchLiteral(serverUrl: urlBase.urlBase, depth: "infinity", literal: literal, showHiddenFiles: CCUtility.getShowHiddenFiles(), options: options) { account, files, _, error in
guard error == .success else {
return completion(nil, error)
}
Expand Down Expand Up @@ -1368,43 +1381,16 @@ class NCNetworking: NSObject, NKCommonDelegate {
NextcloudKit.shared.setFavorite(fileName: fileName, favorite: favorite) { account, error in
if error == .success && metadata.account == account {
NCManageDatabase.shared.setMetadataFavorite(ocId: metadata.ocId, favorite: favorite)
#if !EXTENSION
if favorite, metadata.directory {
let serverUrl = metadata.serverUrl + "/" + metadata.fileName
self.synchronizationServerUrl(serverUrl, account: metadata.account, selector: "")
self.synchronizationServerUrl(serverUrl, account: metadata.account, selector: NCGlobal.shared.selectorSynchronizationFavorite)
}
#endif
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterFavoriteFile, userInfo: ["ocId": ocId, "serverUrl": metadata.serverUrl])
}
completion(error)
}
}

func listingFavoritescompletion(selector: String, completion: @escaping (_ account: String, _ metadatas: [tableMetadata]?, _ error: NKError) -> Void) {

let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)

NextcloudKit.shared.listingFavorites(showHiddenFiles: CCUtility.getShowHiddenFiles(), options: options) { account, files, _, error in
guard error == .success else {
completion(account, nil, error)
return
}

NCManageDatabase.shared.convertFilesToMetadatas(files, useMetadataFolder: false) { _, _, metadatas in
NCManageDatabase.shared.updateMetadatasFavorite(account: account, metadatas: metadatas)
if selector != NCGlobal.shared.selectorListingFavorite {
#if !EXTENSION
for metadata in metadatas where metadata.directory {
let serverUrl = metadata.serverUrl + "/" + metadata.fileName
self.synchronizationServerUrl(serverUrl, account: metadata.account, selector: "")
}
#endif
}
completion(account, metadatas, error)
}
}
}

// MARK: - Lock Files

func lockUnlockFile(_ metadata: tableMetadata, shoulLock: Bool) {
Expand Down
Loading

0 comments on commit 01b74e5

Please sign in to comment.