|
@@ -380,232 +380,6 @@
|
|
|
}];
|
|
|
}
|
|
|
|
|
|
-#pragma --------------------------------------------------------------------------------------------
|
|
|
-#pragma mark ===== Push Notification =====
|
|
|
-#pragma --------------------------------------------------------------------------------------------
|
|
|
-
|
|
|
-- (void)subscribingPushNotificationWithAccount:(NSString *)account url:(NSString *)url pushToken:(NSString *)pushToken Hash:(NSString *)pushTokenHash devicePublicKey:(NSString *)devicePublicKey completion:(void(^)(NSString *account, NSString *deviceIdentifier, NSString *deviceIdentifierSignature, NSString *publicKey, NSString *message, NSInteger errorCode))completion
|
|
|
-{
|
|
|
- tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
|
|
|
- if (tableAccount == nil) {
|
|
|
- completion(account, nil, nil, nil, NSLocalizedString(@"_error_user_not_available_", nil), k_CCErrorUserNotAvailble);
|
|
|
- } else if ([CCUtility getPassword:account].length == 0) {
|
|
|
- completion(account, nil, nil, nil, NSLocalizedString(@"_bad_username_password_", nil), kOCErrorServerUnauthorized);
|
|
|
- } else if ([CCUtility getCertificateError:account]) {
|
|
|
- completion(account, nil, nil, nil, NSLocalizedString(@"_ssl_certificate_untrusted_", nil), NSURLErrorServerCertificateUntrusted);
|
|
|
- }
|
|
|
-
|
|
|
- devicePublicKey = [CCUtility URLEncodeStringFromString:devicePublicKey];
|
|
|
- NSString *proxyServerPath = [NCBrandOptions sharedInstance].pushNotificationServerProxy;
|
|
|
- NSString *proxyServer = [NCBrandOptions sharedInstance].pushNotificationServerProxy;
|
|
|
-
|
|
|
-#ifdef DEBUG
|
|
|
-// proxyServerPath = @"http://127.0.0.1:8088";
|
|
|
-// proxyServer = @"https://10.132.0.37:8443/pushnotifications";
|
|
|
-#endif
|
|
|
-
|
|
|
- OCCommunication *communication = [OCNetworking sharedManager].sharedOCCommunication;
|
|
|
-
|
|
|
- [communication setCredentialsWithUser:tableAccount.user andUserID:tableAccount.userID andPassword:[CCUtility getPassword:account]];
|
|
|
- [communication setUserAgent:[CCUtility getUserAgent]];
|
|
|
- [communication subscribingNextcloudServerPush:url pushTokenHash:pushTokenHash devicePublicKey:devicePublicKey proxyServerPath: proxyServerPath onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *publicKey, NSString *deviceIdentifier, NSString *signature, NSString *redirectedServer) {
|
|
|
-
|
|
|
- deviceIdentifier = [CCUtility URLEncodeStringFromString:deviceIdentifier];
|
|
|
- signature = [CCUtility URLEncodeStringFromString:signature];
|
|
|
- publicKey = [CCUtility URLEncodeStringFromString:publicKey];
|
|
|
-
|
|
|
- [communication subscribingPushProxy:proxyServer pushToken:pushToken deviceIdentifier:deviceIdentifier deviceIdentifierSignature:signature publicKey:publicKey onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
|
|
|
-
|
|
|
- completion(account, deviceIdentifier, signature, publicKey, nil, 0);
|
|
|
-
|
|
|
- } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
|
|
|
-
|
|
|
- NSString *message;
|
|
|
- NSInteger errorCode = response.statusCode;
|
|
|
-
|
|
|
- if (errorCode == 0 || (errorCode >= 200 && errorCode < 300))
|
|
|
- errorCode = error.code;
|
|
|
-
|
|
|
- // Error
|
|
|
- if (errorCode == 503)
|
|
|
- message = NSLocalizedString(@"_server_error_retry_", nil);
|
|
|
- else
|
|
|
- message = [error.userInfo valueForKey:@"NSLocalizedDescription"];
|
|
|
-
|
|
|
- completion(account, nil, nil, nil, message, errorCode);
|
|
|
- }];
|
|
|
-
|
|
|
- } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
|
|
|
-
|
|
|
- NSString *message;
|
|
|
- NSInteger errorCode = response.statusCode;
|
|
|
-
|
|
|
- if (errorCode == 0 || (errorCode >= 200 && errorCode < 300))
|
|
|
- errorCode = error.code;
|
|
|
-
|
|
|
- // Error
|
|
|
- if (errorCode == 503)
|
|
|
- message = NSLocalizedString(@"_server_error_retry_", nil);
|
|
|
- else
|
|
|
- message = [error.userInfo valueForKey:@"NSLocalizedDescription"];
|
|
|
-
|
|
|
- completion(account, nil, nil, nil, message, errorCode);
|
|
|
- }];
|
|
|
-}
|
|
|
-
|
|
|
-- (void)unsubscribingPushNotificationWithAccount:(NSString *)account url:(NSString *)url deviceIdentifier:(NSString *)deviceIdentifier deviceIdentifierSignature:(NSString *)deviceIdentifierSignature publicKey:(NSString *)publicKey completion:(void (^)(NSString *account ,NSString *message, NSInteger errorCode))completion {
|
|
|
-
|
|
|
- tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
|
|
|
- if (tableAccount == nil) {
|
|
|
- completion(account, NSLocalizedString(@"_error_user_not_available_", nil), k_CCErrorUserNotAvailble);
|
|
|
- } else if ([CCUtility getPassword:account].length == 0) {
|
|
|
- completion(account, NSLocalizedString(@"_bad_username_password_", nil), kOCErrorServerUnauthorized);
|
|
|
- } else if ([CCUtility getCertificateError:account]) {
|
|
|
- completion(account, NSLocalizedString(@"_ssl_certificate_untrusted_", nil), NSURLErrorServerCertificateUntrusted);
|
|
|
- }
|
|
|
-
|
|
|
- NSString *proxyServer = [NCBrandOptions sharedInstance].pushNotificationServerProxy;
|
|
|
-
|
|
|
-#ifdef DEBUG
|
|
|
-// proxyServer = @"https://10.132.0.37:8443/pushnotifications";
|
|
|
-#endif
|
|
|
-
|
|
|
- OCCommunication *communication = [OCNetworking sharedManager].sharedOCCommunication;
|
|
|
-
|
|
|
- [communication setCredentialsWithUser:tableAccount.user andUserID:tableAccount.userID andPassword:[CCUtility getPassword:account]];
|
|
|
- [communication setUserAgent:[CCUtility getUserAgent]];
|
|
|
- [communication unsubscribingNextcloudServerPush:url onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
|
|
|
-
|
|
|
- [communication unsubscribingPushProxy:proxyServer deviceIdentifier:deviceIdentifier deviceIdentifierSignature:deviceIdentifierSignature publicKey:publicKey onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
|
|
|
-
|
|
|
- completion(account, nil, 0);
|
|
|
-
|
|
|
- } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
|
|
|
-
|
|
|
- NSString *message;
|
|
|
- NSInteger errorCode = response.statusCode;
|
|
|
-
|
|
|
- if (errorCode == 0 || (errorCode >= 200 && errorCode < 300))
|
|
|
- errorCode = error.code;
|
|
|
-
|
|
|
- // Error
|
|
|
- if (errorCode == 503)
|
|
|
- message = NSLocalizedString(@"_server_error_retry_", nil);
|
|
|
- else
|
|
|
- message = [error.userInfo valueForKey:@"NSLocalizedDescription"];
|
|
|
-
|
|
|
- completion(account, message, errorCode);
|
|
|
- }];
|
|
|
-
|
|
|
- } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
|
|
|
-
|
|
|
- NSString *message;
|
|
|
- NSInteger errorCode = response.statusCode;
|
|
|
-
|
|
|
- if (errorCode == 0 || (errorCode >= 200 && errorCode < 300))
|
|
|
- errorCode = error.code;
|
|
|
-
|
|
|
- // Error
|
|
|
- if (errorCode == 503)
|
|
|
- message = NSLocalizedString(@"_server_error_retry_", nil);
|
|
|
- else
|
|
|
- message = [error.userInfo valueForKey:@"NSLocalizedDescription"];
|
|
|
-
|
|
|
- completion(account, message, errorCode);
|
|
|
- }];
|
|
|
-}
|
|
|
-
|
|
|
-- (void)getServerNotification:(NSString *)serverUrl notificationId:(NSInteger)notificationId completion:(void(^)(NSDictionary*jsongParsed, NSString *message, NSInteger errorCode))completion
|
|
|
-{
|
|
|
- NSString *URLString = [NSString stringWithFormat:@"%@/ocs/v2.php/apps/notifications/api/v2/notifications/%ld?format=json", serverUrl, (long)notificationId];
|
|
|
-
|
|
|
- NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:URLString] cachePolicy:0 timeoutInterval:20.0];
|
|
|
- [request addValue:[CCUtility getUserAgent] forHTTPHeaderField:@"User-Agent"];
|
|
|
- [request addValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
|
|
|
-
|
|
|
- NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
|
|
|
- NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
|
|
|
-
|
|
|
- NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) {
|
|
|
-
|
|
|
- if (error) {
|
|
|
-
|
|
|
- NSString *message;
|
|
|
- NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
|
|
|
- NSInteger errorCode = httpResponse.statusCode;
|
|
|
-
|
|
|
- if (errorCode == 0 || (errorCode >= 200 && errorCode < 300))
|
|
|
- errorCode = error.code;
|
|
|
-
|
|
|
- // Error
|
|
|
- if (errorCode == 503)
|
|
|
- message = NSLocalizedString(@"_server_error_retry_", nil);
|
|
|
- else
|
|
|
- message = [error.userInfo valueForKey:@"NSLocalizedDescription"];
|
|
|
-
|
|
|
- completion(nil, message, errorCode);
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
|
|
|
-
|
|
|
- completion(jsongParsed, nil, 0);
|
|
|
- }
|
|
|
- }];
|
|
|
-
|
|
|
- [task resume];
|
|
|
-}
|
|
|
-
|
|
|
-- (void)deletingServerNotification:(NSString *)serverUrl notificationId:(NSInteger)notificationId completion:(void(^)(NSString *message, NSInteger errorCode))completion
|
|
|
-{
|
|
|
-// NSData *authData = [[NSString stringWithFormat:@"%@:%@", tableAccount.user, [CCUtility getPassword:tableAccount.account]] dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
-// NSString *authValue = [NSString stringWithFormat: @"Basic %@",[authData base64EncodedStringWithOptions:0]];
|
|
|
-
|
|
|
- // Delete
|
|
|
- NSString *URLString = [NSString stringWithFormat:@"%@/ocs/v2.php/apps/notifications/api/v2/notifications/%ld", serverUrl, (long)notificationId];
|
|
|
-
|
|
|
- // Delete-all
|
|
|
- if (notificationId == 0) {
|
|
|
- URLString = [NSString stringWithFormat:@"%@/ocs/v2.php/apps/notifications/api/v2/notifications", serverUrl];
|
|
|
- }
|
|
|
-
|
|
|
- NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:URLString] cachePolicy:0 timeoutInterval:20.0];
|
|
|
-// [request setValue:authValue forHTTPHeaderField:@"Authorization"];
|
|
|
- [request addValue:[CCUtility getUserAgent] forHTTPHeaderField:@"User-Agent"];
|
|
|
- [request addValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
|
|
|
- [request setHTTPMethod: @"DELETE"];
|
|
|
-
|
|
|
- NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
|
|
|
- NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
|
|
|
-
|
|
|
- NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) {
|
|
|
-
|
|
|
- if (error) {
|
|
|
-
|
|
|
- NSString *message;
|
|
|
- NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
|
|
|
- NSInteger errorCode = httpResponse.statusCode;
|
|
|
-
|
|
|
- if (errorCode == 0 || (errorCode >= 200 && errorCode < 300))
|
|
|
- errorCode = error.code;
|
|
|
-
|
|
|
- // Error
|
|
|
- if (errorCode == 503)
|
|
|
- message = NSLocalizedString(@"_server_error_retry_", nil);
|
|
|
- else
|
|
|
- message = [error.userInfo valueForKey:@"NSLocalizedDescription"];
|
|
|
-
|
|
|
- completion(message, errorCode);
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- completion(nil, 0);
|
|
|
- }
|
|
|
- }];
|
|
|
-
|
|
|
- [task resume];
|
|
|
-}
|
|
|
-
|
|
|
#pragma --------------------------------------------------------------------------------------------
|
|
|
#pragma mark ===== Third Parts =====
|
|
|
#pragma --------------------------------------------------------------------------------------------
|