Browse Source

coding

Signed-off-by: marinofaggiana <ios@nextcloud.com>
marinofaggiana 2 years ago
parent
commit
733b7cda5a

+ 4 - 1
iOSClient/Data/NCDataSource.swift

@@ -22,6 +22,7 @@
 //
 
 import UIKit
+import NCCommunication
 
 class NCDataSource: NSObject {
 
@@ -29,6 +30,7 @@ class NCDataSource: NSObject {
     public var metadatasForSection: [NCMetadatasForSection] = []
 
     private var sectionsValue: [String] = []
+    private var providers: [NCCSearchProvider]?
 
     private var ascending: Bool = true
     private var sort: String = ""
@@ -41,7 +43,7 @@ class NCDataSource: NSObject {
         super.init()
     }
 
-    init(metadatasSource: [tableMetadata], sort: String? = "none", ascending: Bool? = false, directoryOnTop: Bool? = true, favoriteOnTop: Bool? = true, filterLivePhoto: Bool? = true, groupByField: String = "name") {
+    init(metadatasSource: [tableMetadata], sort: String? = "none", ascending: Bool? = false, directoryOnTop: Bool? = true, favoriteOnTop: Bool? = true, filterLivePhoto: Bool? = true, groupByField: String = "name", providers: [NCCSearchProvider]? = nil) {
         super.init()
 
         self.metadatasSource = metadatasSource
@@ -51,6 +53,7 @@ class NCDataSource: NSObject {
         self.favoriteOnTop = favoriteOnTop ?? true
         self.filterLivePhoto = filterLivePhoto ?? true
         self.groupByField = groupByField
+        self.providers = providers
 
         createSections()
 

+ 2 - 1
iOSClient/Data/NCManageDatabase.swift

@@ -149,9 +149,10 @@ class NCManageDatabase: NSObject {
                         }
                     }
 
-                    if oldSchemaVersion < 226 {
+                    if oldSchemaVersion < 227 {
                         migration.deleteData(forType: tableMetadata.className())
                         migration.deleteData(forType: tableDirectory.className())
+                        migration.deleteData(forType: tableTrash.className())
                     }
 
                 }, shouldCompactOnLaunch: { totalBytes, usedBytes in

+ 9 - 3
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -1015,6 +1015,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
                 self.reloadDataSource()
             }
         }
+        var providers: [NCCSearchProvider]?
 
         isReloadDataSourceNetworkInProgress = true
         self.metadatasSource.removeAll()
@@ -1024,7 +1025,9 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         let serverVersionMajor = NCManageDatabase.shared.getCapabilitiesServerInt(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
         if serverVersionMajor >= NCGlobal.shared.nextcloudVersion20 {
             self.refreshControl.beginRefreshing()
-            NCNetworking.shared.unifiedSearchFiles(urlBase: appDelegate, literal: literalSearch, update: { metadatas in
+            NCNetworking.shared.unifiedSearchFiles(urlBase: appDelegate, literal: literalSearch) { allProviders in
+                providers = allProviders
+            } update: { metadatas in
                 guard let metadatas = metadatas, metadatas.count > 0 else { return }
                 DispatchQueue.main.async {
                     if self.searchController?.isActive == true {
@@ -1035,11 +1038,14 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
                             ascending: self.layoutForView?.ascending,
                             directoryOnTop: self.layoutForView?.directoryOnTop,
                             favoriteOnTop: true,
-                            filterLivePhoto: true)
+                            filterLivePhoto: true,
+                            providers: providers)
                         self.collectionView.reloadData()
                     }
                 }
-            }, completion: completionHandler)
+            } completion: { metadatas, errorCode, errorDescription in
+                completionHandler(metadatas, errorCode, errorDescription)
+            }
         } else {
             NCNetworking.shared.searchFiles(urlBase: appDelegate, literal: literalSearch, completion: completionHandler)
         }

+ 1 - 1
iOSClient/NCGlobal.swift

@@ -115,7 +115,7 @@ class NCGlobal: NSObject {
     // Database Realm
     //
     let databaseDefault                             = "nextcloud.realm"
-    let databaseSchemaVersion: UInt64               = 226
+    let databaseSchemaVersion: UInt64               = 227
 
     // Intro selector
     //

+ 3 - 1
iOSClient/Networking/NCNetworking.swift

@@ -931,7 +931,7 @@ import Queuer
 
     /// Unified Search (NC>=20)
     ///
-    func unifiedSearchFiles(urlBase: NCUserBaseUrl, literal: String, update: @escaping ([tableMetadata]?) -> Void, completion: @escaping (_ metadatas: [tableMetadata]?, _ errorCode: Int, _ errorDescription: String) -> ()) {
+    func unifiedSearchFiles(urlBase: NCUserBaseUrl, literal: String, providers: @escaping ([NCCSearchProvider]?) -> Void, update: @escaping ([tableMetadata]?) -> Void, completion: @escaping (_ metadatas: [tableMetadata]?, _ errorCode: Int, _ errorDescription: String) -> ()) {
 
         var searchFiles: [tableMetadata] = []
         var errCode = 0
@@ -951,6 +951,8 @@ import Queuer
             if let request = request {
                 self.requestsUnifiedSearch.append(request)
             }
+        } providers: { allProviders in
+            providers(allProviders)
         } update: { partialResult, provider, errorCode, errorDescription in
             guard let partialResult = partialResult else { return }