marinofaggiana 4 years ago
parent
commit
2ad0487c74

+ 1 - 1
iOSClient/AppDelegate.h

@@ -142,7 +142,7 @@
 
 // Push Notification
 - (void)pushNotification;
-- (void)unsubscribingNextcloudServerPushNotification:(NSString *)account url:(NSString *)url withSubscribing:(BOOL)subscribing;
+//- (void)unsubscribingNextcloudServerPushNotification:(NSString *)account url:(NSString *)url withSubscribing:(BOOL)subscribing;
 
 // Theming Color
 - (void)settingThemingColorBrand;

+ 35 - 37
iOSClient/AppDelegate.m

@@ -440,7 +440,10 @@
 
 - (void)deleteAccount:(NSString *)account wipe:(BOOL)wipe
 {
-    [self unsubscribingNextcloudServerPushNotification:account url:self.activeUrl withSubscribing:false];
+    // Push Notification
+    tableAccount *accountPN = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
+    [self unsubscribingNextcloudServerPushNotification:accountPN.account url:accountPN.url user:accountPN.user withSubscribing:false];
+
     [self settingActiveAccount:nil activeUrl:nil activeUser:nil activeUserID:nil activePassword:nil];
     
     /* DELETE ALL FILES LOCAL FS */
@@ -500,15 +503,15 @@
         if (![token isEqualToString:self.pushKitToken]) {
             if (token != nil) {
                 // unsubscribing + subscribing
-                [self unsubscribingNextcloudServerPushNotification:result.account url:result.url withSubscribing:true];
+                [self unsubscribingNextcloudServerPushNotification:result.account url:result.url user:result.user withSubscribing:true];
             } else {
-                [self subscribingNextcloudServerPushNotification:result.account url:result.url];
+                [self subscribingNextcloudServerPushNotification:result.account url:result.url user:result.user];
             }
         }
     }
 }
 
-- (void)subscribingNextcloudServerPushNotification:(NSString *)account url:(NSString *)url
+- (void)subscribingNextcloudServerPushNotification:(NSString *)account url:(NSString *)url user:(NSString *)user
 {
     // test
     if (self.activeAccount.length == 0 || self.maintenanceMode || self.pushKitToken.length == 0)
@@ -520,18 +523,15 @@
     NSData *pushPublicKey = [CCUtility getPushNotificationPublicKey:account];
     NSString *pushDevicePublicKey = [[NSString alloc] initWithData:pushPublicKey encoding:NSUTF8StringEncoding];
     NSString *proxyServerPath = [NCBrandOptions sharedInstance].pushNotificationServerProxy;
-
-    [[NCCommunication shared] subscribingPushNotificationWithPushTokenHash:pushTokenHash devicePublicKey:pushDevicePublicKey proxyServerUrl:proxyServerPath customUserAgent:nil addCustomHeaders:nil completionHandler:^(NSString *account, NSString *deviceIdentifier, NSString *signature, NSString *publicKey, NSInteger errorCode, NSString *errorDescription) {
-
-        if (errorCode == 0 && [account isEqualToString:account]) {
-            
-            NSString *customUserAgent = [NSString stringWithFormat:@"%@  (Strict VoIP)", [CCUtility getUserAgent]];
-            
-            [[NCCommunication shared] subscribingPushProxyWithProxyServerUrl:proxyServerPath pushToken:self.pushKitToken deviceIdentifier:deviceIdentifier signature:signature publicKey:publicKey customUserAgent:customUserAgent addCustomHeaders:nil completionHandler:^(NSString *account, NSInteger errorCode, NSString *errorDescription) {
-               
-                if (errorCode == 0 && [account isEqualToString:account]) {
+    
+    [[NCCommunication shared] subscribingPushNotificationWithServerUrl:url account:account user:user password:[CCUtility getPassword:account] pushTokenHash:pushTokenHash devicePublicKey:pushDevicePublicKey proxyServerUrl:proxyServerPath customUserAgent:nil addCustomHeaders:nil completionHandler:^(NSString *account, NSString *deviceIdentifier, NSString *signature, NSString *publicKey, NSInteger errorCode, NSString *errorDescription) {
+        if (errorCode == 0) {
+            NSString *userAgent = [NSString stringWithFormat:@"%@  (Strict VoIP)", [CCUtility getUserAgent]];
+            [[NCCommunication shared] subscribingPushProxyWithProxyServerUrl:proxyServerPath pushToken:self.pushKitToken deviceIdentifier:deviceIdentifier signature:signature publicKey:publicKey userAgent:userAgent completionHandler:^(NSInteger errorCode, NSString *errorDescription) {
+                if (errorCode == 0) {
+                    
                     NSLog(@"[LOG] Subscribed to Push Notification server & proxy successfully.");
-                
+                        
                     [CCUtility setPushNotificationToken:account token:self.pushKitToken];
                     [CCUtility setPushNotificationDeviceIdentifier:account deviceIdentifier:deviceIdentifier];
                     [CCUtility setPushNotificationDeviceIdentifierSignature:account deviceIdentifierSignature:signature];
@@ -542,37 +542,35 @@
     }];
 }
 
-- (void)unsubscribingNextcloudServerPushNotification:(NSString *)account url:(NSString *)url withSubscribing:(BOOL)subscribing
+- (void)unsubscribingNextcloudServerPushNotification:(NSString *)account url:(NSString *)url user:(NSString *)user withSubscribing:(BOOL)subscribing
 {
     // test
     if (self.activeAccount.length == 0 || self.maintenanceMode)
         return;
     
     NSString *deviceIdentifier = [CCUtility getPushNotificationDeviceIdentifier:account];
-    NSString *deviceIdentifierSignature = [CCUtility getPushNotificationDeviceIdentifierSignature:account];
+    NSString *signature = [CCUtility getPushNotificationDeviceIdentifierSignature:account];
     NSString *publicKey = [CCUtility getPushNotificationSubscribingPublicKey:account];
 
-    [[OCNetworking sharedManager] unsubscribingPushNotificationWithAccount:account url:url deviceIdentifier:deviceIdentifier deviceIdentifierSignature:deviceIdentifierSignature publicKey:publicKey completion:^(NSString *account, NSString *message, NSInteger errorCode) {
-       
+    [[NCCommunication shared] unsubscribingPushNotificationWithServerUrl:url account:account user:user password:[CCUtility getPassword:account] customUserAgent:nil addCustomHeaders:nil completionHandler:^(NSString *account, NSInteger errorCode, NSString *errorDescription) {
         if (errorCode == 0) {
-            
-            NSLog(@"[LOG] Unsubscribed to Push Notification server & proxy successfully.");
-            
-            [CCUtility setPushNotificationPublicKey:account data:nil];
-            [CCUtility setPushNotificationSubscribingPublicKey:account publicKey:nil];
-            [CCUtility setPushNotificationPrivateKey:account data:nil];
-            [CCUtility setPushNotificationToken:account token:nil];
-            [CCUtility setPushNotificationDeviceIdentifier:account deviceIdentifier:nil];
-            [CCUtility setPushNotificationDeviceIdentifierSignature:account deviceIdentifierSignature:nil];
-            
-            if (self.pushKitToken != nil && subscribing) {
-                [self subscribingNextcloudServerPushNotification:account url:url];
-            }
-            
-        } else if (errorCode != 0) {
-            NSLog(@"[LOG] Unsubscribed to Push Notification server & proxy error.");
-        } else {
-            NSLog(@"[LOG] It has been changed user during networking process, error.");
+            [[NCCommunication shared] unsubscribingPushProxyWithProxyServerUrl:url deviceIdentifier:deviceIdentifier signature:signature publicKey:publicKey completionHandler:^(NSInteger errorCode, NSString *errorDescription) {
+                if (errorCode == 0) {
+                
+                    NSLog(@"[LOG] Unsubscribed to Push Notification server & proxy successfully.");
+                    
+                    [CCUtility setPushNotificationPublicKey:account data:nil];
+                    [CCUtility setPushNotificationSubscribingPublicKey:account publicKey:nil];
+                    [CCUtility setPushNotificationPrivateKey:account data:nil];
+                    [CCUtility setPushNotificationToken:account token:nil];
+                    [CCUtility setPushNotificationDeviceIdentifier:account deviceIdentifier:nil];
+                    [CCUtility setPushNotificationDeviceIdentifierSignature:account deviceIdentifierSignature:nil];
+                    
+                    if (self.pushKitToken != nil && subscribing) {
+                        [self subscribingNextcloudServerPushNotification:account url:url user:user];
+                    }
+                }
+            }];
         }
     }];
 }

+ 0 - 7
iOSClient/Networking/OCNetworking.h

@@ -45,13 +45,6 @@
 - (void)unshareAccount:(NSString *)account shareID:(NSInteger)shareID completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion;
 - (void)getUserGroupWithAccount:(NSString *)account searchString:(NSString *)searchString completion:(void (^)(NSString *account, NSArray *item, NSString *message, NSInteger errorCode))completion;
 
-#pragma mark ===== Push Notification =====
-
-- (void)subscribingPushNotificationWithAccount:(NSString *)account url:(NSString *)url pushToken:(NSString *)pushToken Hash:(NSString *)pushTokenHash devicePublicKey:(NSString *)devicePublicKey completion:(void(^)(NSString *account, NSString *deviceIdentifier, NSString *deviceIdentifierSignature, NSString *publicKey, NSString *message, NSInteger errorCode))completion;
-- (void)unsubscribingPushNotificationWithAccount:(NSString *)account url:(NSString *)url deviceIdentifier:(NSString *)deviceIdentifier deviceIdentifierSignature:(NSString *)deviceIdentifierSignature publicKey:(NSString *)publicKey completion:(void (^)(NSString *account ,NSString *message, NSInteger errorCode))completion;
-- (void)getServerNotification:(NSString *)serverUrl notificationId:(NSInteger)notificationId completion:(void(^)(NSDictionary*jsongParsed, NSString *message, NSInteger errorCode))completion;
-- (void)deletingServerNotification:(NSString *)serverUrl notificationId:(NSInteger)notificationId completion:(void(^)(NSString *message, NSInteger errorCode))completion;
-
 #pragma mark ===== Third Parts =====
 
 - (void)getHCUserProfileWithAccount:(NSString *)account serverUrl:(NSString *)serverUrl completion:(void (^)(NSString *account, OCUserProfile *userProfile, NSString *message, NSInteger errorCode))completion;

+ 0 - 226
iOSClient/Networking/OCNetworking.m

@@ -380,232 +380,6 @@
     }];
 }
 
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Push Notification =====
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)subscribingPushNotificationWithAccount:(NSString *)account url:(NSString *)url pushToken:(NSString *)pushToken Hash:(NSString *)pushTokenHash devicePublicKey:(NSString *)devicePublicKey completion:(void(^)(NSString *account, NSString *deviceIdentifier, NSString *deviceIdentifierSignature, NSString *publicKey, NSString *message, NSInteger errorCode))completion
-{
-    tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
-    if (tableAccount == nil) {
-        completion(account, nil, nil, nil, NSLocalizedString(@"_error_user_not_available_", nil), k_CCErrorUserNotAvailble);
-    } else if ([CCUtility getPassword:account].length == 0) {
-        completion(account, nil, nil, nil, NSLocalizedString(@"_bad_username_password_", nil), kOCErrorServerUnauthorized);
-    } else if ([CCUtility getCertificateError:account]) {
-        completion(account, nil, nil, nil, NSLocalizedString(@"_ssl_certificate_untrusted_", nil), NSURLErrorServerCertificateUntrusted);
-    }
-    
-    devicePublicKey = [CCUtility URLEncodeStringFromString:devicePublicKey];
-    NSString *proxyServerPath = [NCBrandOptions sharedInstance].pushNotificationServerProxy;
-    NSString *proxyServer = [NCBrandOptions sharedInstance].pushNotificationServerProxy;
-    
-#ifdef DEBUG
-//    proxyServerPath = @"http://127.0.0.1:8088";
-//    proxyServer = @"https://10.132.0.37:8443/pushnotifications";
-#endif
-    
-    OCCommunication *communication = [OCNetworking sharedManager].sharedOCCommunication;
-    
-    [communication setCredentialsWithUser:tableAccount.user andUserID:tableAccount.userID andPassword:[CCUtility getPassword:account]];
-    [communication setUserAgent:[CCUtility getUserAgent]];
-    [communication subscribingNextcloudServerPush:url pushTokenHash:pushTokenHash devicePublicKey:devicePublicKey proxyServerPath: proxyServerPath onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *publicKey, NSString *deviceIdentifier, NSString *signature, NSString *redirectedServer) {
-        
-        deviceIdentifier = [CCUtility URLEncodeStringFromString:deviceIdentifier];
-        signature = [CCUtility URLEncodeStringFromString:signature];
-        publicKey = [CCUtility URLEncodeStringFromString:publicKey];
-        
-        [communication subscribingPushProxy:proxyServer pushToken:pushToken deviceIdentifier:deviceIdentifier deviceIdentifierSignature:signature publicKey:publicKey onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
-            
-            completion(account, deviceIdentifier, signature, publicKey, nil, 0);
-            
-        } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
-           
-            NSString *message;
-            NSInteger errorCode = response.statusCode;
-            
-            if (errorCode == 0 || (errorCode >= 200 && errorCode < 300))
-                errorCode = error.code;
-        
-            // Error
-            if (errorCode == 503)
-                message = NSLocalizedString(@"_server_error_retry_", nil);
-            else
-                message = [error.userInfo valueForKey:@"NSLocalizedDescription"];
-                        
-            completion(account, nil, nil, nil, message, errorCode);
-        }];
-        
-    } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
-        
-        NSString *message;
-        NSInteger errorCode = response.statusCode;
-        
-        if (errorCode == 0 || (errorCode >= 200 && errorCode < 300))
-            errorCode = error.code;
-    
-        // Error
-        if (errorCode == 503)
-            message = NSLocalizedString(@"_server_error_retry_", nil);
-        else
-            message = [error.userInfo valueForKey:@"NSLocalizedDescription"];
-
-        completion(account, nil, nil, nil, message, errorCode);
-    }];
-}
-
-- (void)unsubscribingPushNotificationWithAccount:(NSString *)account url:(NSString *)url deviceIdentifier:(NSString *)deviceIdentifier deviceIdentifierSignature:(NSString *)deviceIdentifierSignature publicKey:(NSString *)publicKey completion:(void (^)(NSString *account ,NSString *message, NSInteger errorCode))completion {
-    
-    tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
-    if (tableAccount == nil) {
-        completion(account, NSLocalizedString(@"_error_user_not_available_", nil), k_CCErrorUserNotAvailble);
-    } else if ([CCUtility getPassword:account].length == 0) {
-        completion(account, NSLocalizedString(@"_bad_username_password_", nil), kOCErrorServerUnauthorized);
-    } else if ([CCUtility getCertificateError:account]) {
-        completion(account, NSLocalizedString(@"_ssl_certificate_untrusted_", nil), NSURLErrorServerCertificateUntrusted);
-    }
-    
-    NSString *proxyServer = [NCBrandOptions sharedInstance].pushNotificationServerProxy;
-    
-#ifdef DEBUG
-//    proxyServer = @"https://10.132.0.37:8443/pushnotifications";
-#endif
-    
-    OCCommunication *communication = [OCNetworking sharedManager].sharedOCCommunication;
-
-    [communication setCredentialsWithUser:tableAccount.user andUserID:tableAccount.userID andPassword:[CCUtility getPassword:account]];
-    [communication setUserAgent:[CCUtility getUserAgent]];
-    [communication unsubscribingNextcloudServerPush:url onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
-
-        [communication unsubscribingPushProxy:proxyServer deviceIdentifier:deviceIdentifier deviceIdentifierSignature:deviceIdentifierSignature publicKey:publicKey onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
-            
-            completion(account, nil, 0);
-            
-        } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)  {
-            
-            NSString *message;
-            NSInteger errorCode = response.statusCode;
-            
-            if (errorCode == 0 || (errorCode >= 200 && errorCode < 300))
-                errorCode = error.code;
-            
-            // Error
-            if (errorCode == 503)
-                message = NSLocalizedString(@"_server_error_retry_", nil);
-            else
-                message = [error.userInfo valueForKey:@"NSLocalizedDescription"];
-            
-            completion(account, message, errorCode);
-        }];
-        
-    } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
-
-        NSString *message;
-        NSInteger errorCode = response.statusCode;
-        
-        if (errorCode == 0 || (errorCode >= 200 && errorCode < 300))
-            errorCode = error.code;
-        
-        // Error
-        if (errorCode == 503)
-            message = NSLocalizedString(@"_server_error_retry_", nil);
-        else
-            message = [error.userInfo valueForKey:@"NSLocalizedDescription"];
-        
-        completion(account, message, errorCode);
-    }];
-}
-
-- (void)getServerNotification:(NSString *)serverUrl notificationId:(NSInteger)notificationId completion:(void(^)(NSDictionary*jsongParsed, NSString *message, NSInteger errorCode))completion
-{
-    NSString *URLString = [NSString stringWithFormat:@"%@/ocs/v2.php/apps/notifications/api/v2/notifications/%ld?format=json", serverUrl, (long)notificationId];
-
-    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:URLString] cachePolicy:0 timeoutInterval:20.0];
-    [request addValue:[CCUtility getUserAgent] forHTTPHeaderField:@"User-Agent"];
-    [request addValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
-
-    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
-    NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
-
-    NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) {
-
-        if (error) {
-            
-            NSString *message;
-            NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
-            NSInteger errorCode = httpResponse.statusCode;
-            
-            if (errorCode == 0 || (errorCode >= 200 && errorCode < 300))
-                errorCode = error.code;
-            
-            // Error
-            if (errorCode == 503)
-                message = NSLocalizedString(@"_server_error_retry_", nil);
-            else
-                message = [error.userInfo valueForKey:@"NSLocalizedDescription"];
-            
-            completion(nil, message, errorCode);
-            
-        } else {
-            
-            NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
-
-            completion(jsongParsed, nil, 0);
-        }
-    }];
-    
-    [task resume];
-}
-
-- (void)deletingServerNotification:(NSString *)serverUrl notificationId:(NSInteger)notificationId completion:(void(^)(NSString *message, NSInteger errorCode))completion
-{
-//    NSData *authData = [[NSString stringWithFormat:@"%@:%@", tableAccount.user, [CCUtility getPassword:tableAccount.account]] dataUsingEncoding:NSUTF8StringEncoding];
-//    NSString *authValue = [NSString stringWithFormat: @"Basic %@",[authData base64EncodedStringWithOptions:0]];
-
-    // Delete
-    NSString *URLString = [NSString stringWithFormat:@"%@/ocs/v2.php/apps/notifications/api/v2/notifications/%ld", serverUrl, (long)notificationId];
-    
-    // Delete-all
-    if (notificationId == 0) {
-        URLString = [NSString stringWithFormat:@"%@/ocs/v2.php/apps/notifications/api/v2/notifications", serverUrl];
-    }
-    
-    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:URLString] cachePolicy:0 timeoutInterval:20.0];
-//    [request setValue:authValue forHTTPHeaderField:@"Authorization"];
-    [request addValue:[CCUtility getUserAgent] forHTTPHeaderField:@"User-Agent"];
-    [request addValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
-    [request setHTTPMethod: @"DELETE"];
-
-    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
-    NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
-    
-    NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) {
-        
-        if (error) {
-            
-            NSString *message;
-            NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
-            NSInteger errorCode = httpResponse.statusCode;
-            
-            if (errorCode == 0 || (errorCode >= 200 && errorCode < 300))
-                errorCode = error.code;
-            
-            // Error
-            if (errorCode == 503)
-                message = NSLocalizedString(@"_server_error_retry_", nil);
-            else
-                message = [error.userInfo valueForKey:@"NSLocalizedDescription"];
-            
-            completion(message, errorCode);
-            
-        } else {
-            
-            completion(nil, 0);
-        }
-    }];
-    
-    [task resume];
-}
-
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Third Parts =====
 #pragma --------------------------------------------------------------------------------------------