Skip to content

Commit

Permalink
Version 5.2.2 (nextcloud#2852)
Browse files Browse the repository at this point in the history
  • Loading branch information
marinofaggiana authored Mar 18, 2024
1 parent f4c65b1 commit 09dd9a1
Show file tree
Hide file tree
Showing 175 changed files with 1,327 additions and 821 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion Brand/Database.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ import Foundation
// Database Realm
//
let databaseName = "nextcloud.realm"
let databaseSchemaVersion: UInt64 = 345
let databaseSchemaVersion: UInt64 = 346
67 changes: 57 additions & 10 deletions Nextcloud.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Share/NCShareExtension+DataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extension NCShareExtension: UICollectionViewDataSource {
return UICollectionViewCell()
}

cell.delegate = self
cell.listCellDelegate = self

cell.fileObjectId = metadata.ocId
cell.indexPath = indexPath
Expand Down
47 changes: 20 additions & 27 deletions iOSClient/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
NCSettingsBundleHelper.setVersionAndBuildNumber()
NCSettingsBundleHelper.checkAndExecuteSettings(delay: 0.5)

// START OBSERVE/TIMER UPLOAD PROCESS
NCNetworkingProcess.shared.observeTableMetadata()
// START TIMER UPLOAD PROCESS
NCNetworkingProcess.shared.startTimer()

if !NCAskAuthorization().isRequesting {
Expand All @@ -211,8 +210,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD

guard !account.isEmpty else { return }

// STOP OBSERVE/TIMER UPLOAD PROCESS
NCNetworkingProcess.shared.invalidateObserveTableMetadata()
// STOP TIMER UPLOAD PROCESS
NCNetworkingProcess.shared.stopTimer()

if NCKeychain().privacyScreenEnabled {
Expand Down Expand Up @@ -359,33 +357,28 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
}

func handleAppRefreshProcessingTask(taskText: String, completion: @escaping () -> Void = {}) {
let semaphore = DispatchSemaphore(value: 0)

NCAutoUpload.shared.initAutoUpload(viewController: nil) { items in
Task {
NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] \(taskText) start handle")
let items = await NCAutoUpload.shared.initAutoUpload()
NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] \(taskText) auto upload with \(items) uploads")

NCNetworkingProcess.shared.start { counterDownload, counterUpload in
NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] \(taskText) networking process with download: \(counterDownload) upload: \(counterUpload)")

if taskText == "ProcessingTask",
items == 0, counterDownload == 0, counterUpload == 0,
let directories = NCManageDatabase.shared.getTablesDirectory(predicate: NSPredicate(format: "account == %@ AND offline == true", self.account), sorted: "offlineDate", ascending: true) {

for directory: tableDirectory in directories {
// only 3 time for day
if let offlineDate = directory.offlineDate, offlineDate.addingTimeInterval(28800) > Date() {
NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] \(taskText) skip synchronization for \(directory.serverUrl) in date \(offlineDate)")
continue
}
NCNetworking.shared.synchronization(account: self.account, serverUrl: directory.serverUrl, add: false) { errorCode, items in
NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] \(taskText) end synchronization for \(directory.serverUrl), errorCode: \(errorCode), item: \(items)")
semaphore.signal()
}
semaphore.wait()
let results = await NCNetworkingProcess.shared.start()
NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] \(taskText) networking process with download: \(results.counterDownload) upload: \(results.counterUpload)")

if taskText == "ProcessingTask",
items == 0, results.counterDownload == 0, results.counterUpload == 0,
let directories = NCManageDatabase.shared.getTablesDirectory(predicate: NSPredicate(format: "account == %@ AND offline == true", self.account), sorted: "offlineDate", ascending: true) {
for directory: tableDirectory in directories {
// only 3 time for day
if let offlineDate = directory.offlineDate, offlineDate.addingTimeInterval(28800) > Date() {
NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] \(taskText) skip synchronization for \(directory.serverUrl) in date \(offlineDate)")
continue
}
let results = await NCNetworking.shared.synchronization(account: self.account, serverUrl: directory.serverUrl, add: false)
NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] \(taskText) end synchronization for \(directory.serverUrl), errorCode: \(results.errorCode), item: \(results.items)")
}
completion()
}
NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] \(taskText) completion handle")
completion()
}
}

Expand Down
26 changes: 12 additions & 14 deletions iOSClient/Data/NCManageDatabase+Metadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class tableMetadata: Object, NCUserBaseUrl {
@objc dynamic var dataFingerprint = ""
@objc dynamic var date = NSDate()
@objc dynamic var directory: Bool = false
@objc dynamic var deleteAssetLocalIdentifier: Bool = false
@objc dynamic var downloadURL = ""
@objc dynamic var e2eEncrypted: Bool = false
@objc dynamic var edited: Bool = false
Expand Down Expand Up @@ -215,7 +214,7 @@ extension tableMetadata {
return session.isEmpty && !isDocumentViewableOnly && !isDirectoryE2EE && !e2eEncrypted
}

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

Expand Down Expand Up @@ -979,7 +978,7 @@ extension NCManageDatabase {

do {
let realm = try Realm()
let results = realm.objects(tableMetadata.self).filter("account == %@ AND assetLocalIdentifier != '' AND deleteAssetLocalIdentifier == true", account)
let results = realm.objects(tableMetadata.self).filter("account == %@ AND assetLocalIdentifier != ''", account)
for result in results {
assetLocalIdentifiers.append(result.assetLocalIdentifier)
}
Expand All @@ -998,7 +997,6 @@ extension NCManageDatabase {
let results = realm.objects(tableMetadata.self).filter("account == %@ AND assetLocalIdentifier IN %@", account, assetLocalIdentifiers)
for result in results {
result.assetLocalIdentifier = ""
result.deleteAssetLocalIdentifier = false
}
}
} catch let error {
Expand Down Expand Up @@ -1123,24 +1121,24 @@ extension NCManageDatabase {
}

@discardableResult
func updateMetadatas(_ metadatas: [tableMetadata], predicate: NSPredicate) -> (metadatasChangedCount: Int, metadatasChanged: Bool) {
func updateMetadatas(_ metadatas: [tableMetadata], predicate: NSPredicate) -> (metadatasDifferentCount: Int, metadatasModified: Int) {

var metadatasChangedCount: Int = 0
var metadatasChanged: Bool = false
var metadatasDifferentCount: Int = 0
var metadatasModified: Int = 0

do {
let realm = try Realm()
try realm.write {
let results = realm.objects(tableMetadata.self).filter(predicate)
metadatasChangedCount = metadatas.count - results.count
metadatasDifferentCount = metadatas.count - results.count
for metadata in metadatas {
if let result = results.first(where: { $0.ocId == metadata.ocId }),
metadata.isEqual(result) { } else {
metadatasChanged = true
break
if let result = results.first(where: { $0.ocId == metadata.ocId }) {
// before realm.add copy the value not available from server
metadata.assetLocalIdentifier = result.assetLocalIdentifier
if !metadata.isEqual(result) { metadatasModified += 1 }
}
}
if metadatasChangedCount != 0 || metadatasChanged {
if metadatasDifferentCount != 0 || metadatasModified > 0 {
realm.delete(results)
for metadata in metadatas {
realm.add(tableMetadata(value: metadata), update: .all)
Expand All @@ -1151,7 +1149,7 @@ extension NCManageDatabase {
NextcloudKit.shared.nkCommonInstance.writeLog("Could not write to database: \(error)")
}

return (metadatasChangedCount, metadatasChanged)
return (metadatasDifferentCount, metadatasModified)
}

func replaceMetadata(_ metadatas: [tableMetadata], predicate: NSPredicate) {
Expand Down
45 changes: 45 additions & 0 deletions iOSClient/Extensions/UIAlertController+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,51 @@ extension UIAlertController {
textField.isSecureTextEntry = true
textField.placeholder = NSLocalizedString("_password_", comment: "")
}, completion: completion)
}

static func deleteFileOrFolder(titleString: String, message: String?, canDeleteServer: Bool, selectedMetadatas: [tableMetadata], indexPaths: [IndexPath], completion: @escaping (_ cancelled: Bool) -> Void) -> UIAlertController {
let alertController = UIAlertController(
title: titleString,
message: message,
preferredStyle: .alert)
if canDeleteServer {
alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .destructive) { (_: UIAlertAction) in
Task {
var error = NKError()
var ocId: [String] = []
for metadata in selectedMetadatas where error == .success {
error = await NCNetworking.shared.deleteMetadata(metadata, onlyLocalCache: false)
if error == .success {
ocId.append(metadata.ocId)
}
}
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDeleteFile, userInfo: ["ocId": ocId, "indexPath": indexPaths, "onlyLocalCache": false, "error": error])
}
completion(false)
})
}

alertController.addAction(UIAlertAction(title: NSLocalizedString("_remove_local_file_", comment: ""), style: .default) { (_: UIAlertAction) in
Task {
var error = NKError()
var ocId: [String] = []
for metadata in selectedMetadatas where error == .success {
error = await NCNetworking.shared.deleteMetadata(metadata, onlyLocalCache: true)
if error == .success {
ocId.append(metadata.ocId)
}
}
if error != .success {
NCContentPresenter().showError(error: error)
}
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDeleteFile, userInfo: ["ocId": ocId, "indexPath": indexPaths, "onlyLocalCache": true, "error": error])
}
completion(false)
})

alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel) { (_: UIAlertAction) in
completion(true)
})
return alertController
}
}
7 changes: 6 additions & 1 deletion iOSClient/Extensions/UIColor+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ import Foundation
import UIKit

extension UIColor {

var inverted: UIColor {
var r: CGFloat = 0.0, g: CGFloat = 0.0, b: CGFloat = 0.0, a: CGFloat = 0.0
self.getRed(&r, green: &g, blue: &b, alpha: &a)
return UIColor(red: (1 - r), green: (1 - g), blue: (1 - b), alpha: a) // Assuming you want the same alpha value.
}

var hexString: String {

let cgColorInRGB = cgColor.converted(to: CGColorSpace(name: CGColorSpace.sRGB)!, intent: .defaultIntent, options: nil)!
Expand Down
6 changes: 6 additions & 0 deletions iOSClient/Extensions/UIView+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,10 @@ extension UIView {
blurredEffectView.isUserInteractionEnabled = false
self.addSubview(blurredEffectView)
}

func makeCircularBackground(withColor backgroundColor: UIColor) {
self.backgroundColor = backgroundColor
self.layer.cornerRadius = self.frame.size.width / 2
self.layer.masksToBounds = true
}
}
27 changes: 16 additions & 11 deletions iOSClient/Files/NCFiles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class NCFiles: NCCollectionViewCommon {
self.isSearchingMode = false
self.isEditMode = false
self.selectOcId.removeAll()
self.selectIndexPath.removeAll()
self.selectIndexPaths.removeAll()

self.layoutForView = NCManageDatabase.shared.getLayoutForView(account: self.appDelegate.account, key: self.layoutKey, serverUrl: self.serverUrl)
self.gridLayout.itemForLine = CGFloat(self.layoutForView?.itemForLine ?? 3)
Expand Down Expand Up @@ -104,7 +104,12 @@ class NCFiles: NCCollectionViewCommon {
override func queryDB() {
super.queryDB()

let metadatas = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", self.appDelegate.account, self.serverUrl))
var metadatas: [tableMetadata] = []
if NCKeychain().getPersonalFilesOnly(account: self.appDelegate.account) {
metadatas = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND (ownerId == %@ || ownerId == '') AND mountType == ''", self.appDelegate.account, self.serverUrl, self.appDelegate.userId))
} else {
metadatas = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", self.appDelegate.account, self.serverUrl))
}
let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", self.appDelegate.account, self.serverUrl))
if self.metadataFolder == nil {
self.metadataFolder = NCManageDatabase.shared.getMetadataFolder(account: self.appDelegate.account, urlBase: self.appDelegate.urlBase, userId: self.appDelegate.userId, serverUrl: self.serverUrl)
Expand Down Expand Up @@ -156,7 +161,7 @@ class NCFiles: NCCollectionViewCommon {

super.reloadDataSourceNetwork()

networkReadFolder { tableDirectory, metadatas, metadatasChangedCount, metadatasChanged, error in
networkReadFolder { tableDirectory, metadatas, metadatasDifferentCount, metadatasModified, error in
if error == .success {
for metadata in metadatas ?? [] where !metadata.directory && downloadMetadata(metadata) {
if NCNetworking.shared.downloadQueue.operations.filter({ ($0 as? NCOperationDownload)?.metadata.ocId == metadata.ocId }).isEmpty {
Expand All @@ -165,7 +170,7 @@ class NCFiles: NCCollectionViewCommon {
}
self.richWorkspaceText = tableDirectory?.richWorkspace

if metadatasChangedCount != 0 || metadatasChanged {
if metadatasDifferentCount != 0 || metadatasModified != 0 {
self.reloadDataSource()
} else {
self.reloadDataSource(withQueryDB: false)
Expand All @@ -176,7 +181,7 @@ class NCFiles: NCCollectionViewCommon {
}
}

private func networkReadFolder(completion: @escaping(_ tableDirectory: tableDirectory?, _ metadatas: [tableMetadata]?, _ metadatasChangedCount: Int, _ metadatasChanged: Bool, _ error: NKError) -> Void) {
private func networkReadFolder(completion: @escaping(_ tableDirectory: tableDirectory?, _ metadatas: [tableMetadata]?, _ metadatasDifferentCount: Int, _ metadatasModified: Int, _ error: NKError) -> Void) {

var tableDirectory: tableDirectory?

Expand All @@ -185,7 +190,7 @@ class NCFiles: NCCollectionViewCommon {
self.collectionView.reloadData()
} completion: { account, metadataFolder, error in
guard error == .success, let metadataFolder else {
return completion(nil, nil, 0, false, error)
return completion(nil, nil, 0, 0, error)
}
tableDirectory = NCManageDatabase.shared.setDirectory(serverUrl: self.serverUrl, richWorkspace: metadataFolder.richWorkspace, account: account)
// swiftlint:disable empty_string
Expand All @@ -198,9 +203,9 @@ class NCFiles: NCCollectionViewCommon {
forceReplaceMetadatas: forceReplaceMetadatas) { task in
self.dataSourceTask = task
self.collectionView.reloadData()
} completion: { _, metadataFolder, metadatas, metadatasChangedCount, metadatasChanged, error in
} completion: { _, metadataFolder, metadatas, metadatasDifferentCount, metadatasModified, error in
guard error == .success else {
return completion(tableDirectory, nil, 0, false, error)
return completion(tableDirectory, nil, 0, 0, error)
}
self.metadataFolder = metadataFolder
// E2EE
Expand Down Expand Up @@ -245,14 +250,14 @@ class NCFiles: NCCollectionViewCommon {
} else {
NCContentPresenter().showError(error: NKError(errorCode: NCGlobal.shared.errorE2EEKeyDecodeMetadata, errorDescription: "_e2e_error_"))
}
completion(tableDirectory, metadatas, metadatasChangedCount, metadatasChanged, error)
completion(tableDirectory, metadatas, metadatasDifferentCount, metadatasModified, error)
}
} else {
completion(tableDirectory, metadatas, metadatasChangedCount, metadatasChanged, error)
completion(tableDirectory, metadatas, metadatasDifferentCount, metadatasModified, error)
}
}
} else {
completion(tableDirectory, nil, 0, false, NKError())
completion(tableDirectory, nil, 0, 0, NKError())
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions iOSClient/Images.xcassets/Image.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"images" : [

],
"info" : {
"author" : "xcode",
"version" : 1
}
}
10 changes: 10 additions & 0 deletions iOSClient/Images.xcassets/Image.imageset/folder_link.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.000",
"green" : "0.000",
"red" : "0.000"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "1.000",
"green" : "1.000",
"red" : "1.000"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading

0 comments on commit 09dd9a1

Please sign in to comment.