Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@
AFCE353527E4ED5900FEA6C2 /* DateFormatter+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353427E4ED5900FEA6C2 /* DateFormatter+Extension.swift */; };
AFCE353727E4ED7B00FEA6C2 /* NCShareCells.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353627E4ED7B00FEA6C2 /* NCShareCells.swift */; };
AFCE353927E5DE0500FEA6C2 /* Shareable.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353827E5DE0400FEA6C2 /* Shareable.swift */; };
AFCE353927E5DE0500FEA6C2 /* NCShare+Helper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353827E5DE0400FEA6C2 /* NCShare+Helper.swift */; };
B5C980182DACD51C0041B146 /* NCMediaCommandView.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5C980172DACD51C0041B146 /* NCMediaCommandView.xib */; };
B5C9801A2DACD56C0041B146 /* NCMedia+Menu.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C980192DACD56C0041B146 /* NCMedia+Menu.swift */; };
C04E2F232A17BB4D001BAD85 /* FilesIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04E2F222A17BB4D001BAD85 /* FilesIntegrationTests.swift */; };
D575039F27146F93008DC9DC /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A0D1342591FBC5008F8A13 /* String+Extension.swift */; };
D5B6AA7827200C7200D49C24 /* NCActivityTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */; };
F310B1EF2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = F310B1EE2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift */; };
Expand Down Expand Up @@ -1330,6 +1334,9 @@
AFCE353427E4ED5900FEA6C2 /* DateFormatter+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DateFormatter+Extension.swift"; sourceTree = "<group>"; };
AFCE353627E4ED7B00FEA6C2 /* NCShareCells.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCShareCells.swift; sourceTree = "<group>"; };
AFCE353827E5DE0400FEA6C2 /* Shareable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shareable.swift; sourceTree = "<group>"; };
AFCE353827E5DE0400FEA6C2 /* NCShare+Helper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCShare+Helper.swift"; sourceTree = "<group>"; };
B5C980172DACD51C0041B146 /* NCMediaCommandView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NCMediaCommandView.xib; sourceTree = "<group>"; };
B5C980192DACD56C0041B146 /* NCMedia+Menu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCMedia+Menu.swift"; sourceTree = "<group>"; };
C0046CDA2A17B98400D87C9D /* NextcloudUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NextcloudUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
C04E2F202A17BB4D001BAD85 /* NextcloudIntegrationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NextcloudIntegrationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCActivityTableViewCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2076,6 +2083,7 @@
371B5A2F23D0B04B00FAFAE9 /* Menu */ = {
isa = PBXGroup;
children = (
B5C980192DACD56C0041B146 /* NCMedia+Menu.swift */,
3704EB2923D5A58400455C5B /* NCMenu.storyboard */,
371B5A2D23D0B04500FAFAE9 /* NCMenu.swift */,
AF68326927BE65A90010BF0B /* NCMenuAction.swift */,
Expand Down Expand Up @@ -3219,6 +3227,7 @@
F7EC9CB921185F2000F1C5CE /* Media */ = {
isa = PBXGroup;
children = (
B5C980172DACD51C0041B146 /* NCMediaCommandView.xib */,
F720B5B72507B9A5008C94E5 /* Cell */,
F7501C302212E57400FB1415 /* NCMedia.storyboard */,
F7501C312212E57400FB1415 /* NCMedia.swift */,
Expand Down Expand Up @@ -3991,6 +4000,7 @@
F74C0437253F1CDC009762AB /* NCShares.storyboard in Resources */,
F7F4F10C27ECDBDB008676F9 /* Inconsolata-Regular.ttf in Resources */,
F7B8B83025681C3400967775 /* GoogleService-Info.plist in Resources */,
B5C980182DACD51C0041B146 /* NCMediaCommandView.xib in Resources */,
F7381EE5218218C9000B1560 /* NCOffline.storyboard in Resources */,
F768822D2C0DD1E7001CF441 /* Acknowledgements.rtf in Resources */,
F7E0CDCF265CE8610044854E /* NCUserStatus.storyboard in Resources */,
Expand Down Expand Up @@ -4854,6 +4864,7 @@
F758B45E212C569D00515F55 /* NCScanCell.swift in Sources */,
F78B87E72B62527100C65ADC /* NCMediaDataSource.swift in Sources */,
F76882272C0DD1E7001CF441 /* NCManageE2EEView.swift in Sources */,
B5C9801A2DACD56C0041B146 /* NCMedia+Menu.swift in Sources */,
F7864ACC2A78FE73004870E0 /* NCManageDatabase+LocalFile.swift in Sources */,
F7327E302B73A86700A462C7 /* NCNetworking+WebDAV.swift in Sources */,
F79FFB262A97C24A0055EEA4 /* NCNetworkingE2EEMarkFolder.swift in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions iOSClient/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
if isUiTestingEnabled {
NCAccount().deleteAllAccounts()
}
UINavigationBar.appearance().tintColor = NCBrandColor.shared.customer
UIToolbar.appearance().tintColor = NCBrandColor.shared.customer

let utilityFileSystem = NCUtilityFileSystem()
let utility = NCUtility()
Expand Down
161 changes: 151 additions & 10 deletions iOSClient/Data/NCManageDatabase+Metadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,23 @@ extension tableMetadata {
return true
}

var isPrintable: Bool {
if isDocumentViewableOnly {
return false
}
if ["application/pdf", "com.adobe.pdf"].contains(contentType) || contentType.hasPrefix("text/") || classFile == NKCommon.TypeClassFile.image.rawValue {
return true
}
return false
}

var isSavebleInCameraRoll: Bool {
return (classFile == NKCommon.TypeClassFile.image.rawValue && contentType != "image/svg+xml") || classFile == NKCommon.TypeClassFile.video.rawValue
}

/*

var isDocumentViewableOnly: Bool {
sharePermissionsCollaborationServices == NCPermissions().permissionReadShare && classFile == NKCommon.TypeClassFile.document.rawValue
}
*/

var isAudioOrVideo: Bool {
return classFile == NKCommon.TypeClassFile.audio.rawValue || classFile == NKCommon.TypeClassFile.video.rawValue
Expand All @@ -201,15 +209,15 @@ extension tableMetadata {
}

var isCopyableInPasteboard: Bool {
!directory
!isDocumentViewableOnly && !directory
}

var isCopyableMovable: Bool {
!isDirectoryE2EE && !e2eEncrypted
!isDocumentViewableOnly && !isDirectoryE2EE && !e2eEncrypted
}

var isModifiableWithQuickLook: Bool {
if directory || isDirectoryE2EE {
if directory || isDocumentViewableOnly || isDirectoryE2EE {
return false
}
return isPDF || isImage
Expand All @@ -223,11 +231,12 @@ extension tableMetadata {
}

var canSetAsAvailableOffline: Bool {
return session.isEmpty && !isDirectoryE2EE && !e2eEncrypted
// return session.isEmpty && !isDirectoryE2EE && !e2eEncrypted
return session.isEmpty && !isDocumentViewableOnly
}

var canShare: Bool {
return session.isEmpty && !directory && !NCBrandOptions.shared.disable_openin_file
return session.isEmpty && !isDocumentViewableOnly && !directory && !NCBrandOptions.shared.disable_openin_file
}

var canSetDirectoryAsE2EE: Bool {
Expand All @@ -238,6 +247,32 @@ extension tableMetadata {
return !isDirectoryE2EE && directory && size == 0 && e2eEncrypted && NCKeychain().isEndToEndEnabled(account: account)
}

var canOpenExternalEditor: Bool {
if isDocumentViewableOnly {
return false
}
let utility = NCUtility()
let editors = utility.editorsDirectEditing(account: account, contentType: contentType)
let isRichDocument = utility.isTypeFileRichDocument(self)
return classFile == NKCommon.TypeClassFile.document.rawValue && editors.contains(NCGlobal.shared.editorText) && ((editors.contains(NCGlobal.shared.editorOnlyoffice) || isRichDocument))
}

var isWaitingTransfer: Bool {
status == NCGlobal.shared.metadataStatusWaitDownload || status == NCGlobal.shared.metadataStatusWaitUpload || status == NCGlobal.shared.metadataStatusUploadError
}

var isInTransfer: Bool {
status == NCGlobal.shared.metadataStatusDownloading || status == NCGlobal.shared.metadataStatusUploading
}

var isTransferInForeground: Bool {
(status > 0 && (chunk > 0 || e2eEncrypted))
}

var isDownloadUpload: Bool {
status == NCGlobal.shared.metadataStatusDownloading || status == NCGlobal.shared.metadataStatusUploading
}

var isDownload: Bool {
status == NCGlobal.shared.metadataStatusWaitDownload || status == NCGlobal.shared.metadataStatusDownloading
}
Expand Down Expand Up @@ -328,7 +363,7 @@ extension tableMetadata {
if !NCCapabilities.shared.getCapabilities(account: account).capabilityFileSharingApiEnabled || (NCCapabilities.shared.getCapabilities(account: account).capabilityE2EEEnabled && isDirectoryE2EE) {
return false
}
return true
return !e2eEncrypted
}
}

Expand Down Expand Up @@ -467,6 +502,42 @@ extension NCManageDatabase {
completion(metadataFolder, metadatas)
}

func convertFilesToMetadatas(_ files: [NKFile], useMetadataFolder: Bool, completion: @escaping (_ metadataFolder: tableMetadata, _ metadatasFolder: [tableMetadata], _ metadatas: [tableMetadata]) -> Void) {

var counter: Int = 0
var isDirectoryE2EE: Bool = false
let listServerUrl = ThreadSafeDictionary<String, Bool>()

var metadataFolder = tableMetadata()
var metadataFolders: [tableMetadata] = []
var metadatas: [tableMetadata] = []

for file in files {

if let key = listServerUrl[file.serverUrl] {
isDirectoryE2EE = key
} else {
isDirectoryE2EE = NCUtilityFileSystem().isDirectoryE2EE(file: file)
listServerUrl[file.serverUrl] = isDirectoryE2EE
}

let metadata = convertFileToMetadata(file, isDirectoryE2EE: isDirectoryE2EE)

if counter == 0 && useMetadataFolder {
metadataFolder = tableMetadata.init(value: metadata)
} else {
metadatas.append(metadata)
if metadata.directory {
metadataFolders.append(metadata)
}
}

counter += 1
}

completion(metadataFolder, metadataFolders, metadatas)
}

func getMetadataDirectoryFrom(files: [NKFile]) -> tableMetadata? {
guard let file = files.first else { return nil }
let isDirectoryE2EE = NCUtilityFileSystem().isDirectoryE2EE(file: file)
Expand Down Expand Up @@ -1168,7 +1239,7 @@ extension NCManageDatabase {
return listIdentifierRank
}

func clearMetadatasUpload(account: String) {
@objc func clearMetadatasUpload(account: String) {
do {
let realm = try Realm()
try realm.write {
Expand Down Expand Up @@ -1260,4 +1331,74 @@ extension NCManageDatabase {
let concatenatedEtags = metadatas.map { $0.etag }.joined(separator: "-")
return sha256Hash(concatenatedEtags)
}

func getMediaMetadatas(predicate: NSPredicate) -> ThreadSafeArray<tableMetadata>? {

do {
let realm = try Realm()
let results = realm.objects(tableMetadata.self).filter(predicate).sorted(byKeyPath: "date", ascending: false)
return ThreadSafeArray(results.map { tableMetadata.init(value: $0) })
} catch let error as NSError {
NextcloudKit.shared.nkCommonInstance.writeLog("Could not access database: \(error)")
}

return nil
}

func getMediaMetadatas(predicate: NSPredicate, sorted: String? = nil, ascending: Bool = false) -> ThreadSafeArray<tableMetadata>? {

do {
let realm = try Realm()
if let sorted {
var results: [tableMetadata] = []
switch NCKeychain().mediaSortDate {
case "date":
results = realm.objects(tableMetadata.self).filter(predicate).sorted { ($0.date as Date) > ($1.date as Date) }
case "creationDate":
results = realm.objects(tableMetadata.self).filter(predicate).sorted { ($0.creationDate as Date) > ($1.creationDate as Date) }
case "uploadDate":
results = realm.objects(tableMetadata.self).filter(predicate).sorted { ($0.uploadDate as Date) > ($1.uploadDate as Date) }
default:
let results = realm.objects(tableMetadata.self).filter(predicate)
return ThreadSafeArray(results.map { tableMetadata.init(value: $0) })
}
return ThreadSafeArray(results.map { tableMetadata.init(value: $0) })
} else {
let results = realm.objects(tableMetadata.self).filter(predicate)
return ThreadSafeArray(results.map { tableMetadata.init(value: $0) })
}
} catch let error as NSError {
NextcloudKit.shared.nkCommonInstance.writeLog("Could not access database: \(error)")
}
return nil
}

func getAdvancedMetadatas(predicate: NSPredicate, page: Int = 0, limit: Int = 0, sorted: String, ascending: Bool) -> [tableMetadata] {

var metadatas: [tableMetadata] = []

do {
let realm = try Realm()
realm.refresh()
let results = realm.objects(tableMetadata.self).filter(predicate).sorted(byKeyPath: sorted, ascending: ascending)
if !results.isEmpty {
if page == 0 || limit == 0 {
return Array(results.map { tableMetadata.init(value: $0) })
} else {
let nFrom = (page - 1) * limit
let nTo = nFrom + (limit - 1)
for n in nFrom...nTo {
if n == results.count {
break
}
metadatas.append(tableMetadata.init(value: results[n]))
}
}
}
} catch let error as NSError {
NextcloudKit.shared.nkCommonInstance.writeLog("Could not access database: \(error)")
}

return metadatas
}
}
Loading