Эх сурвалжийг харах

Capabilities : isNotificationServerEnabled (ADD) + Fix

Marino Faggiana 7 жил өмнө
parent
commit
12a29edd7d

+ 5 - 0
iOSClient/Library/OCCommunicationLib/OCCapabilities.h

@@ -52,6 +52,11 @@
 // External sites
 @property (nonatomic) BOOL isExternalSitesServerEnabled;
 
+// Notification
+@property (nonatomic) BOOL isNotificationServerEnabled;
+@property (nonatomic, strong) NSString *notificationOcsEndpoints;
+@property (nonatomic, strong) NSString *notificationPush;
+
 /*FILES*/
 @property (nonatomic) BOOL isFileBigFileChunkingEnabled;
 @property (nonatomic) BOOL isFileUndeleteEnabled;

+ 9 - 0
iOSClient/Library/OCCommunicationLib/OCCommunication.m

@@ -1391,6 +1391,15 @@
                             capabilities.isExternalSitesServerEnabled = YES;
                 }
                 
+                // NOTIFICATION
+                NSDictionary *notificationDic = [capabilitiesDict valueForKey:@"notifications"];
+                if (notificationDic) {
+                    capabilities.isNotificationServerEnabled = YES;
+                    NSArray *ocsendpointsArray = [notificationDic valueForKey:@"ocs-endpoints"];
+                    capabilities.notificationOcsEndpoints = [ocsendpointsArray componentsJoinedByString:@","];
+                    NSArray *pushArray = [notificationDic valueForKey:@"push"];
+                    capabilities.notificationPush = [pushArray componentsJoinedByString:@","];
+                }
                 //FILES
             
                 NSDictionary *files = [capabilitiesDict valueForKey:@"files"];

+ 21 - 19
iOSClient/Networking/NCService.swift

@@ -43,7 +43,6 @@ class NCService: NSObject, OCNetworkingDelegate {
         
         self.requestUserProfile()
         self.requestServerCapabilities()
-        self.requestNotificationServer()
         self.requestActivityServer()
     }
 
@@ -78,20 +77,6 @@ class NCService: NSObject, OCNetworkingDelegate {
         appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
     }
     
-    @objc func requestNotificationServer() {
-        
-        if (appDelegate.activeAccount == nil || appDelegate.activeAccount.count == 0 || appDelegate.maintenanceMode == true) {
-            return
-        }
-        
-        guard let metadataNet = CCMetadataNet.init(account: appDelegate.activeAccount) else {
-            return
-        }
-        
-        metadataNet.action = actionGetNotificationServer
-        appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
-    }
-    
     @objc func requestActivityServer() {
         
         if (appDelegate.activeAccount == nil || appDelegate.activeAccount.count == 0 || appDelegate.maintenanceMode == true) {
@@ -139,11 +124,11 @@ class NCService: NSObject, OCNetworkingDelegate {
             
             // ------ THEMING -----------------------------------------------------------------------
             
-            // Download Theming Background & Change Theming color
-            DispatchQueue.global().async {
+            if (NCBrandOptions.sharedInstance.use_themingBackground) {
+                
+                // Download Theming Background & Change Theming color
+                DispatchQueue.global().async {
                 
-                if (NCBrandOptions.sharedInstance.use_themingBackground) {
-                    
                     let address = capabilities!.themingBackground!.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)!
                     guard let imageData = try? Data(contentsOf: URL(string: address)!) else {
                         return
@@ -174,6 +159,23 @@ class NCService: NSObject, OCNetworkingDelegate {
             
             // ------ GET OTHER SERVICE -------------------------------------------------------------
 
+            // Read Notification
+            if (capabilities!.isNotificationServerEnabled) {
+                
+                metadataNet.action = actionGetNotificationServer
+                appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
+                
+            } else {
+                
+                // Remove all Notification
+                self.appDelegate.listOfNotifications.removeAllObjects()
+                NotificationCenter.default.post(name: NSNotification.Name(rawValue: "notificationReloadData"), object: nil)
+                // Update Main NavigationBar
+                if (self.appDelegate.activeMain.isSelectedMode == false) {
+                    self.appDelegate.activeMain.setUINavigationBarDefault()
+                }
+            }
+            
             // Read External Sites
             if (capabilities!.isExternalSitesServerEnabled) {
                 

+ 8 - 4
iOSClient/Notification/CCNotification.swift

@@ -46,9 +46,9 @@ class CCNotification: UITableViewController, OCNetworkingDelegate {
         self.tableView.estimatedRowHeight = 50.0
 
         // Register to receive notification reload data
-        NotificationCenter.default.addObserver(self, selector: #selector(self.tableView.reloadData), name: Notification.Name("notificationReloadData"), object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(self.reloadDatasource), name: Notification.Name("notificationReloadData"), object: nil)
 
-        self.tableView.reloadData()
+        reloadDatasource()
     }
     
     override func didReceiveMemoryWarning() {
@@ -65,6 +65,10 @@ class CCNotification: UITableViewController, OCNetworkingDelegate {
     
     // MARK: - Table
 
+    @objc func reloadDatasource() {
+        self.tableView.reloadData()
+    }
+    
     override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
         return true
     }
@@ -203,7 +207,7 @@ class CCNotification: UITableViewController, OCNetworkingDelegate {
                 appDelegate.listOfNotifications.removeObject(at: index)
             }
             
-            self.tableView.reloadData()
+            reloadDatasource()
             
             if appDelegate.listOfNotifications.count == 0 {
                 viewClose()
@@ -237,7 +241,7 @@ class CCNotification: UITableViewController, OCNetworkingDelegate {
                     let pathFileName = (self.appDelegate.directoryUser) + "/" + fileName
                     try data.write(to: URL(fileURLWithPath: pathFileName), options: .atomic)
                     
-                    self.tableView.reloadData()
+                    self.reloadDatasource()
                 } catch {
                     print(error)
                 }