diff --git a/Examples/xx-messenger/Sources/AppCore/ReceiveFileHandler/ReceiveFileHandler.swift b/Examples/xx-messenger/Sources/AppCore/ReceiveFileHandler/ReceiveFileHandler.swift index 84abe3c5edf058f205978bc836758a52bd379e0f..03a22e4da0bdd02e1c8aedea42c3f9804070431a 100644 --- a/Examples/xx-messenger/Sources/AppCore/ReceiveFileHandler/ReceiveFileHandler.swift +++ b/Examples/xx-messenger/Sources/AppCore/ReceiveFileHandler/ReceiveFileHandler.swift @@ -5,14 +5,6 @@ import XXMessengerClient import XXModels public struct ReceiveFileHandler { - public struct ProgressError: Error { - public init(message: String) { - self.message = message - } - - public var message: String - } - public typealias OnError = (Error) -> Void public var run: (@escaping OnError) -> Cancellable @@ -70,14 +62,11 @@ extension ReceiveFileHandler { data: data ) - case .failed(.receiveError(let error)): + case .failed(.receive(let error)): onError(error) - case .failed(.callbackError(let error)): + case .failed(.callback(let error)): onError(error) - - case .failed(.progressError(let message)): - onError(ProgressError(message: message)) } } } catch { diff --git a/Examples/xx-messenger/Sources/AppCore/SendImage/SendImage.swift b/Examples/xx-messenger/Sources/AppCore/SendImage/SendImage.swift index a457dcd49e11c3e06975a7151a6bd8a9dd839412..9a9a216ac1fb5c13912ac845c0243740517aa1c9 100644 --- a/Examples/xx-messenger/Sources/AppCore/SendImage/SendImage.swift +++ b/Examples/xx-messenger/Sources/AppCore/SendImage/SendImage.swift @@ -5,14 +5,6 @@ import XXMessengerClient import XXModels public struct SendImage { - public struct ProgressError: Error, Equatable { - public init(message: String) { - self.message = message - } - - public var message: String - } - public typealias OnError = (Error) -> Void public typealias Completion = () -> Void @@ -75,12 +67,9 @@ extension SendImage { progress: 1 ) - case .failed(_, .error(let error)): + case .failed(_, .callback(let error)): onError(error) - case .failed(_, .progressError(let message)): - onError(ProgressError(message: message)) - case .failed(_, .close(let error)): onError(error) } diff --git a/Examples/xx-messenger/Sources/HomeFeature/HomeView.swift b/Examples/xx-messenger/Sources/HomeFeature/HomeView.swift index d505100474cdd330d28afc81e126bbb0daf853b0..f2fb823ce3772601b24e65bf66063bad2304846f 100644 --- a/Examples/xx-messenger/Sources/HomeFeature/HomeView.swift +++ b/Examples/xx-messenger/Sources/HomeFeature/HomeView.swift @@ -36,6 +36,7 @@ public struct HomeView: View { if let failure = viewStore.failure { Section { Text(failure) + .textSelection(.enabled) Button { viewStore.send(.messenger(.start)) } label: { diff --git a/Examples/xx-messenger/Tests/AppCoreTests/ReceiveFileHandler/ReceiveFileHandlerTests.swift b/Examples/xx-messenger/Tests/AppCoreTests/ReceiveFileHandler/ReceiveFileHandlerTests.swift index 6d54a9cfcc27db703a70f723b29bbc0833e1f5b1..2c687e00245825856077a5aa186bfa3638f9a6e8 100644 --- a/Examples/xx-messenger/Tests/AppCoreTests/ReceiveFileHandler/ReceiveFileHandlerTests.swift +++ b/Examples/xx-messenger/Tests/AppCoreTests/ReceiveFileHandler/ReceiveFileHandlerTests.swift @@ -124,7 +124,7 @@ final class ReceiveFileHandlerTests: XCTestCase { actions = [] let receivingFileError = NSError(domain: "receiving-file", code: 2) - receivingFileCallback?(.failed(.receiveError(receivingFileError))) + receivingFileCallback?(.failed(.receive(receivingFileError))) XCTAssertNoDifference(actions, [ .didCatchError(receivingFileError) @@ -132,20 +132,12 @@ final class ReceiveFileHandlerTests: XCTestCase { actions = [] let receivingFileCallbackError = NSError(domain: "receiving-file-callback", code: 3) - receivingFileCallback?(.failed(.callbackError(receivingFileCallbackError))) + receivingFileCallback?(.failed(.callback(receivingFileCallbackError))) XCTAssertNoDifference(actions, [ .didCatchError(receivingFileCallbackError) ]) - actions = [] - let receivingFileProgressError = "receiving-file-progress" - receivingFileCallback?(.failed(.progressError(receivingFileProgressError))) - - XCTAssertNoDifference(actions, [ - .didCatchError(ReceiveFileHandler.ProgressError(message: receivingFileProgressError) as NSError) - ]) - actions = [] receivingFileCallback?(.progress(transmitted: 1, total: 2)) diff --git a/Examples/xx-messenger/Tests/AppCoreTests/SendImage/SendImageTests.swift b/Examples/xx-messenger/Tests/AppCoreTests/SendImage/SendImageTests.swift index d1cb1741abe2ffdbd2f4481800ca8529943cb9df..3d3b306415c4cd470fb79cd4bab1592cf0c082a6 100644 --- a/Examples/xx-messenger/Tests/AppCoreTests/SendImage/SendImageTests.swift +++ b/Examples/xx-messenger/Tests/AppCoreTests/SendImage/SendImageTests.swift @@ -98,7 +98,7 @@ final class SendImageTests: XCTestCase { actions = [] let sendError = NSError(domain: "send-error", code: 1) - sendFileCallback?(.failed(id: transferId, .error(sendError))) + sendFileCallback?(.failed(id: transferId, .callback(sendError))) XCTAssertNoDifference(actions, [ .didFail(sendError), @@ -112,14 +112,6 @@ final class SendImageTests: XCTestCase { .didFail(closeError), ]) - actions = [] - let progressError = "progress-error" - sendFileCallback?(.failed(id: transferId, .progressError(progressError))) - - XCTAssertNoDifference(actions, [ - .didFail(SendImage.ProgressError(message: progressError) as NSError), - ]) - actions = [] sendFileCallback?(.progress(id: transferId, transmitted: 1, total: 2)) diff --git a/Frameworks/Bindings.txt b/Frameworks/Bindings.txt index 4a3541b0c1d545d625c05ae1246334fecbfa046a..3c0c95da8eaf034c94d2911d77a7571013b6bed6 100644 --- a/Frameworks/Bindings.txt +++ b/Frameworks/Bindings.txt @@ -1,4 +1,4 @@ -https://git.xx.network/elixxir/client/-/commit/835afaaaaef3d98a5a0da5e608f583d4617bf754 +https://git.xx.network/elixxir/client/-/commit/0ac9136c14e1907710946e23949aad261e0be82a go version go1.17.13 darwin/arm64 Xcode 14.1 Build version 14B47b gomobile bind target: ios,iossimulator,macos diff --git a/Frameworks/Bindings.xcframework/Info.plist b/Frameworks/Bindings.xcframework/Info.plist index ab0338a02ded757edb59566001da4efa827302aa..3d81013ba0ba606da4b42b6f3119f688c6d9b97d 100644 --- a/Frameworks/Bindings.xcframework/Info.plist +++ b/Frameworks/Bindings.xcframework/Info.plist @@ -6,15 +6,18 @@ <array> <dict> <key>LibraryIdentifier</key> - <string>ios-arm64</string> + <string>ios-arm64_x86_64-simulator</string> <key>LibraryPath</key> <string>Bindings.framework</string> <key>SupportedArchitectures</key> <array> <string>arm64</string> + <string>x86_64</string> </array> <key>SupportedPlatform</key> <string>ios</string> + <key>SupportedPlatformVariant</key> + <string>simulator</string> </dict> <dict> <key>LibraryIdentifier</key> @@ -31,18 +34,15 @@ </dict> <dict> <key>LibraryIdentifier</key> - <string>ios-arm64_x86_64-simulator</string> + <string>ios-arm64</string> <key>LibraryPath</key> <string>Bindings.framework</string> <key>SupportedArchitectures</key> <array> <string>arm64</string> - <string>x86_64</string> </array> <key>SupportedPlatform</key> <string>ios</string> - <key>SupportedPlatformVariant</key> - <string>simulator</string> </dict> </array> <key>CFBundlePackageType</key> diff --git a/Frameworks/Bindings.xcframework/ios-arm64/Bindings.framework/Versions/A/Bindings b/Frameworks/Bindings.xcframework/ios-arm64/Bindings.framework/Versions/A/Bindings index fa8580e72215d38590f7f0975d6f6ea31602c376..b60abe52e5edc1148e469b45a9fde5f0f05d8e92 100644 Binary files a/Frameworks/Bindings.xcframework/ios-arm64/Bindings.framework/Versions/A/Bindings and b/Frameworks/Bindings.xcframework/ios-arm64/Bindings.framework/Versions/A/Bindings differ diff --git a/Frameworks/Bindings.xcframework/ios-arm64/Bindings.framework/Versions/A/Headers/Bindings.objc.h b/Frameworks/Bindings.xcframework/ios-arm64/Bindings.framework/Versions/A/Headers/Bindings.objc.h index 8c041875c58f46b06bf6e9517453a28f8ffdbdda..0870dbbbb626c1dc4c5e030f6fec29a9e363c6cb 100644 --- a/Frameworks/Bindings.xcframework/ios-arm64/Bindings.framework/Versions/A/Headers/Bindings.objc.h +++ b/Frameworks/Bindings.xcframework/ios-arm64/Bindings.framework/Versions/A/Headers/Bindings.objc.h @@ -252,24 +252,34 @@ Statuses will be enumerated as such: @protocol BindingsFileTransferReceiveProgressCallback <NSObject> /** - * Callback is called when a file part is sent or an error occurs. + * Callback is called when a file part is received or an error occurs. Once +a transfer completes, the file can be received using +[FileTransfer.Receive]. Parameters: - - payload - the JSON marshalled bytes of a Progress object. - - t - tracker that allows the lookup of the status of any file part - - err - any errors that occurred during sending + - payload - JSON of [Progress], which describes the progress of the + current transfer. + - t - file part tracker that allows the lookup of the status of + individual file parts. + - err - Fatal errors during receiving. If an error is returned, the + transfer has failed and will not resume. */ - (void)callback:(NSData* _Nullable)payload t:(BindingsFilePartTracker* _Nullable)t err:(NSError* _Nullable)err; @end @protocol BindingsFileTransferSentProgressCallback <NSObject> /** - * Callback is called when a file part is sent or an error occurs. + * Callback is called when a file part is sent or an error occurs. Once a +transfer completes, it should be closed using [FileTransfer.CloseSend]. Parameters: - - payload - the JSON marshalled bytes of a Progress object. - - t - tracker that allows the lookup of the status of any file part - - err - any errors that occurred during sending + - payload - JSON of [Progress], which describes the progress of the + current transfer. + - t - file part tracker that allows the lookup of the status of + individual file parts. + - err - Fatal errors during sending. If an error is returned, the + transfer has failed and will not resume. It must be cleared using + [FileTransfer.CloseSend]. */ - (void)callback:(NSData* _Nullable)payload t:(BindingsFilePartTracker* _Nullable)t err:(NSError* _Nullable)err; @end @@ -319,10 +329,10 @@ Parameters: * Callback is called when a new file transfer is received. Parameters: - - payload - the JSON marshalled bytes of a ReceivedFile object. - - err - any errors that occurred during reception + - payload - JSON of [ReceivedFile], which contains information about the + incoming file transfer. */ -- (void)callback:(NSData* _Nullable)payload err:(NSError* _Nullable)err; +- (void)callback:(NSData* _Nullable)payload; @end @protocol BindingsReporterFunc <NSObject> @@ -1480,10 +1490,10 @@ report. Example JSON: { - "Priority":1, - "Category":"Test Events", - "EventType":"Ping", - "Details":"This is an example of an event report" + "Priority": 1, + "Category": "Test Events", + "EventType": "Ping", + "Details": "This is an example of an event report" } */ @interface BindingsEventReport : NSObject <goSeqRefInterface> { @@ -1524,13 +1534,15 @@ The possible values for the status are: @end /** - * FileSend is a public struct that contains the file contents and its name, -type, and preview. + * FileSend contains the file and its metadata to send. This structure is JSON +marshalled and passed as the payload to [FileTransfer.Send]. + +Example JSON: { - "Name":"testfile.txt", - "Type":"text file", - "Preview":"aXQncyBtZSBhIHByZXZpZXc=", - "Contents":"VGhpcyBpcyB0aGUgZnVsbCBjb250ZW50cyBvZiB0aGUgZmlsZSBpbiBieXRlcw==" + "Name": "testfile.txt", + "Type": "text file", + "Preview": "RMlsZSBwCmV2aWV3Lg==", + "Contents": "RMlsZSBjb250ZW50cy4=" } */ @interface BindingsFileSend : NSObject <goSeqRefInterface> { @@ -1539,15 +1551,31 @@ type, and preview. - (nonnull instancetype)initWithRef:(_Nonnull id)ref; - (nonnull instancetype)init; +/** + * Name is the human-readable file name. Get max length from +[FileTransfer.MaxFileNameLen]. + */ @property (nonatomic) NSString* _Nonnull name; +/** + * Type is a shorthand that identifies the type of file. Get max length from +[FileTransfer.MaxFileTypeLen]. + */ @property (nonatomic) NSString* _Nonnull type; +/** + * Preview of the file data (e.g. a thumbnail). Get max length from +[FileTransfer.MaxPreviewSize]. + */ @property (nonatomic) NSData* _Nullable preview; +/** + * Contents is the full file contents. Get max length from +[FileTransfer.MaxFileSize]. + */ @property (nonatomic) NSData* _Nullable contents; @end /** * FileTransfer object is a bindings-layer struct which wraps a -fileTransfer.FileTransfer interface. +[fileTransfer.FileTransfer] interface. */ @interface BindingsFileTransfer : NSObject <goSeqRefInterface> { } @@ -1557,14 +1585,14 @@ fileTransfer.FileTransfer interface. - (nonnull instancetype)init; /** * CloseSend deletes a file from the internal storage once a transfer has -completed or reached the retry limit. Returns an error if the transfer has -not run out of retries. +completed or reached the retry limit. If neither of those condition are met, +an error is returned. This function should be called once a transfer completes or errors out (as reported by the progress callback). Parameters: - - tidBytes - file transfer ID + - tidBytes - the file transfer's unique [fileTransfer.TransferID]. */ - (BOOL)closeSend:(NSData* _Nullable)tidBytes error:(NSError* _Nullable* _Nullable)error; /** @@ -1586,59 +1614,87 @@ Parameters: /** * Receive returns the full file on the completion of the transfer. It deletes internal references to the data and unregisters any attached progress -callbacks. Returns an error if the transfer is not complete, the full file +callback. Returns an error if the transfer is not complete, the full file cannot be verified, or if the transfer cannot be found. -Receive can only be called once the progress callback returns that the -file transfer is complete. +Receive can only be called once the progress callback returns that the file +transfer is complete. Parameters: - - tidBytes - file transfer ID + - tidBytes - The file transfer's unique [fileTransfer.TransferID]. */ - (NSData* _Nullable)receive:(NSData* _Nullable)tidBytes error:(NSError* _Nullable* _Nullable)error; /** * RegisterReceivedProgressCallback allows for the registration of a callback to track the progress of an individual received file transfer. -This should be done when a new transfer is received on the ReceiveCallback. +The callback will be called immediately when added to report the current +progress of the transfer. It will then call every time a file part is +received, the transfer completes, or a fatal error occurs. It is called at +most once every period regardless of the number of progress updates. + +In the event that the client is closed and resumed, this function must be +used to re-register any callbacks previously registered. + +Once the callback reports that the transfer has completed, the recipient can +get the full file by calling Receive. Parameters: - - tidBytes - file transfer ID - - callback - callback that reports file reception progress - - period - Duration (in ms) to wait between progress callbacks triggering. - This value should depend on how frequently you want to receive updates, - and should be tuned to your implementation. + - tidBytes - The file transfer's unique [fileTransfer.TransferID]. + - callback - A callback that reports the progress of the file transfer. The + callback is called once on initialization, on every progress update (or + less if restricted by the period), or on fatal error. + - period - The progress callback will be limited from triggering only once + per period. It is a duration in milliseconds. This value should depend on + how frequently you want to receive updates, and should be tuned to your + implementation. */ - (BOOL)registerReceivedProgressCallback:(NSData* _Nullable)tidBytes callback:(id<BindingsFileTransferReceiveProgressCallback> _Nullable)callback period:(long)period error:(NSError* _Nullable* _Nullable)error; /** * RegisterSentProgressCallback allows for the registration of a callback to track the progress of an individual sent file transfer. -SentProgressCallback is auto registered on Send; this function should be -called when resuming clients or registering extra callbacks. +The callback will be called immediately when added to report the current +progress of the transfer. It will then call every time a file part +arrives, the transfer completes, or a fatal error occurs. It is called at +most once every period regardless of the number of progress updates. + +In the event that the client is closed and resumed, this function must be +used to re-register any callbacks previously registered with this +function or Send. Parameters: - - tidBytes - file transfer ID - - callback - callback that reports file reception progress - - period - Duration (in ms) to wait between progress callbacks triggering. - This value should depend on how frequently you want to receive updates, - and should be tuned to your implementation. + - tidBytes - The file transfer's unique [fileTransfer.TransferID]. + - callback - A callback that reports the progress of the file transfer. The + callback is called once on initialization, on every progress update (or + less if restricted by the period), or on fatal error. + - period - The progress callback will be limited from triggering only once + per period. It is a duration in milliseconds. This value should depend on + how frequently you want to receive updates, and should be tuned to your + implementation. */ - (BOOL)registerSentProgressCallback:(NSData* _Nullable)tidBytes callback:(id<BindingsFileTransferSentProgressCallback> _Nullable)callback period:(long)period error:(NSError* _Nullable* _Nullable)error; /** - * Send is the bindings-level function for sending a file. + * Send initiates the sending of a file to a recipient and returns a transfer ID +that uniquely identifies this file transfer. Progress for the file transfer +is reported to that passed in callback. Parameters: - - payload - JSON marshalled FileSend - - recipientID - marshalled recipient id.ID - - retry - number of retries allowed - - callback - callback that reports file sending progress - - period - Duration (in ms) to wait between progress callbacks triggering. - This value should depend on how frequently you want to receive updates, - and should be tuned to your implementation. + - payload - JSON of [FileSend], which contains the file contents and its + metadata. + - recipientID - marshalled bytes of the recipient's [id.ID]. + - retry - The number of sending retries allowed on send failure (e.g. a + retry of 2.0 with 6 parts means 12 total possible sends). + - callback - A callback that reports the progress of the file transfer. The + callback is called once on initialization, on every progress update (or + less if restricted by the period), or on fatal error. + - period - The progress callback will be limited from triggering only once + per period. It is a duration in milliseconds. This value should depend on + how frequently you want to receive updates, and should be tuned to your + implementation. Returns: - - []byte - unique file transfer ID + - The bytes of the unique [fileTransfer.TransferID]. */ - (NSData* _Nullable)send:(NSData* _Nullable)payload recipientID:(NSData* _Nullable)recipientID retry:(float)retry callback:(id<BindingsFileTransferSentProgressCallback> _Nullable)callback period:(long)period error:(NSError* _Nullable* _Nullable)error; @end @@ -2025,15 +2081,16 @@ false, this report may be ignored. @end /** - * Progress is a public struct that represents the progress of an in-progress -file transfer. + * Progress contains the progress information of a transfer. It is returned by +[FileTransferSentProgressCallback.Callback] and +[FileTransferReceiveProgressCallback.Callback]. Example JSON: { - "Completed":false, - "Transmitted":128, - "Total":2048, - "Err":null + "TransferID": "RyJcMqtI3IIM1+YMxRwCcFiOX6AGuIzS+vQaPnqXVT8=", + "Completed": false, + "Transmitted": 128, + "Total": 2048 } */ @interface BindingsProgress : NSObject <goSeqRefInterface> { @@ -2042,10 +2099,11 @@ Example JSON: - (nonnull instancetype)initWithRef:(_Nonnull id)ref; - (nonnull instancetype)init; +// skipped field Progress.TransferID with unsupported type: *gitlab.com/elixxir/crypto/fileTransfer.TransferID + @property (nonatomic) BOOL completed; @property (nonatomic) long transmitted; @property (nonatomic) long total; -@property (nonatomic) NSError* _Nullable err; @end /** @@ -2088,17 +2146,18 @@ JSON Example: @end /** - * ReceivedFile is a public struct that contains the metadata of a new file -transfer. + * ReceivedFile contains the metadata of a new received file transfer. It is +received from a sender on a new file transfer. It is returned by +[ReceiveFileCallback.Callback]. Example JSON: { - "TransferID":"B4Z9cwU18beRoGbk5xBjbcd5Ryi9ZUFA2UBvi8FOHWo=", - "SenderID":"emV6aW1hAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD", - "Preview":"aXQncyBtZSBhIHByZXZpZXc=", - "Name":"testfile.txt", - "Type":"text file", - "Size":2048 + "TransferID": "0U+QY1nMOUzQGxGpqZyxDw8Cd6+qm8t870CzLtVoUM8=", + "SenderID": "UL3+S8XdJHAfUtCUm7iZMxW8orR8Nd5JM9Ky7/5jds8D", + "Preview": "aXQNcyBtZSBhIHByZXZpZXc=", + "Name": "testfile.txt", + "Type": "text file", + "Size": 2048 } */ @interface BindingsReceivedFile : NSObject <goSeqRefInterface> { @@ -2107,8 +2166,10 @@ Example JSON: - (nonnull instancetype)initWithRef:(_Nonnull id)ref; - (nonnull instancetype)init; -@property (nonatomic) NSData* _Nullable transferID; -@property (nonatomic) NSData* _Nullable senderID; +// skipped field ReceivedFile.TransferID with unsupported type: *gitlab.com/elixxir/crypto/fileTransfer.TransferID + +// skipped field ReceivedFile.SenderID with unsupported type: *gitlab.com/xx_network/primitives/id.ID + @property (nonatomic) NSData* _Nullable preview; @property (nonatomic) NSString* _Nonnull name; @property (nonatomic) NSString* _Nonnull type; @@ -2759,8 +2820,15 @@ FOUNDATION_EXPORT NSData* _Nullable BindingsImportPrivateIdentity(NSString* _Nul * InitFileTransfer creates a bindings-level file transfer manager. Parameters: - - e2eID - e2e object ID in the tracker - - paramsJSON - JSON marshalled fileTransfer.Params + - e2eID - ID of [E2e] object in tracker. + - receiveFileCallback - A callback that is called when a new file transfer + is received. + - e2eFileTransferParamsJson - JSON of + [gitlab.com/elixxir/client/fileTransfer/e2e.Params]. + - fileTransferParamsJson - JSON of [fileTransfer.Params]. + +Returns: + - New [FileTransfer] object. */ FOUNDATION_EXPORT BindingsFileTransfer* _Nullable BindingsInitFileTransfer(long e2eID, id<BindingsReceiveFileCallback> _Nullable receiveFileCallback, NSData* _Nullable e2eFileTransferParamsJson, NSData* _Nullable fileTransferParamsJson, NSError* _Nullable* _Nullable error); @@ -3521,12 +3589,17 @@ called with the progress of a received file. - (nonnull instancetype)initWithRef:(_Nonnull id)ref; /** - * Callback is called when a file part is sent or an error occurs. + * Callback is called when a file part is received or an error occurs. Once +a transfer completes, the file can be received using +[FileTransfer.Receive]. Parameters: - - payload - the JSON marshalled bytes of a Progress object. - - t - tracker that allows the lookup of the status of any file part - - err - any errors that occurred during sending + - payload - JSON of [Progress], which describes the progress of the + current transfer. + - t - file part tracker that allows the lookup of the status of + individual file parts. + - err - Fatal errors during receiving. If an error is returned, the + transfer has failed and will not resume. */ - (void)callback:(NSData* _Nullable)payload t:(BindingsFilePartTracker* _Nullable)t err:(NSError* _Nullable)err; @end @@ -3541,12 +3614,17 @@ a callback that is called when the sent progress updates. - (nonnull instancetype)initWithRef:(_Nonnull id)ref; /** - * Callback is called when a file part is sent or an error occurs. + * Callback is called when a file part is sent or an error occurs. Once a +transfer completes, it should be closed using [FileTransfer.CloseSend]. Parameters: - - payload - the JSON marshalled bytes of a Progress object. - - t - tracker that allows the lookup of the status of any file part - - err - any errors that occurred during sending + - payload - JSON of [Progress], which describes the progress of the + current transfer. + - t - file part tracker that allows the lookup of the status of + individual file parts. + - err - Fatal errors during sending. If an error is returned, the + transfer has failed and will not resume. It must be cleared using + [FileTransfer.CloseSend]. */ - (void)callback:(NSData* _Nullable)payload t:(BindingsFilePartTracker* _Nullable)t err:(NSError* _Nullable)err; @end @@ -3665,10 +3743,10 @@ that is called when a file is received. * Callback is called when a new file transfer is received. Parameters: - - payload - the JSON marshalled bytes of a ReceivedFile object. - - err - any errors that occurred during reception + - payload - JSON of [ReceivedFile], which contains information about the + incoming file transfer. */ -- (void)callback:(NSData* _Nullable)payload err:(NSError* _Nullable)err; +- (void)callback:(NSData* _Nullable)payload; @end /** diff --git a/Frameworks/Bindings.xcframework/ios-arm64_x86_64-simulator/Bindings.framework/Versions/A/Bindings b/Frameworks/Bindings.xcframework/ios-arm64_x86_64-simulator/Bindings.framework/Versions/A/Bindings index 4a70346940a38483b3345189f6d0290341ec10e1..2c2e2605ab374ad50a62ea4dc763eb2e8046045a 100644 Binary files a/Frameworks/Bindings.xcframework/ios-arm64_x86_64-simulator/Bindings.framework/Versions/A/Bindings and b/Frameworks/Bindings.xcframework/ios-arm64_x86_64-simulator/Bindings.framework/Versions/A/Bindings differ diff --git a/Frameworks/Bindings.xcframework/ios-arm64_x86_64-simulator/Bindings.framework/Versions/A/Headers/Bindings.objc.h b/Frameworks/Bindings.xcframework/ios-arm64_x86_64-simulator/Bindings.framework/Versions/A/Headers/Bindings.objc.h index 8c041875c58f46b06bf6e9517453a28f8ffdbdda..0870dbbbb626c1dc4c5e030f6fec29a9e363c6cb 100644 --- a/Frameworks/Bindings.xcframework/ios-arm64_x86_64-simulator/Bindings.framework/Versions/A/Headers/Bindings.objc.h +++ b/Frameworks/Bindings.xcframework/ios-arm64_x86_64-simulator/Bindings.framework/Versions/A/Headers/Bindings.objc.h @@ -252,24 +252,34 @@ Statuses will be enumerated as such: @protocol BindingsFileTransferReceiveProgressCallback <NSObject> /** - * Callback is called when a file part is sent or an error occurs. + * Callback is called when a file part is received or an error occurs. Once +a transfer completes, the file can be received using +[FileTransfer.Receive]. Parameters: - - payload - the JSON marshalled bytes of a Progress object. - - t - tracker that allows the lookup of the status of any file part - - err - any errors that occurred during sending + - payload - JSON of [Progress], which describes the progress of the + current transfer. + - t - file part tracker that allows the lookup of the status of + individual file parts. + - err - Fatal errors during receiving. If an error is returned, the + transfer has failed and will not resume. */ - (void)callback:(NSData* _Nullable)payload t:(BindingsFilePartTracker* _Nullable)t err:(NSError* _Nullable)err; @end @protocol BindingsFileTransferSentProgressCallback <NSObject> /** - * Callback is called when a file part is sent or an error occurs. + * Callback is called when a file part is sent or an error occurs. Once a +transfer completes, it should be closed using [FileTransfer.CloseSend]. Parameters: - - payload - the JSON marshalled bytes of a Progress object. - - t - tracker that allows the lookup of the status of any file part - - err - any errors that occurred during sending + - payload - JSON of [Progress], which describes the progress of the + current transfer. + - t - file part tracker that allows the lookup of the status of + individual file parts. + - err - Fatal errors during sending. If an error is returned, the + transfer has failed and will not resume. It must be cleared using + [FileTransfer.CloseSend]. */ - (void)callback:(NSData* _Nullable)payload t:(BindingsFilePartTracker* _Nullable)t err:(NSError* _Nullable)err; @end @@ -319,10 +329,10 @@ Parameters: * Callback is called when a new file transfer is received. Parameters: - - payload - the JSON marshalled bytes of a ReceivedFile object. - - err - any errors that occurred during reception + - payload - JSON of [ReceivedFile], which contains information about the + incoming file transfer. */ -- (void)callback:(NSData* _Nullable)payload err:(NSError* _Nullable)err; +- (void)callback:(NSData* _Nullable)payload; @end @protocol BindingsReporterFunc <NSObject> @@ -1480,10 +1490,10 @@ report. Example JSON: { - "Priority":1, - "Category":"Test Events", - "EventType":"Ping", - "Details":"This is an example of an event report" + "Priority": 1, + "Category": "Test Events", + "EventType": "Ping", + "Details": "This is an example of an event report" } */ @interface BindingsEventReport : NSObject <goSeqRefInterface> { @@ -1524,13 +1534,15 @@ The possible values for the status are: @end /** - * FileSend is a public struct that contains the file contents and its name, -type, and preview. + * FileSend contains the file and its metadata to send. This structure is JSON +marshalled and passed as the payload to [FileTransfer.Send]. + +Example JSON: { - "Name":"testfile.txt", - "Type":"text file", - "Preview":"aXQncyBtZSBhIHByZXZpZXc=", - "Contents":"VGhpcyBpcyB0aGUgZnVsbCBjb250ZW50cyBvZiB0aGUgZmlsZSBpbiBieXRlcw==" + "Name": "testfile.txt", + "Type": "text file", + "Preview": "RMlsZSBwCmV2aWV3Lg==", + "Contents": "RMlsZSBjb250ZW50cy4=" } */ @interface BindingsFileSend : NSObject <goSeqRefInterface> { @@ -1539,15 +1551,31 @@ type, and preview. - (nonnull instancetype)initWithRef:(_Nonnull id)ref; - (nonnull instancetype)init; +/** + * Name is the human-readable file name. Get max length from +[FileTransfer.MaxFileNameLen]. + */ @property (nonatomic) NSString* _Nonnull name; +/** + * Type is a shorthand that identifies the type of file. Get max length from +[FileTransfer.MaxFileTypeLen]. + */ @property (nonatomic) NSString* _Nonnull type; +/** + * Preview of the file data (e.g. a thumbnail). Get max length from +[FileTransfer.MaxPreviewSize]. + */ @property (nonatomic) NSData* _Nullable preview; +/** + * Contents is the full file contents. Get max length from +[FileTransfer.MaxFileSize]. + */ @property (nonatomic) NSData* _Nullable contents; @end /** * FileTransfer object is a bindings-layer struct which wraps a -fileTransfer.FileTransfer interface. +[fileTransfer.FileTransfer] interface. */ @interface BindingsFileTransfer : NSObject <goSeqRefInterface> { } @@ -1557,14 +1585,14 @@ fileTransfer.FileTransfer interface. - (nonnull instancetype)init; /** * CloseSend deletes a file from the internal storage once a transfer has -completed or reached the retry limit. Returns an error if the transfer has -not run out of retries. +completed or reached the retry limit. If neither of those condition are met, +an error is returned. This function should be called once a transfer completes or errors out (as reported by the progress callback). Parameters: - - tidBytes - file transfer ID + - tidBytes - the file transfer's unique [fileTransfer.TransferID]. */ - (BOOL)closeSend:(NSData* _Nullable)tidBytes error:(NSError* _Nullable* _Nullable)error; /** @@ -1586,59 +1614,87 @@ Parameters: /** * Receive returns the full file on the completion of the transfer. It deletes internal references to the data and unregisters any attached progress -callbacks. Returns an error if the transfer is not complete, the full file +callback. Returns an error if the transfer is not complete, the full file cannot be verified, or if the transfer cannot be found. -Receive can only be called once the progress callback returns that the -file transfer is complete. +Receive can only be called once the progress callback returns that the file +transfer is complete. Parameters: - - tidBytes - file transfer ID + - tidBytes - The file transfer's unique [fileTransfer.TransferID]. */ - (NSData* _Nullable)receive:(NSData* _Nullable)tidBytes error:(NSError* _Nullable* _Nullable)error; /** * RegisterReceivedProgressCallback allows for the registration of a callback to track the progress of an individual received file transfer. -This should be done when a new transfer is received on the ReceiveCallback. +The callback will be called immediately when added to report the current +progress of the transfer. It will then call every time a file part is +received, the transfer completes, or a fatal error occurs. It is called at +most once every period regardless of the number of progress updates. + +In the event that the client is closed and resumed, this function must be +used to re-register any callbacks previously registered. + +Once the callback reports that the transfer has completed, the recipient can +get the full file by calling Receive. Parameters: - - tidBytes - file transfer ID - - callback - callback that reports file reception progress - - period - Duration (in ms) to wait between progress callbacks triggering. - This value should depend on how frequently you want to receive updates, - and should be tuned to your implementation. + - tidBytes - The file transfer's unique [fileTransfer.TransferID]. + - callback - A callback that reports the progress of the file transfer. The + callback is called once on initialization, on every progress update (or + less if restricted by the period), or on fatal error. + - period - The progress callback will be limited from triggering only once + per period. It is a duration in milliseconds. This value should depend on + how frequently you want to receive updates, and should be tuned to your + implementation. */ - (BOOL)registerReceivedProgressCallback:(NSData* _Nullable)tidBytes callback:(id<BindingsFileTransferReceiveProgressCallback> _Nullable)callback period:(long)period error:(NSError* _Nullable* _Nullable)error; /** * RegisterSentProgressCallback allows for the registration of a callback to track the progress of an individual sent file transfer. -SentProgressCallback is auto registered on Send; this function should be -called when resuming clients or registering extra callbacks. +The callback will be called immediately when added to report the current +progress of the transfer. It will then call every time a file part +arrives, the transfer completes, or a fatal error occurs. It is called at +most once every period regardless of the number of progress updates. + +In the event that the client is closed and resumed, this function must be +used to re-register any callbacks previously registered with this +function or Send. Parameters: - - tidBytes - file transfer ID - - callback - callback that reports file reception progress - - period - Duration (in ms) to wait between progress callbacks triggering. - This value should depend on how frequently you want to receive updates, - and should be tuned to your implementation. + - tidBytes - The file transfer's unique [fileTransfer.TransferID]. + - callback - A callback that reports the progress of the file transfer. The + callback is called once on initialization, on every progress update (or + less if restricted by the period), or on fatal error. + - period - The progress callback will be limited from triggering only once + per period. It is a duration in milliseconds. This value should depend on + how frequently you want to receive updates, and should be tuned to your + implementation. */ - (BOOL)registerSentProgressCallback:(NSData* _Nullable)tidBytes callback:(id<BindingsFileTransferSentProgressCallback> _Nullable)callback period:(long)period error:(NSError* _Nullable* _Nullable)error; /** - * Send is the bindings-level function for sending a file. + * Send initiates the sending of a file to a recipient and returns a transfer ID +that uniquely identifies this file transfer. Progress for the file transfer +is reported to that passed in callback. Parameters: - - payload - JSON marshalled FileSend - - recipientID - marshalled recipient id.ID - - retry - number of retries allowed - - callback - callback that reports file sending progress - - period - Duration (in ms) to wait between progress callbacks triggering. - This value should depend on how frequently you want to receive updates, - and should be tuned to your implementation. + - payload - JSON of [FileSend], which contains the file contents and its + metadata. + - recipientID - marshalled bytes of the recipient's [id.ID]. + - retry - The number of sending retries allowed on send failure (e.g. a + retry of 2.0 with 6 parts means 12 total possible sends). + - callback - A callback that reports the progress of the file transfer. The + callback is called once on initialization, on every progress update (or + less if restricted by the period), or on fatal error. + - period - The progress callback will be limited from triggering only once + per period. It is a duration in milliseconds. This value should depend on + how frequently you want to receive updates, and should be tuned to your + implementation. Returns: - - []byte - unique file transfer ID + - The bytes of the unique [fileTransfer.TransferID]. */ - (NSData* _Nullable)send:(NSData* _Nullable)payload recipientID:(NSData* _Nullable)recipientID retry:(float)retry callback:(id<BindingsFileTransferSentProgressCallback> _Nullable)callback period:(long)period error:(NSError* _Nullable* _Nullable)error; @end @@ -2025,15 +2081,16 @@ false, this report may be ignored. @end /** - * Progress is a public struct that represents the progress of an in-progress -file transfer. + * Progress contains the progress information of a transfer. It is returned by +[FileTransferSentProgressCallback.Callback] and +[FileTransferReceiveProgressCallback.Callback]. Example JSON: { - "Completed":false, - "Transmitted":128, - "Total":2048, - "Err":null + "TransferID": "RyJcMqtI3IIM1+YMxRwCcFiOX6AGuIzS+vQaPnqXVT8=", + "Completed": false, + "Transmitted": 128, + "Total": 2048 } */ @interface BindingsProgress : NSObject <goSeqRefInterface> { @@ -2042,10 +2099,11 @@ Example JSON: - (nonnull instancetype)initWithRef:(_Nonnull id)ref; - (nonnull instancetype)init; +// skipped field Progress.TransferID with unsupported type: *gitlab.com/elixxir/crypto/fileTransfer.TransferID + @property (nonatomic) BOOL completed; @property (nonatomic) long transmitted; @property (nonatomic) long total; -@property (nonatomic) NSError* _Nullable err; @end /** @@ -2088,17 +2146,18 @@ JSON Example: @end /** - * ReceivedFile is a public struct that contains the metadata of a new file -transfer. + * ReceivedFile contains the metadata of a new received file transfer. It is +received from a sender on a new file transfer. It is returned by +[ReceiveFileCallback.Callback]. Example JSON: { - "TransferID":"B4Z9cwU18beRoGbk5xBjbcd5Ryi9ZUFA2UBvi8FOHWo=", - "SenderID":"emV6aW1hAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD", - "Preview":"aXQncyBtZSBhIHByZXZpZXc=", - "Name":"testfile.txt", - "Type":"text file", - "Size":2048 + "TransferID": "0U+QY1nMOUzQGxGpqZyxDw8Cd6+qm8t870CzLtVoUM8=", + "SenderID": "UL3+S8XdJHAfUtCUm7iZMxW8orR8Nd5JM9Ky7/5jds8D", + "Preview": "aXQNcyBtZSBhIHByZXZpZXc=", + "Name": "testfile.txt", + "Type": "text file", + "Size": 2048 } */ @interface BindingsReceivedFile : NSObject <goSeqRefInterface> { @@ -2107,8 +2166,10 @@ Example JSON: - (nonnull instancetype)initWithRef:(_Nonnull id)ref; - (nonnull instancetype)init; -@property (nonatomic) NSData* _Nullable transferID; -@property (nonatomic) NSData* _Nullable senderID; +// skipped field ReceivedFile.TransferID with unsupported type: *gitlab.com/elixxir/crypto/fileTransfer.TransferID + +// skipped field ReceivedFile.SenderID with unsupported type: *gitlab.com/xx_network/primitives/id.ID + @property (nonatomic) NSData* _Nullable preview; @property (nonatomic) NSString* _Nonnull name; @property (nonatomic) NSString* _Nonnull type; @@ -2759,8 +2820,15 @@ FOUNDATION_EXPORT NSData* _Nullable BindingsImportPrivateIdentity(NSString* _Nul * InitFileTransfer creates a bindings-level file transfer manager. Parameters: - - e2eID - e2e object ID in the tracker - - paramsJSON - JSON marshalled fileTransfer.Params + - e2eID - ID of [E2e] object in tracker. + - receiveFileCallback - A callback that is called when a new file transfer + is received. + - e2eFileTransferParamsJson - JSON of + [gitlab.com/elixxir/client/fileTransfer/e2e.Params]. + - fileTransferParamsJson - JSON of [fileTransfer.Params]. + +Returns: + - New [FileTransfer] object. */ FOUNDATION_EXPORT BindingsFileTransfer* _Nullable BindingsInitFileTransfer(long e2eID, id<BindingsReceiveFileCallback> _Nullable receiveFileCallback, NSData* _Nullable e2eFileTransferParamsJson, NSData* _Nullable fileTransferParamsJson, NSError* _Nullable* _Nullable error); @@ -3521,12 +3589,17 @@ called with the progress of a received file. - (nonnull instancetype)initWithRef:(_Nonnull id)ref; /** - * Callback is called when a file part is sent or an error occurs. + * Callback is called when a file part is received or an error occurs. Once +a transfer completes, the file can be received using +[FileTransfer.Receive]. Parameters: - - payload - the JSON marshalled bytes of a Progress object. - - t - tracker that allows the lookup of the status of any file part - - err - any errors that occurred during sending + - payload - JSON of [Progress], which describes the progress of the + current transfer. + - t - file part tracker that allows the lookup of the status of + individual file parts. + - err - Fatal errors during receiving. If an error is returned, the + transfer has failed and will not resume. */ - (void)callback:(NSData* _Nullable)payload t:(BindingsFilePartTracker* _Nullable)t err:(NSError* _Nullable)err; @end @@ -3541,12 +3614,17 @@ a callback that is called when the sent progress updates. - (nonnull instancetype)initWithRef:(_Nonnull id)ref; /** - * Callback is called when a file part is sent or an error occurs. + * Callback is called when a file part is sent or an error occurs. Once a +transfer completes, it should be closed using [FileTransfer.CloseSend]. Parameters: - - payload - the JSON marshalled bytes of a Progress object. - - t - tracker that allows the lookup of the status of any file part - - err - any errors that occurred during sending + - payload - JSON of [Progress], which describes the progress of the + current transfer. + - t - file part tracker that allows the lookup of the status of + individual file parts. + - err - Fatal errors during sending. If an error is returned, the + transfer has failed and will not resume. It must be cleared using + [FileTransfer.CloseSend]. */ - (void)callback:(NSData* _Nullable)payload t:(BindingsFilePartTracker* _Nullable)t err:(NSError* _Nullable)err; @end @@ -3665,10 +3743,10 @@ that is called when a file is received. * Callback is called when a new file transfer is received. Parameters: - - payload - the JSON marshalled bytes of a ReceivedFile object. - - err - any errors that occurred during reception + - payload - JSON of [ReceivedFile], which contains information about the + incoming file transfer. */ -- (void)callback:(NSData* _Nullable)payload err:(NSError* _Nullable)err; +- (void)callback:(NSData* _Nullable)payload; @end /** diff --git a/Frameworks/Bindings.xcframework/macos-arm64_x86_64/Bindings.framework/Versions/A/Bindings b/Frameworks/Bindings.xcframework/macos-arm64_x86_64/Bindings.framework/Versions/A/Bindings index 4a86922da0289a505c6db3befc66caab469274cc..c96f35b1be9f90a5f178e08ca6d95cf20c5bf5d9 100644 Binary files a/Frameworks/Bindings.xcframework/macos-arm64_x86_64/Bindings.framework/Versions/A/Bindings and b/Frameworks/Bindings.xcframework/macos-arm64_x86_64/Bindings.framework/Versions/A/Bindings differ diff --git a/Frameworks/Bindings.xcframework/macos-arm64_x86_64/Bindings.framework/Versions/A/Headers/Bindings.objc.h b/Frameworks/Bindings.xcframework/macos-arm64_x86_64/Bindings.framework/Versions/A/Headers/Bindings.objc.h index 8c041875c58f46b06bf6e9517453a28f8ffdbdda..0870dbbbb626c1dc4c5e030f6fec29a9e363c6cb 100644 --- a/Frameworks/Bindings.xcframework/macos-arm64_x86_64/Bindings.framework/Versions/A/Headers/Bindings.objc.h +++ b/Frameworks/Bindings.xcframework/macos-arm64_x86_64/Bindings.framework/Versions/A/Headers/Bindings.objc.h @@ -252,24 +252,34 @@ Statuses will be enumerated as such: @protocol BindingsFileTransferReceiveProgressCallback <NSObject> /** - * Callback is called when a file part is sent or an error occurs. + * Callback is called when a file part is received or an error occurs. Once +a transfer completes, the file can be received using +[FileTransfer.Receive]. Parameters: - - payload - the JSON marshalled bytes of a Progress object. - - t - tracker that allows the lookup of the status of any file part - - err - any errors that occurred during sending + - payload - JSON of [Progress], which describes the progress of the + current transfer. + - t - file part tracker that allows the lookup of the status of + individual file parts. + - err - Fatal errors during receiving. If an error is returned, the + transfer has failed and will not resume. */ - (void)callback:(NSData* _Nullable)payload t:(BindingsFilePartTracker* _Nullable)t err:(NSError* _Nullable)err; @end @protocol BindingsFileTransferSentProgressCallback <NSObject> /** - * Callback is called when a file part is sent or an error occurs. + * Callback is called when a file part is sent or an error occurs. Once a +transfer completes, it should be closed using [FileTransfer.CloseSend]. Parameters: - - payload - the JSON marshalled bytes of a Progress object. - - t - tracker that allows the lookup of the status of any file part - - err - any errors that occurred during sending + - payload - JSON of [Progress], which describes the progress of the + current transfer. + - t - file part tracker that allows the lookup of the status of + individual file parts. + - err - Fatal errors during sending. If an error is returned, the + transfer has failed and will not resume. It must be cleared using + [FileTransfer.CloseSend]. */ - (void)callback:(NSData* _Nullable)payload t:(BindingsFilePartTracker* _Nullable)t err:(NSError* _Nullable)err; @end @@ -319,10 +329,10 @@ Parameters: * Callback is called when a new file transfer is received. Parameters: - - payload - the JSON marshalled bytes of a ReceivedFile object. - - err - any errors that occurred during reception + - payload - JSON of [ReceivedFile], which contains information about the + incoming file transfer. */ -- (void)callback:(NSData* _Nullable)payload err:(NSError* _Nullable)err; +- (void)callback:(NSData* _Nullable)payload; @end @protocol BindingsReporterFunc <NSObject> @@ -1480,10 +1490,10 @@ report. Example JSON: { - "Priority":1, - "Category":"Test Events", - "EventType":"Ping", - "Details":"This is an example of an event report" + "Priority": 1, + "Category": "Test Events", + "EventType": "Ping", + "Details": "This is an example of an event report" } */ @interface BindingsEventReport : NSObject <goSeqRefInterface> { @@ -1524,13 +1534,15 @@ The possible values for the status are: @end /** - * FileSend is a public struct that contains the file contents and its name, -type, and preview. + * FileSend contains the file and its metadata to send. This structure is JSON +marshalled and passed as the payload to [FileTransfer.Send]. + +Example JSON: { - "Name":"testfile.txt", - "Type":"text file", - "Preview":"aXQncyBtZSBhIHByZXZpZXc=", - "Contents":"VGhpcyBpcyB0aGUgZnVsbCBjb250ZW50cyBvZiB0aGUgZmlsZSBpbiBieXRlcw==" + "Name": "testfile.txt", + "Type": "text file", + "Preview": "RMlsZSBwCmV2aWV3Lg==", + "Contents": "RMlsZSBjb250ZW50cy4=" } */ @interface BindingsFileSend : NSObject <goSeqRefInterface> { @@ -1539,15 +1551,31 @@ type, and preview. - (nonnull instancetype)initWithRef:(_Nonnull id)ref; - (nonnull instancetype)init; +/** + * Name is the human-readable file name. Get max length from +[FileTransfer.MaxFileNameLen]. + */ @property (nonatomic) NSString* _Nonnull name; +/** + * Type is a shorthand that identifies the type of file. Get max length from +[FileTransfer.MaxFileTypeLen]. + */ @property (nonatomic) NSString* _Nonnull type; +/** + * Preview of the file data (e.g. a thumbnail). Get max length from +[FileTransfer.MaxPreviewSize]. + */ @property (nonatomic) NSData* _Nullable preview; +/** + * Contents is the full file contents. Get max length from +[FileTransfer.MaxFileSize]. + */ @property (nonatomic) NSData* _Nullable contents; @end /** * FileTransfer object is a bindings-layer struct which wraps a -fileTransfer.FileTransfer interface. +[fileTransfer.FileTransfer] interface. */ @interface BindingsFileTransfer : NSObject <goSeqRefInterface> { } @@ -1557,14 +1585,14 @@ fileTransfer.FileTransfer interface. - (nonnull instancetype)init; /** * CloseSend deletes a file from the internal storage once a transfer has -completed or reached the retry limit. Returns an error if the transfer has -not run out of retries. +completed or reached the retry limit. If neither of those condition are met, +an error is returned. This function should be called once a transfer completes or errors out (as reported by the progress callback). Parameters: - - tidBytes - file transfer ID + - tidBytes - the file transfer's unique [fileTransfer.TransferID]. */ - (BOOL)closeSend:(NSData* _Nullable)tidBytes error:(NSError* _Nullable* _Nullable)error; /** @@ -1586,59 +1614,87 @@ Parameters: /** * Receive returns the full file on the completion of the transfer. It deletes internal references to the data and unregisters any attached progress -callbacks. Returns an error if the transfer is not complete, the full file +callback. Returns an error if the transfer is not complete, the full file cannot be verified, or if the transfer cannot be found. -Receive can only be called once the progress callback returns that the -file transfer is complete. +Receive can only be called once the progress callback returns that the file +transfer is complete. Parameters: - - tidBytes - file transfer ID + - tidBytes - The file transfer's unique [fileTransfer.TransferID]. */ - (NSData* _Nullable)receive:(NSData* _Nullable)tidBytes error:(NSError* _Nullable* _Nullable)error; /** * RegisterReceivedProgressCallback allows for the registration of a callback to track the progress of an individual received file transfer. -This should be done when a new transfer is received on the ReceiveCallback. +The callback will be called immediately when added to report the current +progress of the transfer. It will then call every time a file part is +received, the transfer completes, or a fatal error occurs. It is called at +most once every period regardless of the number of progress updates. + +In the event that the client is closed and resumed, this function must be +used to re-register any callbacks previously registered. + +Once the callback reports that the transfer has completed, the recipient can +get the full file by calling Receive. Parameters: - - tidBytes - file transfer ID - - callback - callback that reports file reception progress - - period - Duration (in ms) to wait between progress callbacks triggering. - This value should depend on how frequently you want to receive updates, - and should be tuned to your implementation. + - tidBytes - The file transfer's unique [fileTransfer.TransferID]. + - callback - A callback that reports the progress of the file transfer. The + callback is called once on initialization, on every progress update (or + less if restricted by the period), or on fatal error. + - period - The progress callback will be limited from triggering only once + per period. It is a duration in milliseconds. This value should depend on + how frequently you want to receive updates, and should be tuned to your + implementation. */ - (BOOL)registerReceivedProgressCallback:(NSData* _Nullable)tidBytes callback:(id<BindingsFileTransferReceiveProgressCallback> _Nullable)callback period:(long)period error:(NSError* _Nullable* _Nullable)error; /** * RegisterSentProgressCallback allows for the registration of a callback to track the progress of an individual sent file transfer. -SentProgressCallback is auto registered on Send; this function should be -called when resuming clients or registering extra callbacks. +The callback will be called immediately when added to report the current +progress of the transfer. It will then call every time a file part +arrives, the transfer completes, or a fatal error occurs. It is called at +most once every period regardless of the number of progress updates. + +In the event that the client is closed and resumed, this function must be +used to re-register any callbacks previously registered with this +function or Send. Parameters: - - tidBytes - file transfer ID - - callback - callback that reports file reception progress - - period - Duration (in ms) to wait between progress callbacks triggering. - This value should depend on how frequently you want to receive updates, - and should be tuned to your implementation. + - tidBytes - The file transfer's unique [fileTransfer.TransferID]. + - callback - A callback that reports the progress of the file transfer. The + callback is called once on initialization, on every progress update (or + less if restricted by the period), or on fatal error. + - period - The progress callback will be limited from triggering only once + per period. It is a duration in milliseconds. This value should depend on + how frequently you want to receive updates, and should be tuned to your + implementation. */ - (BOOL)registerSentProgressCallback:(NSData* _Nullable)tidBytes callback:(id<BindingsFileTransferSentProgressCallback> _Nullable)callback period:(long)period error:(NSError* _Nullable* _Nullable)error; /** - * Send is the bindings-level function for sending a file. + * Send initiates the sending of a file to a recipient and returns a transfer ID +that uniquely identifies this file transfer. Progress for the file transfer +is reported to that passed in callback. Parameters: - - payload - JSON marshalled FileSend - - recipientID - marshalled recipient id.ID - - retry - number of retries allowed - - callback - callback that reports file sending progress - - period - Duration (in ms) to wait between progress callbacks triggering. - This value should depend on how frequently you want to receive updates, - and should be tuned to your implementation. + - payload - JSON of [FileSend], which contains the file contents and its + metadata. + - recipientID - marshalled bytes of the recipient's [id.ID]. + - retry - The number of sending retries allowed on send failure (e.g. a + retry of 2.0 with 6 parts means 12 total possible sends). + - callback - A callback that reports the progress of the file transfer. The + callback is called once on initialization, on every progress update (or + less if restricted by the period), or on fatal error. + - period - The progress callback will be limited from triggering only once + per period. It is a duration in milliseconds. This value should depend on + how frequently you want to receive updates, and should be tuned to your + implementation. Returns: - - []byte - unique file transfer ID + - The bytes of the unique [fileTransfer.TransferID]. */ - (NSData* _Nullable)send:(NSData* _Nullable)payload recipientID:(NSData* _Nullable)recipientID retry:(float)retry callback:(id<BindingsFileTransferSentProgressCallback> _Nullable)callback period:(long)period error:(NSError* _Nullable* _Nullable)error; @end @@ -2025,15 +2081,16 @@ false, this report may be ignored. @end /** - * Progress is a public struct that represents the progress of an in-progress -file transfer. + * Progress contains the progress information of a transfer. It is returned by +[FileTransferSentProgressCallback.Callback] and +[FileTransferReceiveProgressCallback.Callback]. Example JSON: { - "Completed":false, - "Transmitted":128, - "Total":2048, - "Err":null + "TransferID": "RyJcMqtI3IIM1+YMxRwCcFiOX6AGuIzS+vQaPnqXVT8=", + "Completed": false, + "Transmitted": 128, + "Total": 2048 } */ @interface BindingsProgress : NSObject <goSeqRefInterface> { @@ -2042,10 +2099,11 @@ Example JSON: - (nonnull instancetype)initWithRef:(_Nonnull id)ref; - (nonnull instancetype)init; +// skipped field Progress.TransferID with unsupported type: *gitlab.com/elixxir/crypto/fileTransfer.TransferID + @property (nonatomic) BOOL completed; @property (nonatomic) long transmitted; @property (nonatomic) long total; -@property (nonatomic) NSError* _Nullable err; @end /** @@ -2088,17 +2146,18 @@ JSON Example: @end /** - * ReceivedFile is a public struct that contains the metadata of a new file -transfer. + * ReceivedFile contains the metadata of a new received file transfer. It is +received from a sender on a new file transfer. It is returned by +[ReceiveFileCallback.Callback]. Example JSON: { - "TransferID":"B4Z9cwU18beRoGbk5xBjbcd5Ryi9ZUFA2UBvi8FOHWo=", - "SenderID":"emV6aW1hAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD", - "Preview":"aXQncyBtZSBhIHByZXZpZXc=", - "Name":"testfile.txt", - "Type":"text file", - "Size":2048 + "TransferID": "0U+QY1nMOUzQGxGpqZyxDw8Cd6+qm8t870CzLtVoUM8=", + "SenderID": "UL3+S8XdJHAfUtCUm7iZMxW8orR8Nd5JM9Ky7/5jds8D", + "Preview": "aXQNcyBtZSBhIHByZXZpZXc=", + "Name": "testfile.txt", + "Type": "text file", + "Size": 2048 } */ @interface BindingsReceivedFile : NSObject <goSeqRefInterface> { @@ -2107,8 +2166,10 @@ Example JSON: - (nonnull instancetype)initWithRef:(_Nonnull id)ref; - (nonnull instancetype)init; -@property (nonatomic) NSData* _Nullable transferID; -@property (nonatomic) NSData* _Nullable senderID; +// skipped field ReceivedFile.TransferID with unsupported type: *gitlab.com/elixxir/crypto/fileTransfer.TransferID + +// skipped field ReceivedFile.SenderID with unsupported type: *gitlab.com/xx_network/primitives/id.ID + @property (nonatomic) NSData* _Nullable preview; @property (nonatomic) NSString* _Nonnull name; @property (nonatomic) NSString* _Nonnull type; @@ -2759,8 +2820,15 @@ FOUNDATION_EXPORT NSData* _Nullable BindingsImportPrivateIdentity(NSString* _Nul * InitFileTransfer creates a bindings-level file transfer manager. Parameters: - - e2eID - e2e object ID in the tracker - - paramsJSON - JSON marshalled fileTransfer.Params + - e2eID - ID of [E2e] object in tracker. + - receiveFileCallback - A callback that is called when a new file transfer + is received. + - e2eFileTransferParamsJson - JSON of + [gitlab.com/elixxir/client/fileTransfer/e2e.Params]. + - fileTransferParamsJson - JSON of [fileTransfer.Params]. + +Returns: + - New [FileTransfer] object. */ FOUNDATION_EXPORT BindingsFileTransfer* _Nullable BindingsInitFileTransfer(long e2eID, id<BindingsReceiveFileCallback> _Nullable receiveFileCallback, NSData* _Nullable e2eFileTransferParamsJson, NSData* _Nullable fileTransferParamsJson, NSError* _Nullable* _Nullable error); @@ -3521,12 +3589,17 @@ called with the progress of a received file. - (nonnull instancetype)initWithRef:(_Nonnull id)ref; /** - * Callback is called when a file part is sent or an error occurs. + * Callback is called when a file part is received or an error occurs. Once +a transfer completes, the file can be received using +[FileTransfer.Receive]. Parameters: - - payload - the JSON marshalled bytes of a Progress object. - - t - tracker that allows the lookup of the status of any file part - - err - any errors that occurred during sending + - payload - JSON of [Progress], which describes the progress of the + current transfer. + - t - file part tracker that allows the lookup of the status of + individual file parts. + - err - Fatal errors during receiving. If an error is returned, the + transfer has failed and will not resume. */ - (void)callback:(NSData* _Nullable)payload t:(BindingsFilePartTracker* _Nullable)t err:(NSError* _Nullable)err; @end @@ -3541,12 +3614,17 @@ a callback that is called when the sent progress updates. - (nonnull instancetype)initWithRef:(_Nonnull id)ref; /** - * Callback is called when a file part is sent or an error occurs. + * Callback is called when a file part is sent or an error occurs. Once a +transfer completes, it should be closed using [FileTransfer.CloseSend]. Parameters: - - payload - the JSON marshalled bytes of a Progress object. - - t - tracker that allows the lookup of the status of any file part - - err - any errors that occurred during sending + - payload - JSON of [Progress], which describes the progress of the + current transfer. + - t - file part tracker that allows the lookup of the status of + individual file parts. + - err - Fatal errors during sending. If an error is returned, the + transfer has failed and will not resume. It must be cleared using + [FileTransfer.CloseSend]. */ - (void)callback:(NSData* _Nullable)payload t:(BindingsFilePartTracker* _Nullable)t err:(NSError* _Nullable)err; @end @@ -3665,10 +3743,10 @@ that is called when a file is received. * Callback is called when a new file transfer is received. Parameters: - - payload - the JSON marshalled bytes of a ReceivedFile object. - - err - any errors that occurred during reception + - payload - JSON of [ReceivedFile], which contains information about the + incoming file transfer. */ -- (void)callback:(NSData* _Nullable)payload err:(NSError* _Nullable)err; +- (void)callback:(NSData* _Nullable)payload; @end /** diff --git a/Sources/XXClient/Callbacks/FileTransferProgressCallback.swift b/Sources/XXClient/Callbacks/FileTransferProgressCallback.swift index 9c77d7af95ef9f47c42ff47ec682af4658b9ee50..615a715a102dfec5beba26042faf20543b26efaa 100644 --- a/Sources/XXClient/Callbacks/FileTransferProgressCallback.swift +++ b/Sources/XXClient/Callbacks/FileTransferProgressCallback.swift @@ -5,21 +5,24 @@ public struct FileTransferProgressCallback { public struct Callback { public init( progress: Progress, - partTracker: FilePartTracker + partTracker: FilePartTracker, + error: Error? ) { self.progress = progress self.partTracker = partTracker + self.error = error } public var progress: Progress public var partTracker: FilePartTracker + public var error: Error? } - public init(handle: @escaping (Result<Callback, NSError>) -> Void) { + public init(handle: @escaping (Callback) -> Void) { self.handle = handle } - public var handle: (Result<Callback, NSError>) -> Void + public var handle: (Callback) -> Void } extension FileTransferProgressCallback { @@ -51,24 +54,23 @@ extension FileTransferProgressCallback { let debugName: String func callback(_ payload: Data?, t: BindingsFilePartTracker?, err: Error?) { - if let error = err { - callback.handle(.failure(error as NSError)) - return - } guard let payload = payload else { fatalError("\(debugName) received `nil` payload without providing error") } - guard let tracker = t else { - fatalError("\(debugName) received `nil` tracker without providing error") - } + let progress: Progress do { - callback.handle(.success(.init( - progress: try Progress.decode(payload), - partTracker: .live(tracker) - ))) + progress = try Progress.decode(payload) } catch { - callback.handle(.failure(error as NSError)) + fatalError("\(debugName) payload decoding failed with error: \(error)") + } + guard let tracker = t else { + fatalError("\(debugName) received `nil` tracker without providing error") } + callback.handle(.init( + progress: progress, + partTracker: .live(tracker), + error: err + )) } } diff --git a/Sources/XXClient/Callbacks/ReceiveFileCallback.swift b/Sources/XXClient/Callbacks/ReceiveFileCallback.swift index 2c1d94be22e7a3a63a6590e985481c2f437ee777..ea6a0002d40a11760f68256ef84f2c62a6f341b2 100644 --- a/Sources/XXClient/Callbacks/ReceiveFileCallback.swift +++ b/Sources/XXClient/Callbacks/ReceiveFileCallback.swift @@ -26,18 +26,15 @@ extension ReceiveFileCallback { let callback: ReceiveFileCallback - func callback(_ payload: Data?, err: Error?) { - if let error = err { - callback.handle(.failure(error as NSError)) - } else if let data = payload { - do { - callback.handle(.success(try ReceivedFile.decode(data))) - } catch { - callback.handle(.failure(error as NSError)) - } - } else { + func callback(_ payload: Data?) { + guard let data = payload else { fatalError("BindingsReceiveFileCallback received `nil` payload and `nil` error") } + do { + callback.handle(.success(try ReceivedFile.decode(data))) + } catch { + callback.handle(.failure(error as NSError)) + } } } diff --git a/Sources/XXClient/Models/Progress.swift b/Sources/XXClient/Models/Progress.swift index ba2e199db7fb504d790ef6ef514c1e25f9c794eb..430bfeb4645a38bfaa743ed3801a6b3e1a79a7e6 100644 --- a/Sources/XXClient/Models/Progress.swift +++ b/Sources/XXClient/Models/Progress.swift @@ -2,29 +2,29 @@ import Foundation public struct Progress: Equatable { public init( + transferId: Data, completed: Bool, transmitted: Int, - total: Int, - error: String? + total: Int ) { + self.transferId = transferId self.completed = completed self.transmitted = transmitted self.total = total - self.error = error } + public var transferId: Data public var completed: Bool public var transmitted: Int public var total: Int - public var error: String? } extension Progress: Codable { enum CodingKeys: String, CodingKey { + case transferId = "TransferID" case completed = "Completed" case transmitted = "Transmitted" case total = "Total" - case error = "Err" } public static func decode(_ data: Data) throws -> Self { diff --git a/Sources/XXMessengerClient/Messenger/Functions/MessengerReceiveFile.swift b/Sources/XXMessengerClient/Messenger/Functions/MessengerReceiveFile.swift index ef4290f829d7811c4e0c94c31afa812c095edfbc..9c3bda144bd6a52d1f678c6b977a34b653c8ba83 100644 --- a/Sources/XXMessengerClient/Messenger/Functions/MessengerReceiveFile.swift +++ b/Sources/XXMessengerClient/Messenger/Functions/MessengerReceiveFile.swift @@ -18,9 +18,8 @@ public struct MessengerReceiveFile { public enum CallbackInfo: Equatable { public enum Failure: Equatable { - case callbackError(NSError) - case progressError(String) - case receiveError(NSError) + case callback(NSError) + case receive(NSError) } case progress(transmitted: Int, total: Int) @@ -54,26 +53,22 @@ extension MessengerReceiveFile { transferId: params.transferId, period: params.callbackIntervalMS, callback: FileTransferProgressCallback { result in - switch result { - case .success(let info): - if let error = info.progress.error { - callback(.failed(.progressError(error))) - } else if info.progress.completed { - do { - callback(.finished(try fileTransfer.receive(transferId: params.transferId))) - } catch { - callback(.failed(.receiveError(error as NSError))) - } - } else { - callback(.progress( - transmitted: info.progress.transmitted, - total: info.progress.total - )) + if let error = result.error { + callback(.failed(.callback(error as NSError))) + return + } + if result.progress.completed { + do { + callback(.finished(try fileTransfer.receive(transferId: params.transferId))) + } catch { + callback(.failed(.receive(error as NSError))) } - - case .failure(let error): - callback(.failed(.callbackError(error))) + return } + callback(.progress( + transmitted: result.progress.transmitted, + total: result.progress.total + )) } ) } diff --git a/Sources/XXMessengerClient/Messenger/Functions/MessengerSendFile.swift b/Sources/XXMessengerClient/Messenger/Functions/MessengerSendFile.swift index fde8607c42e6e7f6d8d4c97da9beca79e588c589..35158ecb43b734c755466f466db8520601f3d8fc 100644 --- a/Sources/XXMessengerClient/Messenger/Functions/MessengerSendFile.swift +++ b/Sources/XXMessengerClient/Messenger/Functions/MessengerSendFile.swift @@ -24,8 +24,7 @@ public struct MessengerSendFile { public enum CallbackInfo: Equatable { public enum Failure: Equatable { - case error(NSError) - case progressError(String) + case callback(NSError) case close(NSError) } @@ -63,8 +62,7 @@ extension MessengerSendFile { callback(.failed(id: id, .close(error as NSError))) } } - var transferId: Data! - transferId = try fileTransfer.send( + let transferId = try fileTransfer.send( params: FileTransferSend.Params( payload: params.file, recipientId: params.recipientId, @@ -72,29 +70,21 @@ extension MessengerSendFile { period: params.callbackIntervalMS ), callback: FileTransferProgressCallback { result in - guard let transferId else { - fatalError("Bindings issue: file transfer progress callback was called before send function returned transfer id.") + if let error = result.error { + callback(.failed(id: result.progress.transferId, .callback(error as NSError))) + close(id: result.progress.transferId) + return } - switch result { - case .failure(let error): - callback(.failed(id: transferId, .error(error))) - close(id: transferId) - - case .success(let cb): - if let error = cb.progress.error { - callback(.failed(id: transferId, .progressError(error))) - close(id: transferId) - } else if cb.progress.completed { - callback(.finished(id: transferId)) - close(id: transferId) - } else { - callback(.progress( - id: transferId, - transmitted: cb.progress.transmitted, - total: cb.progress.total - )) - } + if result.progress.completed { + callback(.finished(id: result.progress.transferId)) + close(id: result.progress.transferId) + return } + callback(.progress( + id: result.progress.transferId, + transmitted: result.progress.transmitted, + total: result.progress.total + )) } ) return transferId diff --git a/Tests/XXClientTests/Models/ProgressTests.swift b/Tests/XXClientTests/Models/ProgressTests.swift index 35a083c202a1e3d35b6c75860b9f8aa3b39d0d69..80e704583873e5df41c5981e6d5928c7d351f4ff 100644 --- a/Tests/XXClientTests/Models/ProgressTests.swift +++ b/Tests/XXClientTests/Models/ProgressTests.swift @@ -4,25 +4,26 @@ import XCTest final class ProgressTests: XCTestCase { func testCoding() throws { + let transferIdB64 = "RyJcMqtI3IIM1+YMxRwCcFiOX6AGuIzS+vQaPnqXVT8=" let completed = false let transmitted: Int = 128 let total: Int = 2048 let jsonString = """ { + "TransferID": "\(transferIdB64)", "Completed": \(completed), "Transmitted": \(transmitted), - "Total": \(total), - "Err": null + "Total": \(total) } """ let jsonData = jsonString.data(using: .utf8)! let model = try Progress.decode(jsonData) XCTAssertNoDifference(model, Progress( + transferId: Data(base64Encoded: transferIdB64)!, completed: completed, transmitted: transmitted, - total: total, - error: nil + total: total )) let encodedModel = try model.encode() @@ -30,28 +31,4 @@ final class ProgressTests: XCTestCase { XCTAssertNoDifference(decodedModel, model) } - - func testDecodingProgressWithError() throws { - let completed = false - let transmitted: Int = 128 - let total: Int = 2048 - let error = "something went wrong" - let jsonString = """ - { - "Completed": \(completed), - "Transmitted": \(transmitted), - "Total": \(total), - "Err": "\(error)" - } - """ - let jsonData = jsonString.data(using: .utf8)! - let model = try Progress.decode(jsonData) - - XCTAssertNoDifference(model, Progress( - completed: completed, - transmitted: transmitted, - total: total, - error: error - )) - } } diff --git a/Tests/XXMessengerClientTests/Messenger/Functions/MessengerReceiveFileTests.swift b/Tests/XXMessengerClientTests/Messenger/Functions/MessengerReceiveFileTests.swift index 554b7f309114fbdaa2ea2679d290d09f238eaa52..39d641fbedb46c668d4fb7fc950277d2cd9d3fa1 100644 --- a/Tests/XXMessengerClientTests/Messenger/Functions/MessengerReceiveFileTests.swift +++ b/Tests/XXMessengerClientTests/Messenger/Functions/MessengerReceiveFileTests.swift @@ -43,16 +43,15 @@ final class MessengerReceiveFileTests: XCTestCase { XCTAssertNoDifference(didReceiveCallback, []) didReceiveCallback = [] - didRegisterReceivedProgressCallbackWithCallback.first?.handle(.success( - FileTransferProgressCallback.Callback( - progress: Progress( - completed: false, - transmitted: 1, - total: 3, - error: nil - ), - partTracker: .unimplemented - ) + didRegisterReceivedProgressCallbackWithCallback.first?.handle(.init( + progress: .init( + transferId: params.transferId, + completed: false, + transmitted: 1, + total: 3 + ), + partTracker: .unimplemented, + error: nil )) XCTAssertNoDifference(didReceiveCallback, [ @@ -60,16 +59,15 @@ final class MessengerReceiveFileTests: XCTestCase { ]) didReceiveCallback = [] - didRegisterReceivedProgressCallbackWithCallback.first?.handle(.success( - FileTransferProgressCallback.Callback( - progress: Progress( - completed: false, - transmitted: 2, - total: 3, - error: nil - ), - partTracker: .unimplemented - ) + didRegisterReceivedProgressCallbackWithCallback.first?.handle(.init( + progress: .init( + transferId: params.transferId, + completed: false, + transmitted: 2, + total: 3 + ), + partTracker: .unimplemented, + error: nil )) XCTAssertNoDifference(didReceiveCallback, [ @@ -77,16 +75,15 @@ final class MessengerReceiveFileTests: XCTestCase { ]) didReceiveCallback = [] - didRegisterReceivedProgressCallbackWithCallback.first?.handle(.success( - FileTransferProgressCallback.Callback( - progress: Progress( - completed: true, - transmitted: 3, - total: 3, - error: nil - ), - partTracker: .unimplemented - ) + didRegisterReceivedProgressCallbackWithCallback.first?.handle(.init( + progress: Progress( + transferId: params.transferId, + completed: true, + transmitted: 3, + total: 3 + ), + partTracker: .unimplemented, + error: nil )) XCTAssertNoDifference(didReceiveTransferId, [ @@ -110,43 +107,6 @@ final class MessengerReceiveFileTests: XCTestCase { } } - func testReceiveFileProgressError() throws { - let error = "Something went wrong..." - - var receivedProgressCallback: FileTransferProgressCallback? - var didReceiveCallback: [MessengerReceiveFile.CallbackInfo] = [] - - var env: MessengerEnvironment = .unimplemented - env.fileTransfer.get = { - var fileTransfer: FileTransfer = .unimplemented - fileTransfer.registerReceivedProgressCallback.run = { _, _, callback in - receivedProgressCallback = callback - } - return fileTransfer - } - let receiveFile: MessengerReceiveFile = .live(env) - - try receiveFile(.stub) { info in - didReceiveCallback.append(info) - } - - receivedProgressCallback?.handle(.success( - FileTransferProgressCallback.Callback( - progress: Progress( - completed: false, - transmitted: 1, - total: 3, - error: error - ), - partTracker: .unimplemented - ) - )) - - XCTAssertNoDifference(didReceiveCallback, [ - .failed(.progressError(error)) - ]) - } - func testReceiveFileCallbackError() throws { let error = NSError(domain: "test", code: 123) @@ -167,14 +127,19 @@ final class MessengerReceiveFileTests: XCTestCase { didReceiveCallback.append(info) } - receivedProgressCallback?.handle(.failure(error)) + receivedProgressCallback?.handle(.init( + progress: Progress(transferId: Data(), completed: false, transmitted: 0, total: 0), + partTracker: .unimplemented, + error: error + )) XCTAssertNoDifference(didReceiveCallback, [ - .failed(.callbackError(error)) + .failed(.callback(error)) ]) } func testReceiveFileReceiveError() throws { + let params: MessengerReceiveFile.Params = .stub let error = NSError(domain: "test", code: 123) var receivedProgressCallback: FileTransferProgressCallback? @@ -193,24 +158,23 @@ final class MessengerReceiveFileTests: XCTestCase { } let receiveFile: MessengerReceiveFile = .live(env) - try receiveFile(.stub) { info in + try receiveFile(params) { info in didReceiveCallback.append(info) } - receivedProgressCallback?.handle(.success( - FileTransferProgressCallback.Callback( - progress: Progress( - completed: true, - transmitted: 3, - total: 3, - error: nil - ), - partTracker: .unimplemented - ) + receivedProgressCallback?.handle(.init( + progress: Progress( + transferId: params.transferId, + completed: true, + transmitted: 3, + total: 3 + ), + partTracker: .unimplemented, + error: nil )) XCTAssertNoDifference(didReceiveCallback, [ - .failed(.receiveError(error)) + .failed(.receive(error)) ]) } } diff --git a/Tests/XXMessengerClientTests/Messenger/Functions/MessengerSendFileTests.swift b/Tests/XXMessengerClientTests/Messenger/Functions/MessengerSendFileTests.swift index 4e1c1763b489e66206ca18668bd673d8d75c5570..2a0b74dcd3fd214c27f0cd138d88a021d5861481 100644 --- a/Tests/XXMessengerClientTests/Messenger/Functions/MessengerSendFileTests.swift +++ b/Tests/XXMessengerClientTests/Messenger/Functions/MessengerSendFileTests.swift @@ -43,33 +43,36 @@ final class MessengerSendFileTests: XCTestCase { ) ]) - fileTransferProgressCallback.handle(.success(.init( + fileTransferProgressCallback.handle(.init( progress: Progress( + transferId: newTransferId, completed: false, transmitted: 1, - total: 10, - error: nil + total: 10 ), - partTracker: .unimplemented - ))) - fileTransferProgressCallback.handle(.success(.init( + partTracker: .unimplemented, + error: nil + )) + fileTransferProgressCallback.handle(.init( progress: Progress( + transferId: newTransferId, completed: false, transmitted: 6, - total: 10, - error: nil + total: 10 ), - partTracker: .unimplemented - ))) - fileTransferProgressCallback.handle(.success(.init( + partTracker: .unimplemented, + error: nil + )) + fileTransferProgressCallback.handle(.init( progress: Progress( + transferId: newTransferId, completed: true, transmitted: 10, - total: 10, - error: nil + total: 10 ), - partTracker: .unimplemented - ))) + partTracker: .unimplemented, + error: nil + )) XCTAssertNoDifference(didReceiveCallback, [ .progress(id: transferId, transmitted: 1, total: 10), @@ -93,38 +96,9 @@ final class MessengerSendFileTests: XCTestCase { } func testSendFileCallbackFailure() throws { - var didCloseSend: [Data] = [] - var didReceiveCallback: [MessengerSendFile.CallbackInfo] = [] - var fileTransferProgressCallback: FileTransferProgressCallback! - - var env: MessengerEnvironment = .unimplemented - env.fileTransfer.get = { - var fileTransfer: FileTransfer = .unimplemented - fileTransfer.send.run = { _, callback in - fileTransferProgressCallback = callback - return "transferId".data(using: .utf8)! - } - fileTransfer.closeSend.run = { id in - didCloseSend.append(id) - } - return fileTransfer - } - let sendFile: MessengerSendFile = .live(env) - - let transferId = try sendFile(.stub) { info in - didReceiveCallback.append(info) - } - + let newTransferId = "transferId".data(using: .utf8)! let error = NSError(domain: "test", code: 1234) - fileTransferProgressCallback.handle(.failure(error)) - - XCTAssertNoDifference(didReceiveCallback, [ - .failed(id: transferId, .error(error)), - ]) - XCTAssertNoDifference(didCloseSend, [transferId]) - } - func testSendFileProgressError() throws { var didCloseSend: [Data] = [] var didReceiveCallback: [MessengerSendFile.CallbackInfo] = [] var fileTransferProgressCallback: FileTransferProgressCallback! @@ -134,7 +108,7 @@ final class MessengerSendFileTests: XCTestCase { var fileTransfer: FileTransfer = .unimplemented fileTransfer.send.run = { _, callback in fileTransferProgressCallback = callback - return "transferId".data(using: .utf8)! + return newTransferId } fileTransfer.closeSend.run = { id in didCloseSend.append(id) @@ -146,26 +120,26 @@ final class MessengerSendFileTests: XCTestCase { let transferId = try sendFile(.stub) { info in didReceiveCallback.append(info) } - - let error = "something went wrong" - fileTransferProgressCallback.handle(.success(.init( + fileTransferProgressCallback.handle(.init( progress: .init( + transferId: newTransferId, completed: false, transmitted: 0, - total: 0, - error: error + total: 0 ), - partTracker: .unimplemented - ))) + partTracker: .unimplemented, + error: error + )) XCTAssertNoDifference(didReceiveCallback, [ - .failed(id: transferId, .progressError(error)), + .failed(id: newTransferId, .callback(error)), ]) - XCTAssertNoDifference(didCloseSend, [transferId]) + XCTAssertNoDifference(didCloseSend, [newTransferId]) } func testSendFileCloseError() throws { let closeError = NSError(domain: "test", code: 1234) + let newTransferId = "transferId".data(using: .utf8)! var didReceiveCallback: [MessengerSendFile.CallbackInfo] = [] var fileTransferProgressCallback: FileTransferProgressCallback! @@ -175,7 +149,7 @@ final class MessengerSendFileTests: XCTestCase { var fileTransfer: FileTransfer = .unimplemented fileTransfer.send.run = { _, callback in fileTransferProgressCallback = callback - return "transferId".data(using: .utf8)! + return newTransferId } fileTransfer.closeSend.run = { id in throw closeError @@ -188,19 +162,20 @@ final class MessengerSendFileTests: XCTestCase { didReceiveCallback.append(info) } - fileTransferProgressCallback.handle(.success(.init( + fileTransferProgressCallback.handle(.init( progress: .init( + transferId: newTransferId, completed: true, transmitted: 1, - total: 1, - error: nil + total: 1 ), - partTracker: .unimplemented - ))) + partTracker: .unimplemented, + error: nil + )) XCTAssertNoDifference(didReceiveCallback, [ - .finished(id: transferId), - .failed(id: transferId, .close(closeError)), + .finished(id: newTransferId), + .failed(id: newTransferId, .close(closeError)), ]) } }