Marino Faggiana 6 years ago
parent
commit
0cb97b00e8

+ 2 - 2
iOSClient/AppDelegate.h

@@ -160,8 +160,8 @@
 - (NSString *)getTabBarControllerActiveServerUrl;
 
 // Push Notification
-- (void)subscribingNextcloudServerPushNotification:(NSString *)user userID:(NSString *)userID password:(NSString *)password url:(NSString *)url;
-- (void)unsubscribingNextcloudServerPushNotification:(NSString *)user userID:(NSString *)userID password:(NSString *)password url:(NSString *)url;
+- (void)subscribingNextcloudServerPushNotification;
+- (void)unsubscribingNextcloudServerPushNotification;
 
 // Theming Color
 - (void)settingThemingColorBrand;

+ 15 - 7
iOSClient/AppDelegate.m

@@ -400,9 +400,13 @@
 #pragma mark ===== Push Notification =====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)subscribingNextcloudServerPushNotification:(NSString *)user userID:(NSString *)userID password:(NSString *)password url:(NSString *)url
+- (void)subscribingNextcloudServerPushNotification
 {
-    OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:user withUserID:userID withPassword:password withUrl:url];
+    // test
+    if (self.activeAccount.length == 0 || self.maintenanceMode)
+        return;
+    
+    OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:self.activeUser withUserID:self.activeUserID withPassword:self.activePassword withUrl:self.activeUrl];
     
     [[NCPushNotificationEncryption sharedInstance] generatePushNotificationsKeyPair];
 
@@ -414,7 +418,7 @@
     self.pnDeviceIdentifierSignature = nil;
     self.pnPublicKey = nil;
     
-    [ocNetworking subscribingPushNotificationServer:url pushToken:pushToken Hash:pushTokenHash devicePublicKey:devicePublicKey success:^(NSString *deviceIdentifier, NSString *deviceIdentifierSignature, NSString *publicKey) {
+    [ocNetworking subscribingPushNotificationServer:self.activeUrl pushToken:pushToken Hash:pushTokenHash devicePublicKey:devicePublicKey success:^(NSString *deviceIdentifier, NSString *deviceIdentifierSignature, NSString *publicKey) {
         NSLog(@"[LOG] Subscribed to Push Notification server & proxy successfully.");
         self.pnDeviceIdentifier = deviceIdentifier;
         self.pnDeviceIdentifierSignature = deviceIdentifierSignature;
@@ -424,11 +428,15 @@
     }];
 }
 
-- (void)unsubscribingNextcloudServerPushNotification:(NSString *)user userID:(NSString *)userID password:(NSString *)password url:(NSString *)url
+- (void)unsubscribingNextcloudServerPushNotification
 {
-    OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:user withUserID:userID withPassword:password withUrl:url];
+    // test
+    if (self.activeAccount.length == 0 || self.maintenanceMode)
+        return;
+    
+    OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:self.activeUser withUserID:self.activeUserID withPassword:self.activePassword withUrl:self.activeUrl];
 
-    [ocNetworking unsubscribingPushNotificationServer:url deviceIdentifier:self.pnDeviceIdentifier deviceIdentifierSignature:self.pnDeviceIdentifierSignature publicKey:self.pnPublicKey success:^{
+    [ocNetworking unsubscribingPushNotificationServer:self.activeUrl deviceIdentifier:self.pnDeviceIdentifier deviceIdentifierSignature:self.pnDeviceIdentifierSignature publicKey:self.pnPublicKey success:^{
         NSLog(@"[LOG] Unsubscribed to Push Notification server & proxy successfully.");
     } failure:^(NSString *message, NSInteger errorCode) {
         NSLog(@"[LOG] Unsubscribed to Push Notification server & proxy successfully.");
@@ -507,7 +515,7 @@
     NSLog(@"FCM registration token: %@", fcmToken);
     [CCUtility setPushNotificationToken:fcmToken];
     
-    [self subscribingNextcloudServerPushNotification:self.activeUser userID:self.activeUserID password:self.activePassword url:self.activeUrl];
+    [self subscribingNextcloudServerPushNotification];
 }
 
 #pragma --------------------------------------------------------------------------------------------

+ 4 - 0
iOSClient/Login/CCLogin.m

@@ -463,6 +463,10 @@
                 
             } else {
                 
+                // LOGOUT
+                
+                [appDelegate unsubscribingNextcloudServerPushNotification];
+                
                 [[NCManageDatabase sharedInstance] deleteAccount:account];
                 [[NCManageDatabase sharedInstance] addAccount:account url:url user:user password:password loginFlow:false];
                 

+ 3 - 0
iOSClient/Login/CCLoginWeb.swift

@@ -121,6 +121,9 @@ extension CCLoginWeb: SwiftModalWebVCDelegate {
                     
                     if (loginType == k_login_Add || loginType == k_login_Add_Forced) {
                         
+                        // LOGOUT
+                        appDelegate.unsubscribingNextcloudServerPushNotification()
+                        
                         // Add new account
                         NCManageDatabase.sharedInstance.deleteAccount(account)
                         NCManageDatabase.sharedInstance.addAccount(account, url: serverUrl, user: username, password: password, loginFlow: true)

+ 11 - 1
iOSClient/Main/CCMain.m

@@ -1025,6 +1025,8 @@
         
         [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:YES];
     });
+    
+    [appDelegate subscribingNextcloudServerPushNotification];
 }
 
 - (void)loginClose
@@ -2633,13 +2635,21 @@
     
     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
 
+        // LOGOUT
+        
+        [appDelegate unsubscribingNextcloudServerPushNotification];
+        
         tableAccount *tableAccount = [[NCManageDatabase sharedInstance] setAccountActive:[sender argument]];
         if (tableAccount) {
             
+            // LOGIN
+            
             [appDelegate settingActiveAccount:tableAccount.account activeUrl:tableAccount.url activeUser:tableAccount.user activeUserID:tableAccount.userID activePassword:tableAccount.password];
     
             // go to home sweet home
-            [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];        
+            [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
+            
+            [appDelegate subscribingNextcloudServerPushNotification];
         }
     });
 }

+ 2 - 0
iOSClient/Main/CCMore.swift

@@ -451,6 +451,8 @@ class CCMore: UIViewController, UITableViewDelegate, UITableViewDataSource, CCLo
         NotificationCenter.default.post(name: NSNotification.Name(rawValue: "initializeMain"), object: nil, userInfo: nil)
         
         appDelegate.selectedTabBarController(Int(k_tabBarApplicationIndexFile))
+        
+        appDelegate.subscribingNextcloudServerPushNotification()
     }
     
     func loginClose() {

+ 2 - 0
iOSClient/Main/CCSplit.m

@@ -182,6 +182,8 @@
 - (void)loginSuccess:(NSInteger)loginType
 {
     [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
+    
+    [appDelegate subscribingNextcloudServerPushNotification];
 }
 
 - (void)loginClose

+ 6 - 0
iOSClient/Settings/CCManageAccount.m

@@ -202,6 +202,8 @@
 - (void)loginSuccess:(NSInteger)loginType
 {
     [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
+    
+    [appDelegate subscribingNextcloudServerPushNotification];
 }
 
 - (void)loginClose
@@ -271,6 +273,8 @@
         return;
     }
     
+    [appDelegate unsubscribingNextcloudServerPushNotification];
+    
     [appDelegate.netQueue cancelAllOperations];
     
     [[NCManageDatabase sharedInstance] clearTable:[tableAccount class] account:account];
@@ -348,6 +352,8 @@
             [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
             
             [self UpdateForm];
+            
+            [appDelegate subscribingNextcloudServerPushNotification];
         }
     });
 }