浏览代码

remake protocol getNotificationServerSuccessFailure

Marino Faggiana 7 年之前
父节点
当前提交
03a38cd6a0
共有 3 个文件被更改,包括 48 次插入51 次删除
  1. 40 42
      iOSClient/Main/CCMain.m
  2. 1 2
      iOSClient/Networking/OCNetworking.h
  3. 7 7
      iOSClient/Networking/OCNetworking.m

+ 40 - 42
iOSClient/Main/CCMain.m

@@ -1042,60 +1042,58 @@
 #pragma mark ==== Notification  ====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)getNotificationServerSuccess:(CCMetadataNet *)metadataNet listOfNotifications:(NSArray *)listOfNotifications
+- (void)getNotificationServerSuccessFailure:(CCMetadataNet *)metadataNet listOfNotifications:(NSArray *)listOfNotifications message:(NSString *)message errorCode:(NSInteger)errorCode
 {
     // Check Active Account
     if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
         return;
     
-    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
+    if (errorCode == 0) {
+    
+        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
+            
+            // Order by date
+            NSArray *sortedListOfNotifications = [listOfNotifications sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
+                
+                OCNotifications *notification1 = obj1, *notification2 = obj2;
+            
+                return [notification2.date compare: notification1.date];
+            
+            }];
         
-        // Order by date
-        NSArray *sortedListOfNotifications = [listOfNotifications sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
+            // verify if listOfNotifications is changed
+            NSString *old = @"", *new = @"";
+            for (OCNotifications *notification in listOfNotifications)
+                new = [new stringByAppendingString:@(notification.idNotification).stringValue];
+            for (OCNotifications *notification in appDelegate.listOfNotifications)
+                old = [old stringByAppendingString:@(notification.idNotification).stringValue];
+
+            if (![new isEqualToString:old]) {
             
-            OCNotifications *notification1 = obj1, *notification2 = obj2;
+                appDelegate.listOfNotifications = [[NSMutableArray alloc] initWithArray:sortedListOfNotifications];
+            
+                // reload Notification view
+                [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"notificationReloadData" object:nil];
+            }
         
-            return [notification2.date compare: notification1.date];
+            // Update NavigationBar
+            if (!_isSelectedMode) {
+                
+                [self performSelectorOnMainThread:@selector(setUINavigationBarDefault) withObject:nil waitUntilDone:NO];
+            }
+        });
         
-        }];
-    
-        // verify if listOfNotifications is changed
-        NSString *old = @"", *new = @"";
-        for (OCNotifications *notification in listOfNotifications)
-            new = [new stringByAppendingString:@(notification.idNotification).stringValue];
-        for (OCNotifications *notification in appDelegate.listOfNotifications)
-            old = [old stringByAppendingString:@(notification.idNotification).stringValue];
-
-        if (![new isEqualToString:old]) {
+    } else {
         
-            appDelegate.listOfNotifications = [[NSMutableArray alloc] initWithArray:sortedListOfNotifications];
+        NSString *error = [NSString stringWithFormat:@"Get Notification Server failure error %d, %@", (int)errorCode, message];
+        NSLog(@"[LOG] %@", error);
+        
+        [[NCManageDatabase sharedInstance] addActivityClient:@"" fileID:@"" action:k_activityDebugActionCapabilities selector:@"Get Notification Server" note:error type:k_activityTypeFailure verbose:k_activityVerboseHigh activeUrl:appDelegate.activeUrl];
         
-            // reload Notification view
-            [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"notificationReloadData" object:nil];
-        }
-    
         // Update NavigationBar
-        if (!_isSelectedMode) {
-            
-            [self performSelectorOnMainThread:@selector(setUINavigationBarDefault) withObject:nil waitUntilDone:NO];
-        }
-    });
-}
-
-- (void)getNotificationServerFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
-{
-    // Check Active Account
-    if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
-        return;
-    
-    NSString *error = [NSString stringWithFormat:@"Get Notification Server failure error %d, %@", (int)errorCode, message];
-    NSLog(@"[LOG] %@", error);
-    
-    [[NCManageDatabase sharedInstance] addActivityClient:@"" fileID:@"" action:k_activityDebugActionCapabilities selector:@"Get Notification Server" note:error type:k_activityTypeFailure verbose:k_activityVerboseHigh activeUrl:appDelegate.activeUrl];
-    
-    // Update NavigationBar
-    if (!_isSelectedMode)
-        [self setUINavigationBarDefault];
+        if (!_isSelectedMode)
+            [self setUINavigationBarDefault];
+    }
 }
 
 - (void)viewNotification

+ 1 - 2
iOSClient/Networking/OCNetworking.h

@@ -88,8 +88,7 @@
 - (void)getExternalSitesServerFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode;
 
 // Notification
-- (void)getNotificationServerSuccess:(CCMetadataNet *)metadataNet listOfNotifications:(NSArray *)listOfNotifications;
-- (void)getNotificationServerFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode;
+- (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;

+ 7 - 7
iOSClient/Networking/OCNetworking.m

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