Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Elixxir dApps SDK Swift
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mobile
iOS
Elixxir dApps SDK Swift
Merge requests
!102
Release 1.0.0
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Release 1.0.0
development
into
main
Overview
0
Commits
1078
Pipelines
0
Changes
2
Merged
Dariusz Rybicki
requested to merge
development
into
main
2 years ago
Overview
0
Commits
1078
Pipelines
0
Changes
2
Expand
0
0
Merge request reports
Viewing commit
cb778700
Show latest version
2 files
+
264
−
13
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
cb778700
Implement MessengerReceiveFile function
· cb778700
Dariusz Rybicki
authored
2 years ago
Sources/XXMessengerClient/Messenger/Functions/MessengerReceiveFile.swift
+
63
−
8
Options
@@ -3,24 +3,79 @@ import XCTestDynamicOverlay
import
XXClient
public
struct
MessengerReceiveFile
{
public
struct
Params
:
Equatable
{
public
init
(
transferId
:
Data
,
callbackIntervalMS
:
Int
=
250
)
{
self
.
transferId
=
transferId
self
.
callbackIntervalMS
=
callbackIntervalMS
}
public
var
transferId
:
Data
public
var
callbackIntervalMS
:
Int
}
public
enum
CallbackInfo
:
Equatable
{
public
enum
Failure
:
Equatable
{
case
callbackError
(
NSError
)
case
progressError
(
String
)
case
receiveError
(
NSError
)
}
case
progress
(
transmitted
:
Int
,
total
:
Int
)
case
finished
(
Data
)
case
failed
(
Failure
)
}
public
typealias
Callback
=
(
CallbackInfo
)
->
Void
public
enum
Error
:
Swift
.
Error
,
Equatable
{
case
notConnec
ted
case
fileTransferNotStar
ted
}
public
var
run
:
()
throws
->
Void
public
var
run
:
(
Params
,
@escaping
Callback
)
throws
->
Void
public
func
callAsFunction
()
throws
->
Void
{
try
run
()
public
func
callAsFunction
(
_
params
:
Params
,
callback
:
@escaping
Callback
)
throws
->
Void
{
try
run
(
params
,
callback
)
}
}
extension
MessengerReceiveFile
{
public
static
func
live
(
_
env
:
MessengerEnvironment
)
->
MessengerReceiveFile
{
MessengerReceiveFile
{
guard
let
e2e
=
env
.
e2e
()
else
{
throw
Error
.
notConnec
ted
MessengerReceiveFile
{
params
,
callback
in
guard
let
fileTransfer
=
env
.
fileTransfer
()
else
{
throw
Error
.
fileTransferNotStar
ted
}
// TODO: implement receiving file
try
fileTransfer
.
registerReceivedProgressCallback
(
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
))
}
case
.
failure
(
let
error
):
callback
(
.
failed
(
.
callbackError
(
error
)))
}
}
)
}
}
}
Loading