Browse Source

Change OCNotifications

Marino Faggiana 8 years ago
parent
commit
7399eca9bb

+ 2 - 1
Libraries external/OCCommunicationLib/OCCommunicationLib/OCCommunication.h

@@ -768,5 +768,6 @@ typedef enum {
 /// @name Get the server Notification
 ///-----------------------------------
 
-- (void) getNotificationsOfTheServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, OCNotifications *notifications, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
+- (void) getNotificationsOfTheServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *listOfNotifications, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
+
 @end

+ 37 - 8
Libraries external/OCCommunicationLib/OCCommunicationLib/OCCommunication.m

@@ -38,7 +38,6 @@
 #import "OCShareUser.h"
 #import "OCCapabilities.h"
 #import "OCNotifications.h"
-#import "OCXMLNotificationsParser.h"
 
 @interface OCCommunication ()
 
@@ -1286,7 +1285,7 @@
 
 #pragma mark - Get Notification Server
 
-- (void) getNotificationsOfTheServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, OCNotifications *notifications, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest{
+- (void) getNotificationsOfTheServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *listOfNotifications, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest{
     
     serverPath = [serverPath encodeString:NSUTF8StringEncoding];
     serverPath = [serverPath stringByAppendingString:k_url_acces_remote_notification_api];
@@ -1301,17 +1300,47 @@
         //Parse
         NSError *error;
         NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
-        NSLog(@"dic: %@",jsongParsed);
-        
-        OCNotifications *notification = [OCNotifications new];
-
-        
+        NSLog(@"[LOG] Notifications : %@",jsongParsed);
         
+        if (jsongParsed.allKeys > 0) {
         
+            NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
+            NSDictionary *meta = [ocs valueForKey:@"meta"];
+            NSDictionary *datas = [ocs valueForKey:@"data"];
         
+            NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
+                        
+            if (statusCode == kOCNotificationAPINoContent || statusCode == kOCNotificationAPISuccessful) {
+                
+                for (NSDictionary *data in datas) {
+                
+                    OCNotifications *notification = [OCNotifications new];
+                    
+                    notification.idNotification = [[data valueForKey:@"notification_id"] integerValue];
+                    notification.app = [data valueForKey:@"app"];
+                
+                    NSLog(@"end");
+
+                }
+                
+                NSLog(@"end");
+                
+            } else {
+                
+                NSString *message = (NSString*)[meta objectForKey:@"message"];
+                
+                if ([message isKindOfClass:[NSNull class]]) {
+                    message = @"";
+                }
+                
+                NSError *error = [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message];
+                failureRequest(response, error, request.redirectedServer);
+
+            }
+        }
     
         //Return success
-        successRequest(response, notification, request.redirectedServer);
+        successRequest(response, nil, request.redirectedServer);
         
     } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
         failureRequest(response, error, request.redirectedServer);

+ 5 - 0
Libraries external/OCCommunicationLib/OCCommunicationLib/OCErrorMsg.h

@@ -37,6 +37,11 @@
 #define kOCSharedAPISuccessful 100
 #define kOCShareeAPISuccessful 200
 
+#define kOCNotificationAPISuccessful 200
+#define kOCNotificationAPINoContent  204
+
+
+
 typedef enum {
     OCServerErrorForbiddenCharacters = 101,
 } OCServerErrorEnum;

+ 1 - 1
iOSClient/Networking/OCNetworking.m

@@ -942,7 +942,7 @@
     [communication setCredentialsWithUser:_activeUser andPassword:_activePassword];
     [communication setUserAgent:[CCUtility getUserAgent:_typeCloud]];
     
-    [communication getNotificationsOfTheServer:[_activeUrl stringByAppendingString:@"/"] onCommunication:communication successRequest:^(NSHTTPURLResponse *response, OCNotifications *notifications, NSString *redirectedServer) {
+    [communication getNotificationsOfTheServer:[_activeUrl stringByAppendingString:@"/"] onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSArray *listOfNotifications, NSString *redirectedServer) {
         
         [self complete];