Marino Faggiana 6 years ago
parent
commit
475eb0cfd9
2 changed files with 27 additions and 2 deletions
  1. 25 0
      iOSClient/Database/NCManageDatabase.swift
  2. 2 2
      iOSClient/Photos/CCPhotos.m

+ 25 - 0
iOSClient/Database/NCManageDatabase.swift

@@ -1616,6 +1616,9 @@ class NCManageDatabase: NSObject {
         for directoryID in directoriesID {
             self.setDateReadDirectory(directoryID: directoryID)
         }
+        
+        // delete Photos archive
+        self.deletePhotos(predicate: predicate)
     }
     
     @objc func moveMetadata(fileName: String, directoryID: String, directoryIDTo: String) {
@@ -1996,6 +1999,28 @@ class NCManageDatabase: NSObject {
         }
     }
     
+    @objc func deletePhotos(predicate: NSPredicate) {
+        
+        guard self.getAccountActive() != nil else {
+            return
+        }
+        
+        let realm = try! Realm()
+        
+        realm.beginWrite()
+        
+        let results = realm.objects(tablePhotos.self).filter(predicate)
+        
+        realm.delete(results)
+        
+        do {
+            try realm.commitWrite()
+        } catch let error {
+            print("[LOG] Could not write to database: ", error)
+            return
+        }
+    }
+    
     //MARK: -
     //MARK: Table Photo Library
     

+ 2 - 2
iOSClient/Photos/CCPhotos.m

@@ -669,8 +669,8 @@
     
         dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 
-            NSArray *metadatasDBImageVideo = [[NCManageDatabase sharedInstance] getTablePhotos];
-            CCSectionDataSourceMetadata *tempSectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:metadatasDBImageVideo listProgressMetadata:nil groupByField:@"date" activeAccount:appDelegate.activeAccount];
+            NSArray *metadatas = [[NCManageDatabase sharedInstance] getTablePhotos];
+            CCSectionDataSourceMetadata *tempSectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:metadatas listProgressMetadata:nil groupByField:@"date" activeAccount:appDelegate.activeAccount];
         
             dispatch_async(dispatch_get_main_queue(), ^{
                 // OPTIMIZED