marinofaggiana 5 роки тому
батько
коміт
2909836039

+ 1 - 0
File Provider Extension/FileProviderExtension-Bridging-Header.h

@@ -35,3 +35,4 @@
 #import "OCExternalSites.h"
 #import "OCSharedDto.h"
 #import "HCFeatures.h"
+#import "NCComments.h"

+ 1 - 0
Share/Share-Bridging-Header.h

@@ -11,3 +11,4 @@
 #import "OCExternalSites.h"
 #import "OCSharedDto.h"
 #import "HCFeatures.h"
+#import "NCComments.h"

+ 1 - 1
iOSClient/CCGlobal.h

@@ -81,7 +81,7 @@
 
 // Database Realm
 #define k_databaseDefault                               @"nextcloud.realm"
-#define k_databaseSchemaVersion                         61
+#define k_databaseSchemaVersion                         62
 
 // Intro selector
 #define k_intro_login                                   0

+ 20 - 0
iOSClient/Database/NCDatabase.swift

@@ -205,6 +205,26 @@ class tableCertificates: Object {
     @objc dynamic var certificateLocation = ""
 }
 
+class tableComments: Object {
+    
+    @objc dynamic var account = ""
+    @objc dynamic var actorDisplayName = ""
+    @objc dynamic var actorId = ""
+    @objc dynamic var actorType = ""
+    @objc dynamic var creationDateTime: NSDate? = nil
+    @objc dynamic var fileID = ""
+    @objc dynamic var isUnread: Bool = false
+    @objc dynamic var message = ""
+    @objc dynamic var messageID: Double = 0
+    @objc dynamic var objectId: Double = 0
+    @objc dynamic var objectType = ""
+    @objc dynamic var verb = ""
+    
+    override static func primaryKey() -> String {
+        return "messageID"
+    }
+}
+
 class tableDirectory: Object {
     
     @objc dynamic var account = ""

+ 46 - 0
iOSClient/Database/NCManageDatabase.swift

@@ -121,6 +121,7 @@ class NCManageDatabase: NSObject {
         self.clearTable(tableActivityPreview.self, account: account)
         self.clearTable(tableActivitySubjectRich.self, account: account)
         self.clearTable(tableCapabilities.self, account: account)
+        self.clearTable(tableComments.self, account: account)
         self.clearTable(tableDirectory.self, account: account)
         self.clearTable(tableE2eEncryption.self, account: account)
         self.clearTable(tableE2eEncryptionLock.self, account: account)
@@ -984,6 +985,51 @@ class NCManageDatabase: NSObject {
     
         return Array(results.map { "\(localCertificatesFolder)/\($0.certificateLocation)" })
     }
+   
+    //MARK: -
+    //MARK: Table Comments
+    
+    @objc func addComments(_ listOfComments: [NCComments], account: String, fileID: String) {
+        
+        let realm = try! Realm()
+        
+        do {
+            try realm.write {
+                
+                for comment in listOfComments {
+                    
+                    let addObject = tableComments()
+                    
+                    addObject.account = account
+                    addObject.actorDisplayName = comment.actorDisplayName
+                    addObject.actorId = comment.actorId
+                    addObject.actorType = comment.actorType
+                    addObject.creationDateTime = comment.creationDateTime as NSDate
+                    addObject.fileID = fileID
+                    addObject.isUnread = comment.isUnread
+                    addObject.message = comment.message
+                    addObject.messageID = comment.messageID
+                    addObject.objectId = comment.objectId
+                    addObject.objectType = comment.objectType
+                    addObject.verb = comment.verb
+                    
+                    realm.add(addObject, update: .all)
+                }
+            }
+        } catch let error {
+            print("[LOG] Could not write to database: ", error)
+        }
+    }
+    
+    @objc func getComments(account: String, fileID: String) -> [tableComments]? {
+        
+        let realm = try! Realm()
+        realm.refresh()
+        
+        let results = realm.objects(tableComments.self).filter("account == %@ AND fileID == %@", account, fileID).sorted(byKeyPath: "creationDateTime", ascending: true)
+        
+        return Array(results.map { tableComments.init(value:$0) })
+    }
     
     //MARK: -
     //MARK: Table Directory

+ 6 - 6
iOSClient/Library/OCCommunicationLib/NCComments.h

@@ -24,15 +24,15 @@
 
 @interface NCComments : NSObject
 
-@property double messageID;
-@property (nonatomic, strong) NSString *verb;
-@property (nonatomic, strong) NSString *actorType;
+@property (nonatomic, strong) NSString *actorDisplayName;
 @property (nonatomic, strong) NSString *actorId;
+@property (nonatomic, strong) NSString *actorType;
 @property (nonatomic, strong) NSDate *creationDateTime;
-@property (nonatomic, strong) NSString *objectType;
-@property double objectId;
-@property (nonatomic, strong) NSString *actorDisplayName;
 @property BOOL isUnread;
 @property (nonatomic, strong) NSString *message;
+@property double messageID;
+@property double objectId;
+@property (nonatomic, strong) NSString *objectType;
+@property (nonatomic, strong) NSString *verb;
 
 @end

+ 1 - 0
iOSClient/Nextcloud-Bridging-Header.h

@@ -26,3 +26,4 @@
 #import "NCNetworkingEndToEnd.h"
 #import "NCRichDocumentTemplate.h"
 #import "HCFeatures.h"
+#import "NCComments.h"