marinofaggiana 6 жил өмнө
parent
commit
4187a64bd5

+ 2 - 2
iOSClient/AppDelegate.h

@@ -160,8 +160,8 @@
 - (NSString *)getTabBarControllerActiveServerUrl;
 - (NSString *)getTabBarControllerActiveServerUrl;
 
 
 // Push Notification
 // Push Notification
-- (void)subscribingNextcloudServerPushNotification:(NSString *)account url:(NSString *)url token:(NSString *)token;
-- (void)unsubscribingNextcloudServerPushNotification:(NSString *)account url:(NSString *)url token:(NSString *)token;
+- (void)pushNotification;
+- (void)unsubscribingNextcloudServerPushNotification:(NSString *)account url:(NSString *)url withSubscribing:(BOOL)subscribing;
 
 
 // Theming Color
 // Theming Color
 - (void)settingThemingColorBrand;
 - (void)settingThemingColorBrand;

+ 44 - 30
iOSClient/AppDelegate.m

@@ -402,29 +402,50 @@ PKPushRegistry *pushRegistry;
 }
 }
 
 
 #pragma --------------------------------------------------------------------------------------------
 #pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Push Notification =====
+#pragma mark ===== PushNotification & PushKit Delegate =====
 #pragma --------------------------------------------------------------------------------------------
 #pragma --------------------------------------------------------------------------------------------
 
 
-- (void)subscribingNextcloudServerPushNotification:(NSString *)account url:(NSString *)url token:(NSString *)token
+- (void)pushNotification
 {
 {
     // test
     // test
-    if (self.activeAccount.length == 0 || self.maintenanceMode)
+    if (self.activeAccount.length == 0 || self.maintenanceMode || self.pushKitToken.length == 0)
+        return;
+    
+    NSString *token = [CCUtility getPushNotificationToken:self.activeAccount];
+    
+    if (![token isEqualToString:self.pushKitToken]) {
+        if (token != nil) {
+            // unsubscribing + subscribing
+            [self unsubscribingNextcloudServerPushNotification:self.activeAccount url:self.activeUrl withSubscribing:true];
+        } else {
+            [self subscribingNextcloudServerPushNotification:self.activeAccount url:self.activeUrl];
+        }
+    }
+}
+
+- (void)subscribingNextcloudServerPushNotification:(NSString *)account url:(NSString *)url
+{
+    // test
+    if (self.activeAccount.length == 0 || self.maintenanceMode || self.pushKitToken.length == 0)
         return;
         return;
     
     
     [[NCPushNotificationEncryption sharedInstance] generatePushNotificationsKeyPair:account];
     [[NCPushNotificationEncryption sharedInstance] generatePushNotificationsKeyPair:account];
 
 
-    NSString *pushTokenHash = [[NCEndToEndEncryption sharedManager] createSHA512:token];
+    NSString *pushTokenHash = [[NCEndToEndEncryption sharedManager] createSHA512:self.pushKitToken];
     NSData *pushPublicKey = [CCUtility getPushNotificationPublicKey:account];
     NSData *pushPublicKey = [CCUtility getPushNotificationPublicKey:account];
     NSString *pushDevicePublicKey = [[NSString alloc] initWithData:pushPublicKey encoding:NSUTF8StringEncoding];
     NSString *pushDevicePublicKey = [[NSString alloc] initWithData:pushPublicKey encoding:NSUTF8StringEncoding];
     
     
-    [[OCNetworking sharedManager] subscribingPushNotificationWithAccount:account url:url pushToken:token Hash:pushTokenHash devicePublicKey:pushDevicePublicKey completion:^(NSString *accountCompletion, NSString *deviceIdentifier, NSString *deviceIdentifierSignature, NSString *publicKey, NSString *message, NSInteger errorCode) {
+    [[OCNetworking sharedManager] subscribingPushNotificationWithAccount:account url:url pushToken:self.pushKitToken Hash:pushTokenHash devicePublicKey:pushDevicePublicKey completion:^(NSString *accountCompletion, NSString *deviceIdentifier, NSString *deviceIdentifierSignature, NSString *publicKey, NSString *message, NSInteger errorCode) {
         
         
         if (errorCode == 0 && [accountCompletion isEqualToString:account]) {
         if (errorCode == 0 && [accountCompletion isEqualToString:account]) {
+            
             NSLog(@"[LOG] Subscribed to Push Notification server & proxy successfully.");
             NSLog(@"[LOG] Subscribed to Push Notification server & proxy successfully.");
-            [CCUtility setPushNotificationToken:account token:token];
+            
+            [CCUtility setPushNotificationToken:account token:self.pushKitToken];
             [CCUtility setPushNotificationDeviceIdentifier:account deviceIdentifier:deviceIdentifier];
             [CCUtility setPushNotificationDeviceIdentifier:account deviceIdentifier:deviceIdentifier];
             [CCUtility setPushNotificationDeviceIdentifierSignature:account deviceIdentifierSignature:deviceIdentifierSignature];
             [CCUtility setPushNotificationDeviceIdentifierSignature:account deviceIdentifierSignature:deviceIdentifierSignature];
             [CCUtility setPushNotificationSubscribingPublicKey:account publicKey:publicKey];
             [CCUtility setPushNotificationSubscribingPublicKey:account publicKey:publicKey];
+            
         } else if (errorCode != 0) {
         } else if (errorCode != 0) {
             NSLog(@"[LOG] Subscribed to Push Notification server & proxy error.");
             NSLog(@"[LOG] Subscribed to Push Notification server & proxy error.");
         } else {
         } else {
@@ -433,7 +454,7 @@ PKPushRegistry *pushRegistry;
     }];
     }];
 }
 }
 
 
-- (void)unsubscribingNextcloudServerPushNotification:(NSString *)account url:(NSString *)url token:(NSString *)token
+- (void)unsubscribingNextcloudServerPushNotification:(NSString *)account url:(NSString *)url withSubscribing:(BOOL)subscribing
 {
 {
     // test
     // test
     if (self.activeAccount.length == 0 || self.maintenanceMode)
     if (self.activeAccount.length == 0 || self.maintenanceMode)
@@ -446,10 +467,20 @@ PKPushRegistry *pushRegistry;
     [[OCNetworking sharedManager] unsubscribingPushNotificationWithAccount:account url:url deviceIdentifier:deviceIdentifier deviceIdentifierSignature:deviceIdentifierSignature publicKey:publicKey completion:^(NSString *account, NSString *message, NSInteger errorCode) {
     [[OCNetworking sharedManager] unsubscribingPushNotificationWithAccount:account url:url deviceIdentifier:deviceIdentifier deviceIdentifierSignature:deviceIdentifierSignature publicKey:publicKey completion:^(NSString *account, NSString *message, NSInteger errorCode) {
        
        
         if (errorCode == 0) {
         if (errorCode == 0) {
+            
             NSLog(@"[LOG] Unsubscribed to Push Notification server & proxy successfully.");
             NSLog(@"[LOG] Unsubscribed to Push Notification server & proxy successfully.");
-            if (token != nil) {
-                [self subscribingNextcloudServerPushNotification:account url:url token:token];
+            
+            [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) {
         } else if (errorCode != 0) {
             NSLog(@"[LOG] Unsubscribed to Push Notification server & proxy error.");
             NSLog(@"[LOG] Unsubscribed to Push Notification server & proxy error.");
         } else {
         } else {
@@ -528,10 +559,6 @@ PKPushRegistry *pushRegistry;
     completionHandler(fetchResult);
     completionHandler(fetchResult);
 }
 }
 
 
-
-#pragma FIREBASE
-
-
 - (void)messaging:(FIRMessaging *)messaging didReceiveRegistrationToken:(NSString *)fcmToken
 - (void)messaging:(FIRMessaging *)messaging didReceiveRegistrationToken:(NSString *)fcmToken
 {
 {
 
 
@@ -552,10 +579,6 @@ PKPushRegistry *pushRegistry;
     }
     }
 }
 }
 */
 */
- 
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== PushKit Delegate =====
-#pragma --------------------------------------------------------------------------------------------
 
 
 - (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type
 - (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type
 {
 {
@@ -565,15 +588,7 @@ PKPushRegistry *pushRegistry;
     
     
     self.pushKitToken = [self stringWithDeviceToken:credentials.token];
     self.pushKitToken = [self stringWithDeviceToken:credentials.token];
 
 
-    NSString *token = [CCUtility getPushNotificationToken:self.activeAccount];
-    if (![token isEqualToString:self.pushKitToken]) {
-        if (token != nil) {
-            // unsubscribing + subscribing
-            [self unsubscribingNextcloudServerPushNotification:self.activeAccount url:self.activeUrl token:self.pushKitToken];
-        } else {
-            [self subscribingNextcloudServerPushNotification:self.activeAccount url:self.activeUrl token:self.pushKitToken];
-        }
-    }
+    [self pushNotification];
 }
 }
 
 
 - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type
 - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type
@@ -605,13 +620,12 @@ PKPushRegistry *pushRegistry;
                     } else {
                     } else {
                         content.body = @"Nextcloud notification";
                         content.body = @"Nextcloud notification";
                     }
                     }
-                    
+                    content.sound = [UNNotificationSound defaultSound];
+
                     [[OCNetworking sharedManager] getServerNotification:result.url notificationId:notificationId completion:^(NSDictionary *json, NSString *message, NSInteger errorCode) {
                     [[OCNetworking sharedManager] getServerNotification:result.url notificationId:notificationId completion:^(NSDictionary *json, NSString *message, NSInteger errorCode) {
                         //
                         //
                     }];
                     }];
-                    
-                    content.sound = [UNNotificationSound defaultSound];
-                    
+                                        
                     NSString *identifier = [NSString stringWithFormat:@"Notification-%@", [NSDate new]];
                     NSString *identifier = [NSString stringWithFormat:@"Notification-%@", [NSDate new]];
                     
                     
                     UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:0.1 repeats:NO];
                     UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:0.1 repeats:NO];

+ 3 - 0
iOSClient/Main/CCMain.m

@@ -375,6 +375,9 @@
         // reload datasource
         // reload datasource
         [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:_serverUrl fileID:nil action:k_action_NULL];
         [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:_serverUrl fileID:nil action:k_action_NULL];
     }
     }
+    
+    // Registered push notification
+    [appDelegate pushNotification];
 }
 }
 
 
 #pragma --------------------------------------------------------------------------------------------
 #pragma --------------------------------------------------------------------------------------------

+ 0 - 3
iOSClient/Security/NCPushNotificationEncryption.m

@@ -67,8 +67,6 @@
         return NO;
         return NO;
     }
     }
     
     
-    
-    
     // Extract publicKey, privateKey
     // Extract publicKey, privateKey
     int len;
     int len;
     char *keyBytes;
     char *keyBytes;
@@ -137,5 +135,4 @@
     return decryptString;
     return decryptString;
 }
 }
 
 
-
 @end
 @end

+ 24 - 16
iOSClient/Settings/CCManageAccount.m

@@ -233,22 +233,30 @@
 #pragma --------------------------------------------------------------------------------------------
 #pragma --------------------------------------------------------------------------------------------
 
 
 - (void)deleteAccount:(NSString *)account
 - (void)deleteAccount:(NSString *)account
-{    
-    [[NCManageDatabase sharedInstance] clearTable:[tableAccount class] account:account];
-    [[NCManageDatabase sharedInstance] clearTable:[tableActivity class] account:account];
-    [[NCManageDatabase sharedInstance] clearTable:[tableActivitySubjectRich class] account:account];
-    [[NCManageDatabase sharedInstance] clearTable:[tableCapabilities class] account:account];
-    [[NCManageDatabase sharedInstance] clearTable:[tableDirectory class] account:account];
-    [[NCManageDatabase sharedInstance] clearTable:[tableE2eEncryption class] account:account];
-    [[NCManageDatabase sharedInstance] clearTable:[tableExternalSites class] account:account];
-    [[NCManageDatabase sharedInstance] clearTable:[tableLocalFile class] account:account];
-    [[NCManageDatabase sharedInstance] clearTable:[tableMetadata class] account:account];
-    [[NCManageDatabase sharedInstance] clearTable:[tableMedia class] account:account];
-    [[NCManageDatabase sharedInstance] clearTable:[tablePhotoLibrary class] account:account];
-    [[NCManageDatabase sharedInstance] clearTable:[tableShare class] account:account];
-    
-    // Clear active user
-    [appDelegate settingActiveAccount:nil activeUrl:nil activeUser:nil activeUserID:nil activePassword:nil];
+{
+    tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
+    if (tableAccount) {
+        [appDelegate unsubscribingNextcloudServerPushNotification:tableAccount.account url:tableAccount.url withSubscribing:false];
+    }
+    
+    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
+
+        [[NCManageDatabase sharedInstance] clearTable:[tableAccount class] account:account];
+        [[NCManageDatabase sharedInstance] clearTable:[tableActivity class] account:account];
+        [[NCManageDatabase sharedInstance] clearTable:[tableActivitySubjectRich class] account:account];
+        [[NCManageDatabase sharedInstance] clearTable:[tableCapabilities class] account:account];
+        [[NCManageDatabase sharedInstance] clearTable:[tableDirectory class] account:account];
+        [[NCManageDatabase sharedInstance] clearTable:[tableE2eEncryption class] account:account];
+        [[NCManageDatabase sharedInstance] clearTable:[tableExternalSites class] account:account];
+        [[NCManageDatabase sharedInstance] clearTable:[tableLocalFile class] account:account];
+        [[NCManageDatabase sharedInstance] clearTable:[tableMetadata class] account:account];
+        [[NCManageDatabase sharedInstance] clearTable:[tableMedia class] account:account];
+        [[NCManageDatabase sharedInstance] clearTable:[tablePhotoLibrary class] account:account];
+        [[NCManageDatabase sharedInstance] clearTable:[tableShare class] account:account];
+    
+        // Clear active user
+        [appDelegate settingActiveAccount:nil activeUrl:nil activeUser:nil activeUserID:nil activePassword:nil];
+    });
 }
 }
 
 
 - (void)answerDelAccount:(XLFormRowDescriptor *)sender
 - (void)answerDelAccount:(XLFormRowDescriptor *)sender