Эх сурвалжийг харах

remake protocol setNotificationServerSuccessFailure

Marino Faggiana 7 жил өмнө
parent
commit
6df5e5ce8f

+ 1 - 3
iOSClient/Networking/OCNetworking.h

@@ -87,9 +87,7 @@
 
 // Notification
 - (void)getNotificationServerSuccessFailure:(CCMetadataNet *)metadataNet listOfNotifications:(NSArray *)listOfNotifications message:(NSString *)message errorCode:(NSInteger)errorCode;
-
-- (void)setNotificationServerSuccess:(CCMetadataNet *)metadataNet;
-- (void)setNotificationServerFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode;
+- (void)setNotificationServerSuccessFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode;
 
 // User Profile
 - (void)getUserProfileSuccessFailure:(CCMetadataNet *)metadataNet userProfile:(OCUserProfile *)userProfile message:(NSString *)message errorCode:(NSInteger)errorCode;

+ 7 - 7
iOSClient/Networking/OCNetworking.m

@@ -1479,15 +1479,15 @@
         // Test active account
         tableAccount *recordAccount = [[NCManageDatabase sharedInstance] getAccountActive];
         if (![recordAccount.account isEqualToString:_metadataNet.account]) {
-            if ([self.delegate respondsToSelector:@selector(setNotificationServerFailure:message:errorCode:)])
-                [self.delegate setNotificationServerFailure:_metadataNet message:NSLocalizedStringFromTable(@"_error_user_not_available_", @"Error", nil) errorCode:k_CCErrorUserNotAvailble];
+            if ([self.delegate respondsToSelector:@selector(setNotificationServerSuccessFailure:message:errorCode:)])
+                [self.delegate setNotificationServerSuccessFailure:_metadataNet message:NSLocalizedStringFromTable(@"_error_user_not_available_", @"Error", nil) errorCode:k_CCErrorUserNotAvailble];
             
             [self complete];
             return;
         }
         
-        if ([self.delegate respondsToSelector:@selector(setNotificationServerSuccess:)])
-            [self.delegate setNotificationServerSuccess:_metadataNet];
+        if ([self.delegate respondsToSelector:@selector(setNotificationServerSuccessFailure:message:errorCode:)])
+            [self.delegate setNotificationServerSuccessFailure:_metadataNet message:nil errorCode:0];
         
         [self complete];
         
@@ -1498,12 +1498,12 @@
             errorCode = error.code;
         
         // Error
-        if ([self.delegate respondsToSelector:@selector(setNotificationServerFailure:message:errorCode:)]) {
+        if ([self.delegate respondsToSelector:@selector(setNotificationServerSuccessFailure:message:errorCode:)]) {
             
             if (errorCode == 503)
-                [self.delegate setNotificationServerFailure:_metadataNet message:NSLocalizedStringFromTable(@"_server_error_retry_", @"Error", nil) errorCode:errorCode];
+                [self.delegate setNotificationServerSuccessFailure:_metadataNet message:NSLocalizedStringFromTable(@"_server_error_retry_", @"Error", nil) errorCode:errorCode];
             else
-                [self.delegate setNotificationServerFailure:_metadataNet message:[error.userInfo valueForKey:@"NSLocalizedDescription"] errorCode:errorCode];
+                [self.delegate setNotificationServerSuccessFailure:_metadataNet message:[error.userInfo valueForKey:@"NSLocalizedDescription"] errorCode:errorCode];
         }
 
         // Request trusted certificated

+ 18 - 16
iOSClient/Notification/CCNotification.swift

@@ -188,28 +188,30 @@ class CCNotification: UITableViewController, OCNetworkingDelegate {
     
     // MARK: - Networking delegate
 
-    func setNotificationServerFailure(_ metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
-        
-        appDelegate.messageNotification("_error_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
-    }
-    
-    func setNotificationServerSuccess(_ metadataNet: CCMetadataNet!) {
+    func setNotificationServerSuccessFailure(_ metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
         
         // Check Active Account
         if (metadataNet.account != appDelegate.activeAccount) {
             return
         }
         
-        let listOfNotifications = appDelegate.listOfNotifications as NSArray as! [OCNotifications]
-        
-        if let index = listOfNotifications.index(where: {$0.idNotification == Int(metadataNet.assetLocalIdentifier)})  {
-            appDelegate.listOfNotifications.removeObject(at: index)
-        }
-        
-        self.tableView.reloadData()
-        
-        if appDelegate.listOfNotifications.count == 0 {
-            viewClose()
+        if (errorCode == 0) {
+            
+            let listOfNotifications = appDelegate.listOfNotifications as NSArray as! [OCNotifications]
+            
+            if let index = listOfNotifications.index(where: {$0.idNotification == Int(metadataNet.assetLocalIdentifier)})  {
+                appDelegate.listOfNotifications.removeObject(at: index)
+            }
+            
+            self.tableView.reloadData()
+            
+            if appDelegate.listOfNotifications.count == 0 {
+                viewClose()
+            }
+            
+        } else {
+            
+            appDelegate.messageNotification("_error_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
         }
     }