Skip to content

Commit

Permalink
Merge pull request #2642 from nextcloud/queue
Browse files Browse the repository at this point in the history
Queue
  • Loading branch information
marinofaggiana authored Oct 19, 2023
2 parents 1023a19 + bfa7bfe commit 2ccb45e
Show file tree
Hide file tree
Showing 15 changed files with 392 additions and 389 deletions.
36 changes: 32 additions & 4 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@
F70753EB2542A99800972D44 /* NCViewerMediaPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = F70753EA2542A99800972D44 /* NCViewerMediaPage.swift */; };
F70753F12542A9A200972D44 /* NCViewerMedia.swift in Sources */ = {isa = PBXBuildFile; fileRef = F70753F02542A9A200972D44 /* NCViewerMedia.swift */; };
F70753F72542A9C000972D44 /* NCViewerMediaPage.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F70753F62542A9C000972D44 /* NCViewerMediaPage.storyboard */; };
F7075B672AE15F6200512300 /* NCCellProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 370D26AE248A3D7A00121797 /* NCCellProtocol.swift */; };
F7075B682AE15F8100512300 /* NCCellProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 370D26AE248A3D7A00121797 /* NCCellProtocol.swift */; };
F707C26521A2DC5200F6181E /* NCStoreReview.swift in Sources */ = {isa = PBXBuildFile; fileRef = F707C26421A2DC5200F6181E /* NCStoreReview.swift */; };
F70821D829E59E6D001CA2D7 /* TagListView in Frameworks */ = {isa = PBXBuildFile; productRef = F70821D729E59E6D001CA2D7 /* TagListView */; };
F70968A424212C4E00ED60E5 /* NCLivePhoto.swift in Sources */ = {isa = PBXBuildFile; fileRef = F70968A324212C4E00ED60E5 /* NCLivePhoto.swift */; };
Expand Down Expand Up @@ -214,7 +216,6 @@
F72944F52A8424F800246839 /* NCEndToEndMetadataV1.swift in Sources */ = {isa = PBXBuildFile; fileRef = F72944F42A8424F800246839 /* NCEndToEndMetadataV1.swift */; };
F72944F62A8424F800246839 /* NCEndToEndMetadataV1.swift in Sources */ = {isa = PBXBuildFile; fileRef = F72944F42A8424F800246839 /* NCEndToEndMetadataV1.swift */; };
F72A17D828B221E300F3F159 /* DashboardWidgetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F72A17D728B221E300F3F159 /* DashboardWidgetView.swift */; };
F72A47EC2487B06B005AD489 /* NCOperationQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = F72A47EB2487B06B005AD489 /* NCOperationQueue.swift */; };
F72AD70D28C24B93006CB92D /* NextcloudKit in Frameworks */ = {isa = PBXBuildFile; productRef = F72AD70C28C24B93006CB92D /* NextcloudKit */; };
F72AD70F28C24BA1006CB92D /* NextcloudKit in Frameworks */ = {isa = PBXBuildFile; productRef = F72AD70E28C24BA1006CB92D /* NextcloudKit */; };
F72AD71128C24BBB006CB92D /* NextcloudKit in Frameworks */ = {isa = PBXBuildFile; productRef = F72AD71028C24BBB006CB92D /* NextcloudKit */; };
Expand Down Expand Up @@ -549,6 +550,10 @@
F7A321AD1E9E6AD50069AD1B /* CCAdvanced.m in Sources */ = {isa = PBXBuildFile; fileRef = F7A321AC1E9E6AD50069AD1B /* CCAdvanced.m */; };
F7A48413297022E000BD1B49 /* ViewerQuickLook.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A48412297022E000BD1B49 /* ViewerQuickLook.swift */; };
F7A48415297028FC00BD1B49 /* Nextcloud Hub.png in Resources */ = {isa = PBXBuildFile; fileRef = F7A48414297028FC00BD1B49 /* Nextcloud Hub.png */; };
F7A560422AE1593700BE8FD6 /* NCOperationSaveLivePhoto.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A560412AE1593700BE8FD6 /* NCOperationSaveLivePhoto.swift */; };
F7A560442AE15D2900BE8FD6 /* Queuer in Frameworks */ = {isa = PBXBuildFile; productRef = F7A560432AE15D2900BE8FD6 /* Queuer */; };
F7A560462AE15D3D00BE8FD6 /* Queuer in Frameworks */ = {isa = PBXBuildFile; productRef = F7A560452AE15D3D00BE8FD6 /* Queuer */; };
F7A560482AE15D5000BE8FD6 /* Queuer in Frameworks */ = {isa = PBXBuildFile; productRef = F7A560472AE15D5000BE8FD6 /* Queuer */; };
F7A60F86292D215000FCE1F2 /* NCShareAccounts.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A60F84292D215000FCE1F2 /* NCShareAccounts.swift */; };
F7A60F87292D215000FCE1F2 /* NCShareAccounts.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7A60F85292D215000FCE1F2 /* NCShareAccounts.storyboard */; };
F7A76DC8256A71CD00119AB3 /* UIImage+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7B7504A2397D38E004E13EC /* UIImage+Extension.swift */; };
Expand Down Expand Up @@ -971,7 +976,6 @@
F72944F12A84246400246839 /* NCEndToEndMetadataV20.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCEndToEndMetadataV20.swift; sourceTree = "<group>"; };
F72944F42A8424F800246839 /* NCEndToEndMetadataV1.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCEndToEndMetadataV1.swift; sourceTree = "<group>"; };
F72A17D728B221E300F3F159 /* DashboardWidgetView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DashboardWidgetView.swift; sourceTree = "<group>"; };
F72A47EB2487B06B005AD489 /* NCOperationQueue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCOperationQueue.swift; sourceTree = "<group>"; };
F72CD63925C19EBF00F46F9A /* NCAutoUpload.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCAutoUpload.swift; sourceTree = "<group>"; };
F72D1005210B6882009C96B7 /* NCPushNotificationEncryption.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NCPushNotificationEncryption.m; sourceTree = "<group>"; };
F72D1006210B6882009C96B7 /* NCPushNotificationEncryption.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NCPushNotificationEncryption.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1171,6 +1175,7 @@
F7A321AC1E9E6AD50069AD1B /* CCAdvanced.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCAdvanced.m; sourceTree = "<group>"; };
F7A48412297022E000BD1B49 /* ViewerQuickLook.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewerQuickLook.swift; sourceTree = "<group>"; };
F7A48414297028FC00BD1B49 /* Nextcloud Hub.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Nextcloud Hub.png"; sourceTree = SOURCE_ROOT; };
F7A560412AE1593700BE8FD6 /* NCOperationSaveLivePhoto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCOperationSaveLivePhoto.swift; sourceTree = "<group>"; };
F7A60F84292D215000FCE1F2 /* NCShareAccounts.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCShareAccounts.swift; sourceTree = "<group>"; };
F7A60F85292D215000FCE1F2 /* NCShareAccounts.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = NCShareAccounts.storyboard; sourceTree = "<group>"; };
F7A7FA6229265CF4000603EF /* NCManageE2EE.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCManageE2EE.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1444,6 +1449,7 @@
F72CD01227A7E92400E59476 /* JGProgressHUD in Frameworks */,
F77CB6A92AA08053000C3CA4 /* OpenSSL in Frameworks */,
F73ADD2126554F8E0069EA0D /* SwiftEntryKit in Frameworks */,
F7A560482AE15D5000BE8FD6 /* Queuer in Frameworks */,
F7EBCDCF277B81FF00A4EF67 /* UICKeyChainStore in Frameworks */,
F70821D829E59E6D001CA2D7 /* TagListView in Frameworks */,
F7F623B72A5EFA0C0022D3D4 /* Gzip in Frameworks */,
Expand All @@ -1460,6 +1466,7 @@
F783034428B5142B00B84583 /* NextcloudKit in Frameworks */,
F7346E1328B0EF5B006CE2D2 /* SwiftUI.framework in Frameworks */,
F7346E2928B0FFF2006CE2D2 /* RealmSwift in Frameworks */,
F7A560462AE15D3D00BE8FD6 /* Queuer in Frameworks */,
F783030D28B4C59A00B84583 /* SwiftEntryKit in Frameworks */,
F7346E1228B0EF5B006CE2D2 /* WidgetKit.framework in Frameworks */,
);
Expand All @@ -1469,6 +1476,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
F7A560442AE15D2900BE8FD6 /* Queuer in Frameworks */,
F7EBCDD1277B820D00A4EF67 /* UICKeyChainStore in Frameworks */,
F73ADD2426554FE20069EA0D /* SwiftEntryKit in Frameworks */,
F710FC84277B7D3500AA9FBF /* RealmSwift in Frameworks */,
Expand Down Expand Up @@ -1552,6 +1560,7 @@
AF93471127E2341B002537EE /* NCShare+Menu.swift */,
F710D2012405826100A6033D /* NCViewer+Menu.swift */,
F78C6FDD296D677300C952C3 /* NCContextMenu.swift */,
F7A560412AE1593700BE8FD6 /* NCOperationSaveLivePhoto.swift */,
);
path = Menu;
sourceTree = "<group>";
Expand Down Expand Up @@ -1882,7 +1891,6 @@
F75A9EE523796C6F0044CFCE /* NCNetworking.swift */,
F7D96FCB246ED7E100536D73 /* NCNetworkingCheckRemoteUser.swift */,
F70D8D8024A4A9BF000A5756 /* NCNetworkingProcessUpload.swift */,
F72A47EB2487B06B005AD489 /* NCOperationQueue.swift */,
F755BD9A20594AC7008C5FBB /* NCService.swift */,
F77BC3EC293E528A005F2B08 /* NCConfigServer.swift */,
);
Expand Down Expand Up @@ -2793,6 +2801,7 @@
F70821D729E59E6D001CA2D7 /* TagListView */,
F7F623B62A5EFA0C0022D3D4 /* Gzip */,
F77CB6A82AA08053000C3CA4 /* OpenSSL */,
F7A560472AE15D5000BE8FD6 /* Queuer */,
);
productName = "Share Ext";
productReference = F7CE8AFB1DC1F8D8009CAE48 /* Share.appex */;
Expand All @@ -2817,6 +2826,7 @@
F783030C28B4C59A00B84583 /* SwiftEntryKit */,
F783034328B5142B00B84583 /* NextcloudKit */,
F787AC0A298BCB540001BB00 /* SVGKitSwift */,
F7A560452AE15D3D00BE8FD6 /* Queuer */,
);
productName = DashboardWidgetExtension;
productReference = F7346E1028B0EF5B006CE2D2 /* Widget.appex */;
Expand All @@ -2840,6 +2850,7 @@
F710FC83277B7D3500AA9FBF /* RealmSwift */,
F7EBCDD0277B820D00A4EF67 /* UICKeyChainStore */,
F72AD71228C24BCC006CB92D /* NextcloudKit */,
F7A560432AE15D2900BE8FD6 /* Queuer */,
);
productName = "File Provider Extension";
productReference = F771E3D020E2392D00AFB62D /* File Provider Extension.appex */;
Expand Down Expand Up @@ -3537,6 +3548,7 @@
F72EA95A28B7BD0D00C88F0C /* FilesWidgetView.swift in Sources */,
F78302FE28B4C44700B84583 /* NCBrand.swift in Sources */,
F749B64B297B0CBB00087535 /* NCManageDatabase+Share.swift in Sources */,
F7075B682AE15F8100512300 /* NCCellProtocol.swift in Sources */,
F7817CF929801A3500FFBC65 /* Data+Extension.swift in Sources */,
F7864ACD2A78FE73004870E0 /* NCManageDatabase+LocalFile.swift in Sources */,
F343A4B42A1E084100DDA874 /* PHAsset+Extension.swift in Sources */,
Expand Down Expand Up @@ -3619,6 +3631,7 @@
F343A4BF2A1E734600DDA874 /* Optional+Extension.swift in Sources */,
AF4BF62027562B3F0081CEEF /* NCManageDatabase+Activity.swift in Sources */,
F785EEA62461A4FB00B3F945 /* CCUtility.m in Sources */,
F7075B672AE15F6200512300 /* NCCellProtocol.swift in Sources */,
F73ADD2226554FD10069EA0D /* NCContentPresenter.swift in Sources */,
F72FD3B9297ED49A00075D28 /* NCManageDatabase+E2EE.swift in Sources */,
);
Expand Down Expand Up @@ -3661,7 +3674,6 @@
F79EDAA326B004980007D134 /* NCPlayerToolBar.swift in Sources */,
F77444F8222816D5000D5EB0 /* NCPickerViewController.swift in Sources */,
F77BB74A2899857B0090FC19 /* UINavigationController+Extension.swift in Sources */,
F72A47EC2487B06B005AD489 /* NCOperationQueue.swift in Sources */,
F769454622E9F1B0000A798A /* NCShareCommon.swift in Sources */,
F70753F12542A9A200972D44 /* NCViewerMedia.swift in Sources */,
F76B649C2ADFFAED00014640 /* NCMediaCache.swift in Sources */,
Expand Down Expand Up @@ -3776,6 +3788,7 @@
F70CAE3A1F8CF31A008125FD /* NCEndToEndEncryption.m in Sources */,
AF93471B27E2361E002537EE /* NCShareAdvancePermission.swift in Sources */,
F77BC3ED293E528A005F2B08 /* NCConfigServer.swift in Sources */,
F7A560422AE1593700BE8FD6 /* NCOperationSaveLivePhoto.swift in Sources */,
F70753EB2542A99800972D44 /* NCViewerMediaPage.swift in Sources */,
F7817CF829801A3500FFBC65 /* Data+Extension.swift in Sources */,
F749B651297B0F2400087535 /* NCManageDatabase+Avatar.swift in Sources */,
Expand Down Expand Up @@ -5427,6 +5440,21 @@
package = F7A1050C29E587AF00FFD92B /* XCRemoteSwiftPackageReference "TagListView" */;
productName = TagListView;
};
F7A560432AE15D2900BE8FD6 /* Queuer */ = {
isa = XCSwiftPackageProductDependency;
package = F76DA961277B760E0082465B /* XCRemoteSwiftPackageReference "Queuer" */;
productName = Queuer;
};
F7A560452AE15D3D00BE8FD6 /* Queuer */ = {
isa = XCSwiftPackageProductDependency;
package = F76DA961277B760E0082465B /* XCRemoteSwiftPackageReference "Queuer" */;
productName = Queuer;
};
F7A560472AE15D5000BE8FD6 /* Queuer */ = {
isa = XCSwiftPackageProductDependency;
package = F76DA961277B760E0082465B /* XCRemoteSwiftPackageReference "Queuer" */;
productName = Queuer;
};
F7A8D72328F1771B008BBE1C /* NextcloudKit */ = {
isa = XCSwiftPackageProductDependency;
package = F783034028B511D200B84583 /* XCRemoteSwiftPackageReference "NextcloudKit" */;
Expand Down
4 changes: 2 additions & 2 deletions iOSClient/Activity/NCActivity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ extension NCActivity: UITableViewDataSource {

// Image
let fileName = appDelegate.userBaseUrl + "-" + comment.actorId + ".png"
NCOperationQueue.shared.downloadAvatar(user: comment.actorId, dispalyName: comment.actorDisplayName, fileName: fileName, cell: cell, view: tableView, cellImageView: cell.fileAvatarImageView)
NCNetworking.shared.downloadAvatar(user: comment.actorId, dispalyName: comment.actorDisplayName, fileName: fileName, cell: cell, view: tableView, cellImageView: cell.fileAvatarImageView)
// Username
cell.labelUser.text = comment.actorDisplayName
cell.labelUser.textColor = .label
Expand Down Expand Up @@ -279,7 +279,7 @@ extension NCActivity: UITableViewDataSource {

let fileName = appDelegate.userBaseUrl + "-" + activity.user + ".png"

NCOperationQueue.shared.downloadAvatar(user: activity.user, dispalyName: nil, fileName: fileName, cell: cell, view: tableView, cellImageView: cell.fileAvatarImageView)
NCNetworking.shared.downloadAvatar(user: activity.user, dispalyName: nil, fileName: fileName, cell: cell, view: tableView, cellImageView: cell.fileAvatarImageView)
}

// subject
Expand Down
55 changes: 54 additions & 1 deletion iOSClient/Activity/NCActivityTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Foundation
import NextcloudKit
import FloatingPanel
import JGProgressHUD
import Queuer

class NCActivityCollectionViewCell: UICollectionViewCell {

Expand Down Expand Up @@ -194,7 +195,13 @@ extension NCActivityTableViewCell: UICollectionViewDataSource {
if FileManager.default.fileExists(atPath: fileNamePath), let image = UIImage(contentsOfFile: fileNamePath) {
cell.imageView.image = image
} else {
NCOperationQueue.shared.downloadThumbnailActivity(fileNamePathOrFileId: activityPreview.source, fileNamePreviewLocalPath: fileNamePath, fileId: fileId, cell: cell, collectionView: collectionView)
cell.imageView?.image = UIImage(named: "file_photo")
cell.fileId = fileId
if !FileManager.default.fileExists(atPath: fileNamePath) {
if appDelegate.downloadThumbnailActivityQueue.operations.filter({ ($0 as? NCOperationDownloadThumbnailActivity)?.fileId == fileId }).isEmpty {
appDelegate.downloadThumbnailActivityQueue.addOperation(NCOperationDownloadThumbnailActivity(fileNamePathOrFileId: activityPreview.source, fileNamePreviewLocalPath: fileNamePath, fileId: fileId, cell: cell, collectionView: collectionView))
}
}
}
}
}
Expand All @@ -219,3 +226,49 @@ extension NCActivityTableViewCell: UICollectionViewDelegateFlowLayout {
return UIEdgeInsets(top: 0, left: 0, bottom: 10, right: 0)
}
}

class NCOperationDownloadThumbnailActivity: ConcurrentOperation {

var cell: NCActivityCollectionViewCell?
var collectionView: UICollectionView?
var fileNamePathOrFileId: String
var fileNamePreviewLocalPath: String
var fileId: String

init(fileNamePathOrFileId: String, fileNamePreviewLocalPath: String, fileId: String, cell: NCActivityCollectionViewCell?, collectionView: UICollectionView?) {
self.fileNamePathOrFileId = fileNamePathOrFileId
self.fileNamePreviewLocalPath = fileNamePreviewLocalPath
self.fileId = fileId
self.cell = cell
self.collectionView = collectionView
}

override func start() {

guard !isCancelled else { return self.finish() }

NextcloudKit.shared.downloadPreview(fileNamePathOrFileId: fileNamePathOrFileId,
fileNamePreviewLocalPath: fileNamePreviewLocalPath,
widthPreview: 0,
heightPreview: 0,
etag: nil,
useInternalEndpoint: false,
options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { _, imagePreview, _, _, _, error in

if error == .success, let imagePreview = imagePreview {
DispatchQueue.main.async {
if self.fileId == self.cell?.fileId, let imageView = self.cell?.imageView {
UIView.transition(with: imageView,
duration: 0.75,
options: .transitionCrossDissolve,
animations: { imageView.image = imagePreview },
completion: nil)
} else {
self.collectionView?.reloadData()
}
}
}
self.finish()
}
}
}
4 changes: 3 additions & 1 deletion iOSClient/Files/NCFiles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ class NCFiles: NCCollectionViewCommon {
networkReadFolder(isForced: isForced) { tableDirectory, metadatas, metadatasUpdate, metadatasDelete, error in
if error == .success {
for metadata in metadatas ?? [] where !metadata.directory && NCManageDatabase.shared.isDownloadMetadata(metadata, download: false) {
NCOperationQueue.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorDownloadFile)
if self.appDelegate.downloadQueue.operations.filter({ ($0 as? NCOperationDownload)?.metadata.ocId == metadata.ocId }).isEmpty {
self.appDelegate.downloadQueue.addOperation(NCOperationDownload(metadata: metadata, selector: NCGlobal.shared.selectorDownloadFile))
}
}
}

Expand Down
Loading

0 comments on commit 2ccb45e

Please sign in to comment.