Skip to content

Commit

Permalink
e2ee
Browse files Browse the repository at this point in the history
Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
  • Loading branch information
marinofaggiana committed Oct 3, 2024
1 parent e91ee9e commit 0922f12
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 30 deletions.
4 changes: 1 addition & 3 deletions iOSClient/Extensions/UIAlertController+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ extension UIAlertController {
preferredStyle: .alert)
if canDeleteServer {
alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .destructive) { (_: UIAlertAction) in
for metadata in selectedMetadatas {
NCNetworking.shared.deleteMetadata(metadata)
}
NCNetworking.shared.deleteMetadatas(selectedMetadatas, sceneIdentifier: sceneIdentifier)
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSource)
completion(false)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,8 @@ extension NCCollectionViewCommon: NCCollectionViewCommonSelectTabBarDelegate {
let canDeleteServer = metadatas.allSatisfy { !$0.lock }

if canDeleteServer {
let copyMetadatas = metadatas
alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .destructive) { _ in
for metadata in copyMetadatas {
NCNetworking.shared.deleteMetadata(metadata)
}
NCNetworking.shared.deleteMetadatas(metadatas, sceneIdentifier: self.controller?.sceneIdentifier)
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSource)
self.setEditMode(false)
})
Expand Down
5 changes: 4 additions & 1 deletion iOSClient/Media/NCMedia+Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ extension NCMedia: NCMediaSelectTabBarDelegate {
let ocIds = self.fileSelect.map { $0 }
var alertStyle = UIAlertController.Style.actionSheet
var indexPaths: [IndexPath] = []
var metadatas: [tableMetadata] = []

if UIDevice.current.userInterfaceIdiom == .pad { alertStyle = .alert }

Expand All @@ -203,10 +204,12 @@ extension NCMedia: NCMediaSelectTabBarDelegate {

for ocId in ocIds {
if let metadata = self.database.getMetadataFromOcId(ocId) {
NCNetworking.shared.deleteMetadata(metadata)
metadatas.append(metadata)
}
}

NCNetworking.shared.deleteMetadatas(metadatas, sceneIdentifier: self.controller?.sceneIdentifier)

for index in indices {
let indexPath = IndexPath(row: index, section: 0)
if let cell = self.collectionView.cellForItem(at: indexPath) as? NCMediaCell,
Expand Down
2 changes: 1 addition & 1 deletion iOSClient/Menu/NCContextMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class NCContextMenu: NSObject {
}
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: alertStyle)
alertController.addAction(UIAlertAction(title: NSLocalizedString("_delete_file_", comment: ""), style: .destructive) { _ in
NCNetworking.shared.deleteMetadata(metadata)
NCNetworking.shared.deleteMetadatas([metadata], sceneIdentifier: sceneIdentifier)
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSource)
})
alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel) { _ in })
Expand Down
2 changes: 0 additions & 2 deletions iOSClient/Networking/E2EE/NCNetworkingE2EEDelete.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ class NCNetworkingE2EEDelete: NSObject {
//
await networkingE2EE.unlock(account: metadata.account, serverUrl: metadata.serverUrl)

NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDeleteFile, userInfo: ["ocId": [metadata.ocId], "error": NKError()])

return NKError()
}
}
76 changes: 58 additions & 18 deletions iOSClient/Networking/NCNetworking+WebDAV.swift
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,12 @@ extension NCNetworking {

// MARK: - Delete

func tapHudDeleteCache() {
tapHudStopDeleteCache = true
func tapHudDelete() {
tapHudStopDelete = true
}

func deleteCache(_ metadata: tableMetadata, sceneIdentifier: String?) async -> (NKError) {
let ncHud = NCHud()

var num: Float = 0

func numIncrement() -> Float {
Expand All @@ -335,24 +334,24 @@ extension NCNetworking {
#endif
}

self.tapHudStopDeleteCache = false
self.tapHudStopDelete = false

if metadata.directory {
#if !EXTENSION
if let controller = SceneManager.shared.getController(sceneIdentifier: sceneIdentifier) {
await MainActor.run {
ncHud.initHudRing(view: controller.view, tapToCancelDetailText: true, tapOperation: tapHudDeleteCache)
ncHud.initHudRing(view: controller.view, tapToCancelDetailText: true, tapOperation: tapHudDelete)
}
}
#endif
let serverUrl = metadata.serverUrl + "/" + metadata.fileName
let metadatas = self.database.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl BEGINSWITH %@ AND directory == false", metadata.account, serverUrl))
let numMetadatas = Float(metadatas.count)
let total = Float(metadatas.count)
for metadata in metadatas {
deleteLocalFile(metadata: metadata)
let num = numIncrement()
ncHud.progress(num: num, total: numMetadatas)
if tapHudStopDeleteCache { break }
ncHud.progress(num: num, total: total)
if tapHudStopDelete { break }
}
#if !EXTENSION
ncHud.dismiss()
Expand All @@ -364,20 +363,61 @@ extension NCNetworking {
return .success
}

func deleteMetadata(_ metadata: tableMetadata) {
let permission = NCUtility().permissionsContainsString(metadata.permissions, permissions: NCPermissions().permissionCanDelete)
if !metadata.permissions.isEmpty && permission == false {
NCContentPresenter().showInfo(error: NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_no_permission_delete_file_"))
return
func deleteMetadatas(_ metadatas: [tableMetadata], sceneIdentifier: String?) {
var metadatasPlain: [tableMetadata] = []
var metadatasE2EE: [tableMetadata] = []
let ncHud = NCHud()
var num: Float = 0

func numIncrement() -> Float {
num += 1
return num
}

if metadata.isDirectoryE2EE, NCNetworking.shared.isOnline {
#if !EXTENSION
for metadata in metadatas {
if metadata.isDirectoryE2EE {
metadatasE2EE.append(metadata)
} else {
metadatasPlain.append(metadata)
}
}

#if !EXTENSION
if !metadatasE2EE.isEmpty {
self.tapHudStopDelete = false
let total = Float(metadatasE2EE.count)

Task {
return await NCNetworkingE2EEDelete().delete(metadata: metadata)
if let controller = SceneManager.shared.getController(sceneIdentifier: sceneIdentifier) {
await MainActor.run {
ncHud.initHudRing(view: controller.view, tapToCancelDetailText: true, tapOperation: tapHudDelete)
}
}

var ocIdDeleted: [String] = []
var error = NKError()
for metadata in metadatasE2EE where error == .success {
error = await NCNetworkingE2EEDelete().delete(metadata: metadata)
if error == .success {
ocIdDeleted.append(metadata.ocId)
}
let num = numIncrement()
ncHud.progress(num: num, total: total)
if tapHudStopDelete { break }
}

ncHud.dismiss()
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDeleteFile, userInfo: ["ocId": ocIdDeleted, "error": error])
}
}
#endif

for metadata in metadatasPlain {
let permission = NCUtility().permissionsContainsString(metadata.permissions, permissions: NCPermissions().permissionCanDelete)
if !metadata.permissions.isEmpty && permission == false {
NCContentPresenter().showInfo(error: NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_no_permission_delete_file_"))
return
}
#endif
} else {

if metadata.status == global.metadataStatusWaitCreateFolder {
let metadatas = database.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl BEGINSWITH %@", metadata.account, metadata.serverUrl))
Expand Down
2 changes: 1 addition & 1 deletion iOSClient/Networking/NCNetworking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class NCNetworking: NSObject, NextcloudKitDelegate {
weak var certificateDelegate: ClientCertificateDelegate?
var p12Data: Data?
var p12Password: String?
var tapHudStopDeleteCache = false
var tapHudStopDelete = false

var isOffline: Bool {
return networkReachability == NKCommon.TypeReachability.notReachable || networkReachability == NKCommon.TypeReachability.unknown
Expand Down

0 comments on commit 0922f12

Please sign in to comment.