Browse Source

Delete Notification

Marino Faggiana 8 years ago
parent
commit
c8e55b8aa7

+ 15 - 3
Libraries external/OCCommunicationLib/OCCommunicationLib/OCCommunication.h

@@ -771,18 +771,30 @@ typedef enum {
 /**
  * Method read the notification of the server
  *
- * @param serverPath  -> NSString server
+ * @param serverPath            -> NSString server
  * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  *
- * @return listOfNotifications -> OCNotification
+ * @return listOfNotifications  -> OCNotification
  *
  */
 
 - (void) getNotificationsOfServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *listOfNotifications, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
 
 
+///-----------------------------------
+/// @name Delete Notification
+///-----------------------------------
+
+/**
+ * Method read the notification of the server
+ *
+ * @param serverPath            -> NSString server
+ * @param idNotification        -> NSString idNotification
+ * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
+ *
+ */
 
-- (void) deleteNotification:(NSString*)serverPath notification_id:(NSString *)notification_id onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
+- (void) deleteNotification:(NSString*)serverPath idNotification:(NSString *)idNotification onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
 
 @end
 

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

@@ -1380,7 +1380,7 @@
     }];
 }
 
-- (void) deleteNotification:(NSString*)serverPath notification_id:(NSString *)notification_id onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void (^)(NSHTTPURLResponse *, NSString *))successRequest failureRequest:(void (^)(NSHTTPURLResponse *, NSError *, NSString *))failureRequest {
+- (void) deleteNotification:(NSString*)serverPath idNotification:(NSString *)idNotification onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void (^)(NSHTTPURLResponse *, NSString *))successRequest failureRequest:(void (^)(NSHTTPURLResponse *, NSError *, NSString *))failureRequest {
     
     serverPath = [serverPath encodeString:NSUTF8StringEncoding];
     serverPath = [serverPath stringByAppendingString:k_url_acces_remote_notification_api];
@@ -1388,8 +1388,11 @@
     OCWebDAVClient *request = [OCWebDAVClient new];
     request = [self getRequestWithCredentials:request];
     
-    [request deleteNotification:serverPath notification_id:notification_id onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-        
+    [request deleteNotification:serverPath idNotification:idNotification onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
+        if (successRequest) {
+            //Return success
+            successRequest(response, request.redirectedServer);
+        }
     } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
         failureRequest(response, error, request.redirectedServer);
     }];

+ 16 - 3
Libraries external/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.h

@@ -475,15 +475,28 @@ extern NSString * _Nullable OCWebDAVModificationDateKey;
 /**
  * Method read the notification of the server
  *
- * @param serverPath  -> NSString server
+ * @param serverPath            -> NSString server
  * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
  *
- * @return listOfNotifications -> OCNotification
+ * @return listOfNotifications  -> OCNotification
  *
  */
 
 - (void) getNotificationsOfServer:(NSString * _Nonnull)serverPath onCommunication:(OCCommunication * _Nonnull)sharedOCComunication success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull operation, id _Nonnull response))success failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull operation, id  _Nullable responseObject, NSError * _Nonnull error))failure;
 
-- (void)deleteNotification:(NSString * _Nonnull)serverPath notification_id:(NSString * _Nonnull)notification_id onCommunication:(OCCommunication * _Nonnull)sharedOCCommunication success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id _Nonnull))success failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id  _Nullable responseObject, NSError * _Nonnull))failure;
+///-----------------------------------
+/// @name Delete Notification
+///-----------------------------------
+
+/**
+ * Method read the notification of the server
+ *
+ * @param serverPath            -> NSString server
+ * @param idNotification        -> NSString idNotification
+ * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
+ *
+ */
+
+- (void)deleteNotification:(NSString * _Nonnull)serverPath idNotification:(NSString * _Nonnull)idNotification onCommunication:(OCCommunication * _Nonnull)sharedOCCommunication success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id _Nonnull))success failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id  _Nullable responseObject, NSError * _Nonnull))failure;
 
 @end

+ 2 - 2
Libraries external/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m

@@ -637,13 +637,13 @@ NSString const *OCWebDAVModificationDateKey	= @"modificationdate";
     [operation resume];
 }
 
-- (void) deleteNotification:(NSString *)serverPath notification_id:(NSString *)notification_id onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *, id))success failure:(void(^)(NSHTTPURLResponse *, id  _Nullable responseObject, NSError *))failure {
+- (void) deleteNotification:(NSString *)serverPath idNotification:(NSString *)idNotification onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *, id))success failure:(void(^)(NSHTTPURLResponse *, id  _Nullable responseObject, NSError *))failure {
     
     NSParameterAssert(success);
     
     _requestMethod = @"DELETE";
     
-    serverPath = [NSString stringWithFormat:@"%@/%@", serverPath, notification_id];
+    serverPath = [NSString stringWithFormat:@"%@/%@", serverPath, idNotification];
     
     NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil];
     

+ 1 - 1
iOSClient/AppDelegate.h

@@ -71,7 +71,7 @@
 @property BOOL hasServerShareeSupport;
 @property BOOL hasServerCapabilitiesSupport;
 @property OCCapabilities *capabilities;
-@property (nonatomic, strong) NSArray *listOfNotifications;
+@property (nonatomic, strong) NSMutableDictionary *listOfNotifications;
 
 // Network Operation
 @property (nonatomic, strong) NSOperationQueue *netQueue;

+ 3 - 0
iOSClient/AppDelegate.m

@@ -141,6 +141,9 @@
     self.sharesLink = [[NSMutableDictionary alloc] init];
     self.sharesUserAndGroup = [[NSMutableDictionary alloc] init];
     
+    // Initialize Notification
+    self.listOfNotifications = [[NSMutableDictionary alloc] init];
+    
     // Verify Session in progress and Init date task
     self.sessionDateLastDownloadTasks = [NSDate date];
     self.sessionDateLastUploadTasks = [NSDate date];

+ 44 - 11
iOSClient/Main/CCMain.m

@@ -1013,37 +1013,70 @@
 
 - (void)getNotificationsOfServerSuccess:(NSArray *)listOfNotifications
 {
-    app.listOfNotifications = [[NSArray alloc] initWithArray:listOfNotifications];
+    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
     
-    for (OCNotifications *notification in listOfNotifications) {
-                
-        //[app messageNotification:@"Notication" description:notification.subject visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeInfo];
+    // Insert/update listOfNotifications in Dictionary App.listOfNotifications
+    for (OCNotifications *notification in listOfNotifications)
+        [appDelegate.listOfNotifications setObject:notification forKey:[NSString stringWithFormat:@"%lu", (unsigned long)notification.idNotification]];
         
-        [JSAlertView alert:notification.subject withTitle:@"Server Notification" buttons:@[@"OK",@"NO"] withCompletionHandler:^(NSInteger buttonIndex, NSString *buttonTitle) {
-            NSLog(@"Pressed %@ at index %ld", buttonTitle, (long)buttonIndex);
-        }];
+    for (NSString *idNotification in app.listOfNotifications) {
+        
+        OCNotifications *notification = [app.listOfNotifications objectForKey:idNotification];
+        
+        // No Action request
+        if ([notification.actions count] == 0) {
+            
+            [JSAlertView alert:notification.subject withTitle:@"Server Notification" buttons:@[NSLocalizedString(@"_close_", nil),NSLocalizedString(@"_postpone_", nil)] withCompletionHandler:^(NSInteger buttonIndex, NSString *buttonTitle) {
+                
+                NSLog(@"Pressed %@ at index %ld", buttonTitle, (long)buttonIndex);
+                
+                if ([buttonTitle isEqualToString:NSLocalizedString(@"_close_", nil)]) {
+                    
+                    if ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud]) {
+                        
+                        CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
+                        
+                        metadataNet.action  = actionDeleteNotifications;
+                        metadataNet.options = [NSString stringWithFormat:@"%lu", (unsigned long)notification.idNotification];
+                        
+                        [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
+                    }
+                }
+            }];
+        }
     }
 }
 
-- (void)showNotification
+- (void)deleteNotificationsSuccess:(CCMetadataNet *)metadataNet
 {
+    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
     
+    NSString *idNotification = metadataNet.options;
+    
+    [appDelegate.listOfNotifications  removeObjectForKey:idNotification];
+    
+    NSLog(@"delete Notification id :%@", idNotification);
 }
 
-- (void)getNotificationsOfServerFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
+- (void)deleteNotificationsFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
 {
     NSLog(@"Error Notification");
 }
 
-- (void)getCapabilitiesOfServerSuccess:(OCCapabilities *)capabilities
+- (void)getNotificationsOfServerFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
 {
-    app.capabilities = capabilities;
+    NSLog(@"Error Notification");
 }
 
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ==== Request Server  ====
 #pragma --------------------------------------------------------------------------------------------
 
+- (void)getCapabilitiesOfServerSuccess:(OCCapabilities *)capabilities
+{
+    app.capabilities = capabilities;
+}
+
 - (void)getFeaturesSupportedByServerSuccess:(BOOL)hasCapabilitiesSupport hasForbiddenCharactersSupport:(BOOL)hasForbiddenCharactersSupport hasShareSupport:(BOOL)hasShareSupport hasShareeSupport:(BOOL)hasShareeSupport
 {
     app.hasServerCapabilitiesSupport = hasCapabilitiesSupport;

+ 3 - 0
iOSClient/Networking/OCNetworking.h

@@ -97,6 +97,9 @@
 - (void)getNotificationsOfServerSuccess:(NSArray *)listOfNotifications;
 - (void)getNotificationsOfServerFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode;
 
+- (void)deleteNotificationsSuccess:(CCMetadataNet *)metadataNet;
+- (void)deleteNotificationsFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode;
+
 // HUD
 - (void)progressTask:(NSString *)fileID serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated progress:(float)progress;
 

+ 22 - 4
iOSClient/Networking/OCNetworking.m

@@ -963,7 +963,6 @@
             [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:[error localizedDescription] viewController:(UIViewController *)self.delegate delegate:self];
         
         [self complete];
-
     }];
 }
 
@@ -974,10 +973,29 @@
     [communication setCredentialsWithUser:_activeUser andPassword:_activePassword];
     [communication setUserAgent:[CCUtility getUserAgent:_typeCloud]];
     
-    [communication deleteNotification:[_activeUrl stringByAppendingString:@"/"] notification_id:0 onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
-        NSLog(@"a");
+    NSString *idNotification = _metadataNet.options;
+    
+    [communication deleteNotification:[_activeUrl stringByAppendingString:@"/"] idNotification:idNotification onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
+        
+        if ([self.delegate respondsToSelector:@selector(deleteNotificationsSuccess:)])
+            [self.delegate deleteNotificationsSuccess:_metadataNet];
+        
+        [self complete];
+        
     } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
-        NSLog(@"b");
+        
+        NSInteger errorCode = response.statusCode;
+        if (errorCode == 0)
+            errorCode = error.code;
+        
+        if([self.delegate respondsToSelector:@selector(deleteNotificationsFailure:message:errorCode:)])
+            [self.delegate deleteNotificationsFailure:_metadataNet message:[error.userInfo valueForKey:@"NSLocalizedDescription"] errorCode:errorCode];
+        
+        // Request trusted certificated
+        if ([error code] == NSURLErrorServerCertificateUntrusted)
+            [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:[error localizedDescription] viewController:(UIViewController *)self.delegate delegate:self];
+        
+        [self complete];
     }];
 }
 

+ 2 - 0
iOSClient/en.lproj/Localizable.strings

@@ -54,6 +54,8 @@
 "_transfers_in_queue_"      = "Tranfers in progress, please wait ...";
 "_too_errors_automatic_all_"= "Too many errors, go to Control Center to verify the problem";
 "_create_folder_"           = "Create folder";
+"_close_"                   = "Close";
+"_postpone_"                = "Postpone";
 
 // App