|
@@ -84,14 +84,30 @@ class CCNotification: UITableViewController, OCNetworkingDelegate {
|
|
|
|
|
|
tableView.setEditing(false, animated: true)
|
|
|
|
|
|
- let metadataNet = CCMetadataNet.init(account: self.appDelegate.activeAccount)!
|
|
|
-
|
|
|
- metadataNet.action = actionSetNotificationServer
|
|
|
- metadataNet.optionString = "\(notification.idNotification)"
|
|
|
- metadataNet.optionAny = "DELETE"
|
|
|
- metadataNet.serverUrl = "\(self.appDelegate.activeUrl!)/\(k_url_acces_remote_notification_api)/\(metadataNet.optionString!)"
|
|
|
-
|
|
|
- self.appDelegate.addNetworkingOperationQueue(self.appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
|
|
|
+ let ocNetworking = OCnetworking.init(delegate: self, metadataNet: nil, withUser: nil, withUserID: nil, withPassword: nil, withUrl: nil)
|
|
|
+ ocNetworking?.setNotificationServer(self.appDelegate.activeAccount, serverUrl: "\(self.appDelegate.activeUrl!)/\(k_url_acces_remote_notification_api)/\(notification.idNotification)", type: "DELETE", completion: { (account, message, errorCode) in
|
|
|
+
|
|
|
+ if (errorCode == 0 && account! == self.appDelegate.activeAccount) {
|
|
|
+
|
|
|
+ let listOfNotifications = self.appDelegate.listOfNotifications as NSArray as! [OCNotifications]
|
|
|
+
|
|
|
+ if let index = listOfNotifications.index(where: {$0.idNotification == notification.idNotification}) {
|
|
|
+ self.appDelegate.listOfNotifications.removeObject(at: index)
|
|
|
+ }
|
|
|
+
|
|
|
+ self.reloadDatasource()
|
|
|
+
|
|
|
+ if self.appDelegate.listOfNotifications.count == 0 {
|
|
|
+ self.viewClose()
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if (errorCode != 0) {
|
|
|
+ self.appDelegate.messageNotification("_error_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
remove.backgroundColor = .red
|
|
@@ -113,14 +129,30 @@ class CCNotification: UITableViewController, OCNetworkingDelegate {
|
|
|
|
|
|
tableView.setEditing(false, animated: true)
|
|
|
|
|
|
- let metadataNet = CCMetadataNet.init(account: self.appDelegate.activeAccount)!
|
|
|
-
|
|
|
- metadataNet.action = actionSetNotificationServer
|
|
|
- metadataNet.optionString = "\(notification.idNotification)"
|
|
|
- metadataNet.serverUrl = (actionNotification as! OCNotificationsAction).link
|
|
|
- metadataNet.optionAny = (actionNotification as! OCNotificationsAction).type
|
|
|
-
|
|
|
- self.appDelegate.addNetworkingOperationQueue(self.appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
|
|
|
+ let ocNetworking = OCnetworking.init(delegate: self, metadataNet: nil, withUser: nil, withUserID: nil, withPassword: nil, withUrl: nil)
|
|
|
+ ocNetworking?.setNotificationServer(self.appDelegate.activeAccount, serverUrl: (actionNotification as! OCNotificationsAction).link, type: (actionNotification as! OCNotificationsAction).type, completion: { (account, message, errorCode) in
|
|
|
+
|
|
|
+ if (errorCode == 0 && account! == self.appDelegate.activeAccount) {
|
|
|
+
|
|
|
+ let listOfNotifications = self.appDelegate.listOfNotifications as NSArray as! [OCNotifications]
|
|
|
+
|
|
|
+ if let index = listOfNotifications.index(where: {$0.idNotification == notification.idNotification}) {
|
|
|
+ self.appDelegate.listOfNotifications.removeObject(at: index)
|
|
|
+ }
|
|
|
+
|
|
|
+ self.reloadDatasource()
|
|
|
+
|
|
|
+ if self.appDelegate.listOfNotifications.count == 0 {
|
|
|
+ self.viewClose()
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if (errorCode != 0) {
|
|
|
+ self.appDelegate.messageNotification("_error_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -190,35 +222,6 @@ class CCNotification: UITableViewController, OCNetworkingDelegate {
|
|
|
tableView.deselectRow(at: indexPath, animated: true)
|
|
|
}
|
|
|
|
|
|
- // MARK: - Networking delegate
|
|
|
-
|
|
|
- func setNotificationServerSuccessFailure(_ metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
|
|
|
-
|
|
|
- // Check Active Account
|
|
|
- if (metadataNet.account != appDelegate.activeAccount) {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- if (errorCode == 0) {
|
|
|
-
|
|
|
- let listOfNotifications = appDelegate.listOfNotifications as NSArray as! [OCNotifications]
|
|
|
-
|
|
|
- if let index = listOfNotifications.index(where: {$0.idNotification == Int(metadataNet.optionString)}) {
|
|
|
- appDelegate.listOfNotifications.removeObject(at: index)
|
|
|
- }
|
|
|
-
|
|
|
- reloadDatasource()
|
|
|
-
|
|
|
- if appDelegate.listOfNotifications.count == 0 {
|
|
|
- viewClose()
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- appDelegate.messageNotification("_error_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
// MARK: - Get Image from url
|
|
|
|
|
|
func getDataFromUrl(url: URL, completion: @escaping (_ data: Data?, _ response: URLResponse?, _ error: Error?) -> Void) {
|