Skip to content

Commit

Permalink
Handle lookup item & attachment creation in IdentifierLookupController (
Browse files Browse the repository at this point in the history
  • Loading branch information
mvasilak authored Nov 22, 2023
1 parent d560c4a commit 2f4687a
Show file tree
Hide file tree
Showing 32 changed files with 1,272 additions and 452 deletions.
21 changes: 21 additions & 0 deletions Zotero.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
6144B5E12A4AE95E00914B3C /* WebDavControllerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3202C6B271048FF00485BE4 /* WebDavControllerSpec.swift */; };
614D65822A79C9AC007CF449 /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = 614D65802A79C9AC007CF449 /* Localizable.stringsdict */; };
614D65832A79C9B0007CF449 /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = 614D65802A79C9AC007CF449 /* Localizable.stringsdict */; };
614D65872A8030C9007CF449 /* OrderedCollections in Frameworks */ = {isa = PBXBuildFile; productRef = 614D65862A8030C9007CF449 /* OrderedCollections */; };
618404262A4456A9005AAF22 /* IdentifierLookupController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 618404252A4456A9005AAF22 /* IdentifierLookupController.swift */; };
61ABA7512A6137D1002A4219 /* ShareableImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61ABA7502A6137D1002A4219 /* ShareableImage.swift */; };
61BD13952A5831EF008A0704 /* TextKit1TextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61BD13942A5831EF008A0704 /* TextKit1TextView.swift */; };
61C817F22A49B5D30085B1E6 /* CollectionResponseSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3B1EDEE250242E700D8BC1E /* CollectionResponseSpec.swift */; };
Expand Down Expand Up @@ -1200,6 +1202,7 @@
611486502A9CD511002EEBEF /* ci_post_xcodebuild.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = ci_post_xcodebuild.sh; sourceTree = "<group>"; };
614D65812A79C9AC007CF449 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = en; path = en.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
614D65842A7BCC22007CF449 /* ci_post_clone.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = ci_post_clone.sh; sourceTree = "<group>"; };
618404252A4456A9005AAF22 /* IdentifierLookupController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdentifierLookupController.swift; sourceTree = "<group>"; };
61ABA7502A6137D1002A4219 /* ShareableImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareableImage.swift; sourceTree = "<group>"; };
61BD13942A5831EF008A0704 /* TextKit1TextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextKit1TextView.swift; sourceTree = "<group>"; };
61FA14CD2B05081D00E7D423 /* TextConverter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextConverter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2034,6 +2037,7 @@
B356A39E2524A703003F1943 /* CocoaLumberjackSwift in Frameworks */,
B356A363252490B3003F1943 /* Alamofire in Frameworks */,
B356A369252490DB003F1943 /* KeychainSwift in Frameworks */,
614D65872A8030C9007CF449 /* OrderedCollections in Frameworks */,
B356A37B2524A63D003F1943 /* SwiftyGif in Frameworks */,
B356A3A02524A703003F1943 /* CocoaLumberjack in Frameworks */,
B35C9C082642A0BC0004C47E /* RealmSwift in Frameworks */,
Expand Down Expand Up @@ -2165,6 +2169,7 @@
B36A988C2428E059005D5790 /* TranslatorsAndStylesController.swift */,
B3972688247D403200A8B469 /* UrlDetector.swift */,
B324276C25C81F2000567504 /* WebSocketController.swift */,
618404252A4456A9005AAF22 /* IdentifierLookupController.swift */,
);
path = Controllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -4051,6 +4056,7 @@
B35C9C072642A0BC0004C47E /* RealmSwift */,
B3445F4526EF5EE9007D4009 /* CrashReporter */,
B3D84BEF27919FDE005DDD7C /* Starscream */,
614D65862A8030C9007CF449 /* OrderedCollections */,
);
productName = Zotero;
productReference = B30D59552206F60400884C4A /* Zotero.app */;
Expand Down Expand Up @@ -4192,6 +4198,7 @@
B35C9C042642A0BC0004C47E /* XCRemoteSwiftPackageReference "realm-cocoa" */,
B3445F4426EF5EE9007D4009 /* XCRemoteSwiftPackageReference "plcrashreporter" */,
B3D84BEE27919FDE005DDD7C /* XCRemoteSwiftPackageReference "Starscream" */,
614D65852A8030C9007CF449 /* XCRemoteSwiftPackageReference "swift-collections" */,
);
productRefGroup = B30D59562206F60400884C4A /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -5091,6 +5098,7 @@
B340ECA6290FDC9F00EE920D /* AnnotationToolbarViewController.swift in Sources */,
B3401D572567D8F700BB8D6E /* AnnotationViewController.swift in Sources */,
B3830CE2255451C200910FE0 /* TagPickerActionHandler.swift in Sources */,
618404262A4456A9005AAF22 /* IdentifierLookupController.swift in Sources */,
B305662223FC051F003304F2 /* StoreVersionSyncAction.swift in Sources */,
B3BC25CD247E6BA000AC27B5 /* DateParser.swift in Sources */,
B305662523FC051F003304F2 /* RevertLibraryUpdatesSyncAction.swift in Sources */,
Expand Down Expand Up @@ -5999,6 +6007,14 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
614D65852A8030C9007CF449 /* XCRemoteSwiftPackageReference "swift-collections" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/apple/swift-collections.git";
requirement = {
kind = exactVersion;
version = 1.0.4;
};
};
B3445F4426EF5EE9007D4009 /* XCRemoteSwiftPackageReference "plcrashreporter" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/microsoft/plcrashreporter";
Expand Down Expand Up @@ -6114,6 +6130,11 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
614D65862A8030C9007CF449 /* OrderedCollections */ = {
isa = XCSwiftPackageProductDependency;
package = 614D65852A8030C9007CF449 /* XCRemoteSwiftPackageReference "swift-collections" */;
productName = OrderedCollections;
};
B3445F4526EF5EE9007D4009 /* CrashReporter */ = {
isa = XCSwiftPackageProductDependency;
package = B3445F4426EF5EE9007D4009 /* XCRemoteSwiftPackageReference "plcrashreporter" */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@
"version" : "4.0.6"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "937e904258d22af6e447a0b72c0bc67583ef64a2",
"version" : "1.0.4"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
Expand Down
5 changes: 4 additions & 1 deletion Zotero/Assets/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"size" = "Size";
"remove" = "Remove";
"keep" = "Keep";
"cancel_all" = "Cancel All";

"beta_wipe_title" = "Resync Required";
"beta_wipe_message" = "Due to a beta update, your data must be redownloaded from zotero.org.";
Expand Down Expand Up @@ -134,6 +135,7 @@
"items.filters.title" = "Filters";
"items.filters.downloads" = "Downloaded Files";
"items.filters.tags" = "Tags";
"items.toolbar_saved" = "Saved %d / %d";
"items.toolbar_downloaded" = "Downloaded %d / %d";
"items.generating_bib" = "Generating Bibliography";
"items.creator_summary.and" = "%@ and %@";
Expand Down Expand Up @@ -470,7 +472,8 @@
"errors.citation.invalid_types" = "Invalid item types selected.";
"errors.citation.missing_style" = "No citation style selected. Go to Settings → Quick Copy and select a new style.";
"errors.citation.open_settings" = "Open Settings";
"errors.lookup" = "Zotero could not find any identifiers in your input. Please verify your input and try again.";
"errors.lookup.no_identifiers_and_no_lookup_data" = "Zotero could not find any identifiers in your input. Please verify your input and try again.";
"errors.lookup.no_identifiers_with_lookup_data" = "Zotero could not find any new identifiers in your input, or they are already being added. Please verify your input and try again.";
"errors.pdf.merge_too_big_title" = "Unable to merge annotations";
"errors.pdf.merge_too_big" = "The combined annotation would be too large.";
"errors.pdf.cant_update_annotation" = "Can't update annotation.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ class AttachmentDownloadOperation: AsynchronousOperation {

var finishedDownload: ((Result<(), Swift.Error>) -> Void)?

init(file: File, download: AttachmentDownloader.Download, progress: Progress, userId: Int, apiClient: ApiClient, webDavController: WebDavController, fileStorage: FileStorage, queue: DispatchQueue) {
init(
file: File,
download: AttachmentDownloader.Download,
progress: Progress,
userId: Int,
apiClient: ApiClient,
webDavController: WebDavController,
fileStorage: FileStorage,
queue: DispatchQueue
) {
self.file = file
self.download = download
self.progress = progress
Expand Down Expand Up @@ -231,7 +240,9 @@ class AttachmentDownloadOperation: AsynchronousOperation {
self.zipProgress = nil
// Try removing downloaded file.
try? self.fileStorage.remove(Files.attachmentDirectory(in: self.download.libraryId, key: self.download.key))
case .done: break

case .done:
break
}

self.finishedDownload?(.failure(Error.cancelled))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,13 @@ final class AttachmentDownloader {

case .file(let filename, let contentType, let location, let linkType):
switch linkType {
case .linkedFile, .embeddedImage: break
case .linkedFile, .embeddedImage:
break

case .importedFile, .importedUrl:
switch location {
case .local: break
case .local:
break

case .remote, .remoteMissing, .localAndChangedRemotely:
DDLogInfo("AttachmentDownloader: batch download remote\(location == .remoteMissing ? "ly missing" : "") file \(attachment.key)")
Expand Down Expand Up @@ -269,8 +271,16 @@ final class AttachmentDownloader {
let observer = progress.observe(\.fractionCompleted) { [weak self] progress, _ in
self?.observable.on(.next(Update(download: download, parentKey: parentKey, kind: .progress(CGFloat(progress.fractionCompleted)))))
}
let operation = AttachmentDownloadOperation(file: file, download: download, progress: progress, userId: self.userId, apiClient: self.apiClient, webDavController: self.webDavController,
fileStorage: self.fileStorage, queue: self.processingQueue)
let operation = AttachmentDownloadOperation(
file: file,
download: download,
progress: progress,
userId: userId,
apiClient: apiClient,
webDavController: webDavController,
fileStorage: fileStorage,
queue: processingQueue
)
operation.finishedDownload = { [weak self] result in
guard let self = self else { return }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,22 @@ class RemoteAttachmentDownloadOperation: AsynchronousOperation {

private let url: URL
private let file: File
let progress: Progress?
private let queue: DispatchQueue
private unowned let apiClient: ApiClient
private unowned let fileStorage: FileStorage

private var request: DownloadRequest?
private var state: State?
private var disposeBag: DisposeBag?
private(set) var progress: Progress?

var progressHandler: ((Progress) -> Void)?
var finishedDownload: ((Result<(), Swift.Error>) -> Void)?

init(url: URL, file: File, apiClient: ApiClient, fileStorage: FileStorage, queue: DispatchQueue) {
init(url: URL, file: File, progress: Progress, apiClient: ApiClient, fileStorage: FileStorage, queue: DispatchQueue) {
self.url = url
self.file = file
self.progress = progress
self.apiClient = apiClient
self.fileStorage = fileStorage
self.queue = queue
Expand Down Expand Up @@ -66,7 +67,7 @@ class RemoteAttachmentDownloadOperation: AsynchronousOperation {
self.apiClient.download(request: request, queue: self.queue)
.subscribe(onNext: { [weak self] request in
// Store download request so that it can be cancelled
self?.progress = request.downloadProgress
self?.progress?.addChild(request.downloadProgress, withPendingUnitCount: 100)
self?.progressHandler?(request.downloadProgress)
self?.request = request
// Start request
Expand Down Expand Up @@ -137,7 +138,9 @@ class RemoteAttachmentDownloadOperation: AsynchronousOperation {
self.request?.cancel()
self.disposeBag = nil
self.request = nil
case .done: break

case .done:
break
}

self.finishedDownload?(.failure(Error.cancelled))
Expand Down
Loading

0 comments on commit 2f4687a

Please sign in to comment.