Forráskód Böngészése

Modify project OC

Marino Faggiana 8 éve
szülő
commit
f035d5ed1e

+ 4 - 11
Libraries external/OCCommunicationLib/OCCommunicationLib/OCCommunication.h

@@ -29,7 +29,9 @@
 @class AFURLSessionManager;
 @class AFSecurityPolicy;
 @class OCCapabilities;
-
+@class OCNotifications;
+@class OCRichObjectStrings;
+@class OCNotificationsAction;
 
 @interface OCCommunication : NSObject
 
@@ -767,15 +769,6 @@ typedef enum {
 /// @name Get the server Notification
 ///-----------------------------------
 
-/**
- * Method read the capabilities of the server
- *
- * @param serverPath  -> NSString server
- * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
- *
- * @return capabilities -> OCCapabilities
- *
- */
+- (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;
 
-- (void) getNotificationsOfTheServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, OCCapabilities *capabilities, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
 @end

+ 81 - 6
Libraries external/OCCommunicationLib/OCCommunicationLib/OCCommunication.m

@@ -37,6 +37,9 @@
 #import "AFURLSessionManager.h"
 #import "OCShareUser.h"
 #import "OCCapabilities.h"
+#import "OCNotifications.h"
+#import "OCNotificationsAction.h"
+#import "OCRichObjectStrings.h"
 
 @interface OCCommunication ()
 
@@ -1284,7 +1287,7 @@
 
 #pragma mark - Get Notification Server
 
-- (void) getNotificationsOfTheServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, OCCapabilities *capabilities, 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];
@@ -1292,15 +1295,87 @@
     OCWebDAVClient *request = [OCWebDAVClient new];
     request = [self getRequestWithCredentials:request];
     
-    
     [request getNotificationsOfTheServer:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
         
         NSData *responseData = (NSData*) responseObject;
-        OCXMLSharedParser *parser = [[OCXMLSharedParser alloc]init];
-            
-        [parser initParserWithData:responseData];
+        
+        //Parse
+        NSError *error;
+        NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
+        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"];
+                    notification.user = [data valueForKey:@"user"];
+                    notification.date = [data valueForKey:@"datetime"];
+                    notification.typeObject = [data valueForKey:@"object_type"];
+                    notification.idObject = [data valueForKey:@"object_id"];
+                    
+                    notification.subject = [data valueForKey:@"subject"];
+                    notification.subjectRich = [data valueForKey:@"subjectRich"];
+                    NSDictionary *subjectsRichParameters = [data valueForKey:@"subjectRichParameters"];
+                    
+                    NSMutableArray *listSubjectRichParameters = [NSMutableArray new];
+                    for (NSDictionary *subjectRichParameters in subjectsRichParameters) {
+                     
+                        OCRichObjectStrings *richObjectStrings = [OCRichObjectStrings new];
+                        
+                        richObjectStrings.idObject = [subjectRichParameters valueForKey:@"id"];
+                        richObjectStrings.type = [subjectRichParameters valueForKey:@"type"];
+                        richObjectStrings.name = [subjectRichParameters valueForKey:@"name"];
+                        richObjectStrings.path = [subjectRichParameters valueForKey:@"path"];
+                        richObjectStrings.link = [subjectRichParameters valueForKey:@"link"];
+                        richObjectStrings.server = [subjectRichParameters valueForKey:@"server"];
+                        
+                        [listSubjectRichParameters addObject:richObjectStrings];
+                    }
+                    notification.subjectRichParameters = [[NSArray alloc] initWithArray:listSubjectRichParameters copyItems:YES];
+                    
+                    notification.message = [data valueForKey:@"message"];
+                    notification.messageRich = [data valueForKey:@"messageRich"];
+                    NSDictionary *messagesRichParameters = [data valueForKey:@"messageRichParameters"];
+
+                    notification.link = [data valueForKey:@"link"];
+                    notification.icon = [data valueForKey:@"icon"];
+                    
+                    NSDictionary *actions = [data valueForKey:@"actions"];
+                    
+                    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);
+
+            }
+        }
     
-        NSLog(@"parser");
+        //Return success
+        successRequest(response, nil, request.redirectedServer);
         
     } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
         failureRequest(response, error, request.redirectedServer);

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

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

+ 30 - 0
Libraries external/OCCommunicationLib/OCCommunicationLib/OCNotifications.h

@@ -0,0 +1,30 @@
+//
+//  OCNotifications.h
+//  ownCloud iOS library
+//
+//  Created by Marino Faggiana on 23/01/17.
+//  Copyright © 2017 ownCloud. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface OCNotifications : NSObject
+
+@property NSInteger idNotification;
+@property (nonatomic, strong) NSString *app;
+@property (nonatomic, strong) NSString *user;
+@property long date;
+@property (nonatomic, strong) NSString *typeObject;
+@property (nonatomic, strong) NSString *idObject;
+@property (nonatomic, strong) NSString *subject;
+@property (nonatomic, strong) NSString *subjectRich;
+@property (nonatomic, strong) NSArray *subjectRichParameters;
+@property (nonatomic, strong) NSString *message;
+@property (nonatomic, strong) NSString *messageRich;
+@property (nonatomic, strong) NSArray *messageRichParameters;
+@property (nonatomic, strong) NSString *link;
+@property (nonatomic, strong) NSString *icon;
+@property (nonatomic, strong) NSArray *action;
+
+@end
+

+ 13 - 0
Libraries external/OCCommunicationLib/OCCommunicationLib/OCNotifications.m

@@ -0,0 +1,13 @@
+//
+//  OCNotifications.m
+//  ownCloud iOS library
+//
+//  Created by Marino Faggiana on 23/01/17.
+//  Copyright © 2017 ownCloud. All rights reserved.
+//
+
+#import "OCNotifications.h"
+
+@implementation OCNotifications
+
+@end

+ 18 - 0
Libraries external/OCCommunicationLib/OCCommunicationLib/OCNotificationsAction.h

@@ -0,0 +1,18 @@
+//
+//  OCNotificationsAction.h
+//  ownCloud iOS library
+//
+//  Created by Marino Faggiana on 23/01/17.
+//  Copyright © 2017 ownCloud. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface OCNotificationsAction : NSObject
+
+@property (nonatomic, strong) NSString *label;
+@property (nonatomic, strong) NSString *link;
+@property (nonatomic, strong) NSString *type;
+@property BOOL primary;
+
+@end

+ 13 - 0
Libraries external/OCCommunicationLib/OCCommunicationLib/OCNotificationsAction.m

@@ -0,0 +1,13 @@
+//
+//  OCNotificationsAction.m
+//  ownCloud iOS library
+//
+//  Created by Marino Faggiana on 23/01/17.
+//  Copyright © 2017 ownCloud. All rights reserved.
+//
+
+#import "OCNotificationsAction.h"
+
+@implementation OCNotificationsAction
+
+@end

+ 20 - 0
Libraries external/OCCommunicationLib/OCCommunicationLib/OCRichObjectStrings.h

@@ -0,0 +1,20 @@
+//
+//  OCRichObjectStrings.h
+//  ownCloud iOS library
+//
+//  Created by Marino Faggiana on 23/01/17.
+//  Copyright © 2017 ownCloud. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface OCRichObjectStrings : NSObject
+
+@property (nonatomic, strong) NSString *idObject;
+@property (nonatomic, strong) NSString *type;
+@property (nonatomic, strong) NSString *name;
+@property (nonatomic, strong) NSString *path;
+@property (nonatomic, strong) NSString *link;
+@property (nonatomic, strong) NSString *server;
+
+@end

+ 13 - 0
Libraries external/OCCommunicationLib/OCCommunicationLib/OCRichObjectStrings.m

@@ -0,0 +1,13 @@
+//
+//  OCRichObjectStrings.m
+//  ownCloud iOS library
+//
+//  Created by Marino Faggiana on 23/01/17.
+//  Copyright © 2017 ownCloud. All rights reserved.
+//
+
+#import "OCRichObjectStrings.h"
+
+@implementation OCRichObjectStrings
+
+@end

+ 18 - 0
Libraries external/OCCommunicationLib/ownCloud iOS library.xcodeproj/project.pbxproj

@@ -48,6 +48,9 @@
 		EAABAB39185B353100909831 /* test.jpeg in Resources */ = {isa = PBXBuildFile; fileRef = EAABAB38185B353100909831 /* test.jpeg */; };
 		EAABAB3C185EE33B00909831 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EAABAB3B185EE33B00909831 /* UIKit.framework */; };
 		EAABAB40185F225300909831 /* video.MOV in Resources */ = {isa = PBXBuildFile; fileRef = EAABAB3F185F225300909831 /* video.MOV */; };
+		F76D14561E365C3E006CD8B1 /* OCNotifications.m in Sources */ = {isa = PBXBuildFile; fileRef = F76D14511E365C3E006CD8B1 /* OCNotifications.m */; };
+		F76D14571E365C3E006CD8B1 /* OCNotificationsAction.m in Sources */ = {isa = PBXBuildFile; fileRef = F76D14531E365C3E006CD8B1 /* OCNotificationsAction.m */; };
+		F76D14581E365C3E006CD8B1 /* OCRichObjectStrings.m in Sources */ = {isa = PBXBuildFile; fileRef = F76D14551E365C3E006CD8B1 /* OCRichObjectStrings.m */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -135,6 +138,12 @@
 		EAABAB38185B353100909831 /* test.jpeg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; name = test.jpeg; path = Resources/test.jpeg; sourceTree = "<group>"; };
 		EAABAB3B185EE33B00909831 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
 		EAABAB3F185F225300909831 /* video.MOV */ = {isa = PBXFileReference; lastKnownFileType = video.quicktime; name = video.MOV; path = Resources/video.MOV; sourceTree = "<group>"; };
+		F76D14501E365C3E006CD8B1 /* OCNotifications.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCNotifications.h; sourceTree = "<group>"; };
+		F76D14511E365C3E006CD8B1 /* OCNotifications.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCNotifications.m; sourceTree = "<group>"; };
+		F76D14521E365C3E006CD8B1 /* OCNotificationsAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCNotificationsAction.h; sourceTree = "<group>"; };
+		F76D14531E365C3E006CD8B1 /* OCNotificationsAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCNotificationsAction.m; sourceTree = "<group>"; };
+		F76D14541E365C3E006CD8B1 /* OCRichObjectStrings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCRichObjectStrings.h; sourceTree = "<group>"; };
+		F76D14551E365C3E006CD8B1 /* OCRichObjectStrings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCRichObjectStrings.m; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -217,6 +226,12 @@
 				13AA8635187C211900A10927 /* OCSharedDto.m */,
 				EA913A701BE9FB0700D015B8 /* OCCapabilities.h */,
 				EA913A711BE9FB0700D015B8 /* OCCapabilities.m */,
+				F76D14501E365C3E006CD8B1 /* OCNotifications.h */,
+				F76D14511E365C3E006CD8B1 /* OCNotifications.m */,
+				F76D14521E365C3E006CD8B1 /* OCNotificationsAction.h */,
+				F76D14531E365C3E006CD8B1 /* OCNotificationsAction.m */,
+				F76D14541E365C3E006CD8B1 /* OCRichObjectStrings.h */,
+				F76D14551E365C3E006CD8B1 /* OCRichObjectStrings.m */,
 				EAABAA2F183E687000909831 /* OCFrameworkConstants.h */,
 				EA7CC932183E150000B6A4B4 /* OCCommunication.h */,
 				EA7CC933183E150000B6A4B4 /* OCCommunication.m */,
@@ -426,7 +441,10 @@
 				1345E4601884213400153F14 /* OCXMLShareByLinkParser.m in Sources */,
 				59A5B720191907F100724BE3 /* AFSecurityPolicy.m in Sources */,
 				EAABAA32183E688900909831 /* OCFileDto.m in Sources */,
+				F76D14581E365C3E006CD8B1 /* OCRichObjectStrings.m in Sources */,
+				F76D14561E365C3E006CD8B1 /* OCNotifications.m in Sources */,
 				EA7CC934183E150000B6A4B4 /* OCCommunication.m in Sources */,
+				F76D14571E365C3E006CD8B1 /* OCNotificationsAction.m in Sources */,
 				131C67B9187C3E360009030E /* OCXMLSharedParser.m in Sources */,
 				13AA8640187C3B9700A10927 /* OCXMLParser.m in Sources */,
 				EA7CC912183E146000B6A4B4 /* UtilsFramework.m in Sources */,

+ 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, OCCapabilities *capabilities, NSString *redirectedServer) {
+    [communication getNotificationsOfTheServer:[_activeUrl stringByAppendingString:@"/"] onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSArray *listOfNotifications, NSString *redirectedServer) {
         
         [self complete];