Use more modern Realm @Persisted

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-01-26 20:48:58 +01:00
parent d0ac36faab
commit 176303dcf1
No known key found for this signature in database
GPG key ID: C839200C384636B0
2 changed files with 89 additions and 101 deletions

View file

@ -325,12 +325,12 @@ class NextcloudFilesDatabaseManager : NSObject {
metadata.commentsUnread = file.commentsUnread metadata.commentsUnread = file.commentsUnread
metadata.contentType = file.contentType metadata.contentType = file.contentType
if let date = file.creationDate { if let date = file.creationDate {
metadata.creationDate = date metadata.creationDate = date as Date
} else { } else {
metadata.creationDate = file.date metadata.creationDate = file.date as Date
} }
metadata.dataFingerprint = file.dataFingerprint metadata.dataFingerprint = file.dataFingerprint
metadata.date = file.date metadata.date = file.date as Date
metadata.directory = file.directory metadata.directory = file.directory
metadata.downloadURL = file.downloadURL metadata.downloadURL = file.downloadURL
metadata.e2eEncrypted = file.e2eEncrypted metadata.e2eEncrypted = file.e2eEncrypted
@ -375,9 +375,9 @@ class NextcloudFilesDatabaseManager : NSObject {
metadata.classFile = NKCommon.typeClassFile.document.rawValue metadata.classFile = NKCommon.typeClassFile.document.rawValue
} }
if let date = file.uploadDate { if let date = file.uploadDate {
metadata.uploadDate = date metadata.uploadDate = date as Date
} else { } else {
metadata.uploadDate = file.date metadata.uploadDate = file.date as Date
} }
metadata.urlBase = file.urlBase metadata.urlBase = file.urlBase
metadata.user = file.user metadata.user = file.user

View file

@ -55,74 +55,70 @@ class NextcloudItemMetadataTable: Object {
comparingMetadata.favorite == self.favorite comparingMetadata.favorite == self.favorite
} }
@objc dynamic var account = "" @Persisted(primaryKey: true) var ocId: String
@objc dynamic var assetLocalIdentifier = "" @Persisted var account = ""
@objc dynamic var checksums = "" @Persisted var assetLocalIdentifier = ""
@objc dynamic var chunk: Bool = false @Persisted var checksums = ""
@objc dynamic var classFile = "" @Persisted var chunk: Bool = false
@objc dynamic var commentsUnread: Bool = false @Persisted var classFile = ""
@objc dynamic var contentType = "" @Persisted var commentsUnread: Bool = false
@objc dynamic var creationDate = NSDate() @Persisted var contentType = ""
@objc dynamic var dataFingerprint = "" @Persisted var creationDate = Date()
@objc dynamic var date = NSDate() @Persisted var dataFingerprint = ""
@objc dynamic var directory: Bool = false @Persisted var date = Date()
@objc dynamic var deleteAssetLocalIdentifier: Bool = false @Persisted var directory: Bool = false
@objc dynamic var downloadURL = "" @Persisted var deleteAssetLocalIdentifier: Bool = false
@objc dynamic var e2eEncrypted: Bool = false @Persisted var downloadURL = ""
@objc dynamic var edited: Bool = false @Persisted var e2eEncrypted: Bool = false
@objc dynamic var etag = "" @Persisted var edited: Bool = false
@objc dynamic var etagResource = "" @Persisted var etag = ""
@objc dynamic var favorite: Bool = false @Persisted var etagResource = ""
@objc dynamic var fileId = "" @Persisted var favorite: Bool = false
@objc dynamic var fileName = "" @Persisted var fileId = ""
@objc dynamic var fileNameView = "" @Persisted var fileName = ""
@objc dynamic var hasPreview: Bool = false @Persisted var fileNameView = ""
@objc dynamic var iconName = "" @Persisted var hasPreview: Bool = false
@objc dynamic var iconUrl = "" @Persisted var iconName = ""
@objc dynamic var isExtractFile: Bool = false @Persisted var iconUrl = ""
@objc dynamic var livePhoto: Bool = false @Persisted var isExtractFile: Bool = false
@objc dynamic var mountType = "" @Persisted var livePhoto: Bool = false
@objc dynamic var name = "" // for unifiedSearch is the provider.id @Persisted var mountType = ""
@objc dynamic var note = "" @Persisted var name = "" // for unifiedSearch is the provider.id
@objc dynamic var ocId = "" @Persisted var note = ""
@objc dynamic var ownerId = "" @Persisted var ownerId = ""
@objc dynamic var ownerDisplayName = "" @Persisted var ownerDisplayName = ""
@objc public var lock = false @Persisted var lock = false
@objc public var lockOwner = "" @Persisted var lockOwner = ""
@objc public var lockOwnerEditor = "" @Persisted var lockOwnerEditor = ""
@objc public var lockOwnerType = 0 @Persisted var lockOwnerType = 0
@objc public var lockOwnerDisplayName = "" @Persisted var lockOwnerDisplayName = ""
@objc public var lockTime: Date? @Persisted var lockTime: Date?
@objc public var lockTimeOut: Date? @Persisted var lockTimeOut: Date?
@objc dynamic var path = "" @Persisted var path = ""
@objc dynamic var permissions = "" @Persisted var permissions = ""
@objc dynamic var quotaUsedBytes: Int64 = 0 @Persisted var quotaUsedBytes: Int64 = 0
@objc dynamic var quotaAvailableBytes: Int64 = 0 @Persisted var quotaAvailableBytes: Int64 = 0
@objc dynamic var resourceType = "" @Persisted var resourceType = ""
@objc dynamic var richWorkspace: String? @Persisted var richWorkspace: String?
@objc dynamic var serverUrl = "" // For parent directory!! @Persisted var serverUrl = "" // For parent directory!!
@objc dynamic var session = "" @Persisted var session = ""
@objc dynamic var sessionError = "" @Persisted var sessionError = ""
@objc dynamic var sessionSelector = "" @Persisted var sessionSelector = ""
@objc dynamic var sessionTaskIdentifier: Int = 0 @Persisted var sessionTaskIdentifier: Int = 0
@objc dynamic var sharePermissionsCollaborationServices: Int = 0 @Persisted var sharePermissionsCollaborationServices: Int = 0
let sharePermissionsCloudMesh = List<String>() let sharePermissionsCloudMesh = List<String>()
let shareType = List<Int>() let shareType = List<Int>()
@objc dynamic var size: Int64 = 0 @Persisted var size: Int64 = 0
@objc dynamic var status: Int = 0 @Persisted var status: Int = 0
@objc dynamic var subline: String? @Persisted var subline: String?
@objc dynamic var trashbinFileName = "" @Persisted var trashbinFileName = ""
@objc dynamic var trashbinOriginalLocation = "" @Persisted var trashbinOriginalLocation = ""
@objc dynamic var trashbinDeletionTime = NSDate() @Persisted var trashbinDeletionTime = Date()
@objc dynamic var uploadDate = NSDate() @Persisted var uploadDate = Date()
@objc dynamic var url = "" @Persisted var url = ""
@objc dynamic var urlBase = "" @Persisted var urlBase = ""
@objc dynamic var user = "" @Persisted var user = ""
@objc dynamic var userId = "" @Persisted var userId = ""
override static func primaryKey() -> String {
return "ocId"
}
} }
class NextcloudDirectoryMetadataTable: Object { class NextcloudDirectoryMetadataTable: Object {
@ -133,37 +129,29 @@ class NextcloudDirectoryMetadataTable: Object {
comparingMetadata.permissions == self.permissions comparingMetadata.permissions == self.permissions
} }
@objc dynamic var account = "" @Persisted(primaryKey: true) var ocId: String
@objc dynamic var colorFolder: String? @Persisted var account = ""
@objc dynamic var e2eEncrypted: Bool = false @Persisted var colorFolder: String?
@objc dynamic var etag = "" @Persisted var e2eEncrypted: Bool = false
@objc dynamic var favorite: Bool = false @Persisted var etag = ""
@objc dynamic var fileId = "" @Persisted var favorite: Bool = false
@objc dynamic var ocId = "" @Persisted var fileId = ""
@objc dynamic var offline: Bool = false @Persisted var offline: Bool = false
@objc dynamic var permissions = "" @Persisted var permissions = ""
@objc dynamic var richWorkspace: String? @Persisted var richWorkspace: String?
@objc dynamic var serverUrl = "" @Persisted var serverUrl = ""
@objc dynamic var parentDirectoryServerUrl = "" @Persisted var parentDirectoryServerUrl = ""
override static func primaryKey() -> String {
return "ocId"
}
} }
class NextcloudLocalFileMetadataTable: Object { class NextcloudLocalFileMetadataTable: Object {
@objc dynamic var account = "" @Persisted(primaryKey: true) var ocId: String
@objc dynamic var etag = "" @Persisted var account = ""
@objc dynamic var exifDate: NSDate? @Persisted var etag = ""
@objc dynamic var exifLatitude = "" @Persisted var exifDate: Date?
@objc dynamic var exifLongitude = "" @Persisted var exifLatitude = ""
@objc dynamic var exifLensModel: String? @Persisted var exifLongitude = ""
@objc dynamic var favorite: Bool = false @Persisted var exifLensModel: String?
@objc dynamic var fileName = "" @Persisted var favorite: Bool = false
@objc dynamic var ocId = "" @Persisted var fileName = ""
@objc dynamic var offline: Bool = false @Persisted var offline: Bool = false
override static func primaryKey() -> String {
return "ocId"
}
} }