marinofaggiana 5 years ago
parent
commit
4a8882897b
2 changed files with 9 additions and 38 deletions
  1. 0 18
      iOSClient/Database/NCManageDatabase.swift
  2. 9 20
      iOSClient/Share/NCShareComments.swift

+ 0 - 18
iOSClient/Database/NCManageDatabase.swift

@@ -1060,24 +1060,6 @@ class NCManageDatabase: NSObject {
         return Array(results.map { tableComments.init(value:$0) })
     }
     
-    @objc func readMarkerComments(account: String, objectId: String) {
-        
-        let realm = try! Realm()
-        
-        realm.beginWrite()
-        
-        let results = realm.objects(tableComments.self).filter("account == %@ AND objectId == %@", account, objectId)
-        for result in results {
-            result.isUnread = false
-        }
-        
-        do {
-            try realm.commitWrite()
-        } catch let error {
-            print("[LOG] Could not write to database: ", error)
-        }
-    }
-    
     //MARK: -
     //MARK: Table Directory
     

+ 9 - 20
iOSClient/Share/NCShareComments.swift

@@ -73,7 +73,14 @@ class NCShareComments: UIViewController, NCShareCommentsCellDelegate {
             }
         }
         
-        reloadData()
+        // Mark comment ad read
+        if metadata != nil && metadata!.commentsUnread {
+            OCNetworking.sharedManager()?.readMarkComments(withAccount: self.appDelegate.activeAccount, fileId: metadata!.fileId, completion: { (account, message, errorCode) in
+                if errorCode == 0 {
+                    NCManageDatabase.sharedInstance.readMarkerMetadata(account: account!, fileId: self.metadata!.fileId)
+                }
+            })
+        }
     }
     
     override func viewWillAppear(_ animated: Bool) {
@@ -84,30 +91,12 @@ class NCShareComments: UIViewController, NCShareCommentsCellDelegate {
     
     @objc func reloadData() {
         
-        var itemsNCComments = [NCComments]()
         guard let metadata = self.metadata else { return }
 
         OCNetworking.sharedManager()?.getCommentsWithAccount(appDelegate.activeAccount, fileId: metadata.fileId, completion: { (account, items, message, errorCode) in
             if errorCode == 0 {
-                var markCommentAsRead = false
-                itemsNCComments = items as! [NCComments]
+                let itemsNCComments = items as! [NCComments]
                 NCManageDatabase.sharedInstance.addComments(itemsNCComments, account: metadata.account, objectId: metadata.fileId)
-                
-                // Mark comment ad read
-                for comment in itemsNCComments {
-                    if comment.isUnread {
-                        markCommentAsRead = true
-                    }
-                }
-                if markCommentAsRead {
-                    OCNetworking.sharedManager()?.readMarkComments(withAccount: self.appDelegate.activeAccount, fileId: metadata.fileId, completion: { (account, message, errorCode) in
-                        if errorCode == 0 {
-                            NCManageDatabase.sharedInstance.readMarkerComments(account: account!, objectId: metadata.fileId)
-                            NCManageDatabase.sharedInstance.readMarkerMetadata(account: account!, fileId: metadata.fileId)
-                        }
-                    })
-                }
-                
                 self.tableView.reloadData()
             } else {
                 self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)