Marino Faggiana hace 7 años
padre
commit
f36696ad23
Se han modificado 2 ficheros con 28 adiciones y 42 borrados
  1. 20 18
      iOSClient/Database/NCManageDatabase.swift
  2. 8 24
      iOSClient/Networking/NCNetworkingSync.m

+ 20 - 18
iOSClient/Database/NCManageDatabase.swift

@@ -955,7 +955,7 @@ class NCManageDatabase: NSObject {
         }
         
         DispatchQueue.main.async {
-
+    
             let realm = try! Realm()
             realm.refresh()
         
@@ -1076,27 +1076,29 @@ class NCManageDatabase: NSObject {
             return
         }
         
-        let realm = try! Realm()
-        realm.refresh()
+        DispatchQueue.main.async {
+            
+            let realm = try! Realm()
+            realm.refresh()
         
-        realm.beginWrite()
+            realm.beginWrite()
         
-        guard let result = realm.objects(tableDirectory.self).filter("account = %@ AND serverUrl = %@", tableAccount.account, serverUrl).first else {
-            realm.cancelWrite()
-            return
-        }
+            guard let result = realm.objects(tableDirectory.self).filter("account = %@ AND serverUrl = %@", tableAccount.account, serverUrl).first else {
+                realm.cancelWrite()
+                return
+            }
         
-        if (token == nil) {
-            result.e2eTokenLock = ""
-        } else {
-            result.e2eTokenLock = token!
-        }
+            if (token == nil) {
+                result.e2eTokenLock = ""
+            } else {
+                result.e2eTokenLock = token!
+            }
     
-        do {
-            try realm.commitWrite()
-        } catch let error {
-            print("[LOG] Could not write to database: ", error)
-            return
+            do {
+                try realm.commitWrite()
+            } catch let error {
+                print("[LOG] Could not write to database: ", error)
+            }
         }
     }
     

+ 8 - 24
iOSClient/Networking/NCNetworkingSync.m

@@ -243,9 +243,7 @@
             // LOCK
             [communication lockEndToEndFolderEncrypted:[url stringByAppendingString:@"/"] fileID:fileID token:tokenDatabase onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *token, NSString *redirectedServer) {
         
-                dispatch_async(dispatch_get_main_queue(), ^{
-                    [[NCManageDatabase sharedInstance] setDirectoryE2ETokenLockWithServerUrl:serverUrl token:token];
-                });
+                [[NCManageDatabase sharedInstance] setDirectoryE2ETokenLockWithServerUrl:serverUrl token:token];
             
                 // REMOVE METADATA
                 [communication deleteEndToEndMetadata:[url stringByAppendingString:@"/"] fileID:fileID onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
@@ -260,9 +258,7 @@
                     // UNLOCK
                     [communication unlockEndToEndFolderEncrypted:[url stringByAppendingString:@"/"] fileID:fileID token:token onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
                 
-                        dispatch_async(dispatch_get_main_queue(), ^{
-                            [[NCManageDatabase sharedInstance] setDirectoryE2ETokenLockWithServerUrl:serverUrl token:@""];
-                        });
+                        [[NCManageDatabase sharedInstance] setDirectoryE2ETokenLockWithServerUrl:serverUrl token:@""];
                         dispatch_semaphore_signal(semaphore);
                 
                     } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
@@ -322,9 +318,7 @@
             // LOCK
             [communication lockEndToEndFolderEncrypted:[url stringByAppendingString:@"/"] fileID:fileID token:tokenDatabase onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *token, NSString *redirectedServer) {
         
-                dispatch_async(dispatch_get_main_queue(), ^{
-                    [[NCManageDatabase sharedInstance] setDirectoryE2ETokenLockWithServerUrl:serverUrl token:token];
-                });
+                [[NCManageDatabase sharedInstance] setDirectoryE2ETokenLockWithServerUrl:serverUrl token:token];
             
                 // DELETE METADATA
                 [communication deleteEndToEndMetadata:[url stringByAppendingString:@"/"] fileID:fileID onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
@@ -339,9 +333,7 @@
                     // UNLOCK
                     [communication unlockEndToEndFolderEncrypted:[url stringByAppendingString:@"/"] fileID:fileID token:token onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
                 
-                        dispatch_async(dispatch_get_main_queue(), ^{
-                            [[NCManageDatabase sharedInstance] setDirectoryE2ETokenLockWithServerUrl:serverUrl token:@""];
-                        });
+                        [[NCManageDatabase sharedInstance] setDirectoryE2ETokenLockWithServerUrl:serverUrl token:@""];
                         dispatch_semaphore_signal(semaphore);
                 
                     } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
@@ -448,9 +440,7 @@
         // LOCK
         [communication lockEndToEndFolderEncrypted:[url stringByAppendingString:@"/"] fileID:fileID token:tokenDatabase onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *token, NSString *redirectedServer) {
         
-            dispatch_async(dispatch_get_main_queue(), ^{
-                [[NCManageDatabase sharedInstance] setDirectoryE2ETokenLockWithServerUrl:serverUrl token:token];
-            });
+            [[NCManageDatabase sharedInstance] setDirectoryE2ETokenLockWithServerUrl:serverUrl token:token];
         
             // STORE METADATA
             [communication storeEndToEndMetadata:[url stringByAppendingString:@"/"] fileID:fileID encryptedMetadata:metadata onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *encryptedMetadata, NSString *redirectedServer) {
@@ -492,9 +482,7 @@
         // LOCK
         [communication lockEndToEndFolderEncrypted:[url stringByAppendingString:@"/"] fileID:fileID token:tokenDatabase onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *token, NSString *redirectedServer) {
         
-            dispatch_async(dispatch_get_main_queue(), ^{
-                [[NCManageDatabase sharedInstance] setDirectoryE2ETokenLockWithServerUrl:serverUrl token:token];
-            });
+            [[NCManageDatabase sharedInstance] setDirectoryE2ETokenLockWithServerUrl:serverUrl token:token];
         
             // UPDATA METADATA
             [communication updateEndToEndMetadata:[url stringByAppendingString:@"/"] fileID:fileID encryptedMetadata:metadata token:token onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *encryptedMetadata, NSString *redirectedServer) {
@@ -537,9 +525,7 @@
         [communication lockEndToEndFolderEncrypted:[url stringByAppendingString:@"/"] fileID:fileID token:tokenDatabase onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *token, NSString *redirectedServer) {
         
             // Write DB token
-            dispatch_async(dispatch_get_main_queue(), ^{
-                [[NCManageDatabase sharedInstance] setDirectoryE2ETokenLockWithServerUrl:serverUrl token:token];
-            });
+            [[NCManageDatabase sharedInstance] setDirectoryE2ETokenLockWithServerUrl:serverUrl token:token];
             dispatch_semaphore_signal(semaphore);
         
         } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
@@ -570,9 +556,7 @@
     [communication unlockEndToEndFolderEncrypted:[url stringByAppendingString:@"/"] fileID:fileID token:token onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
         
         // Write DB token ""
-        dispatch_async(dispatch_get_main_queue(), ^{
-            [[NCManageDatabase sharedInstance] setDirectoryE2ETokenLockWithServerUrl:serverUrl token:@""];
-        });
+        [[NCManageDatabase sharedInstance] setDirectoryE2ETokenLockWithServerUrl:serverUrl token:@""];
         dispatch_semaphore_signal(semaphore);
         
     } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {