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
!81
Messenger example - contact authorization improvements
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Messenger example - contact authorization improvements
feature/messenger-example-contact-auth
into
development
Overview
0
Commits
12
Pipelines
0
Changes
2
Merged
Dariusz Rybicki
requested to merge
feature/messenger-example-contact-auth
into
development
2 years ago
Overview
0
Commits
12
Pipelines
0
Changes
2
Expand
0
0
Merge request reports
Viewing commit
64847678
Prev
Next
Show latest version
2 files
+
51
−
10
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
64847678
Update auth status when verifying contact
· 64847678
Dariusz Rybicki
authored
2 years ago
Examples/xx-messenger/Sources/VerifyContactFeature/VerifyContactFeature.swift
0 → 100644
+
97
−
0
Options
import
AppCore
import
ComposableArchitecture
import
Foundation
import
XCTestDynamicOverlay
import
XXClient
import
XXMessengerClient
import
XXModels
public
struct
VerifyContactState
:
Equatable
{
public
enum
Result
:
Equatable
{
case
success
(
Bool
)
case
failure
(
String
)
}
public
init
(
contact
:
XXClient
.
Contact
,
isVerifying
:
Bool
=
false
,
result
:
Result
?
=
nil
)
{
self
.
contact
=
contact
self
.
isVerifying
=
isVerifying
self
.
result
=
result
}
public
var
contact
:
XXClient
.
Contact
public
var
isVerifying
:
Bool
public
var
result
:
Result
?
}
public
enum
VerifyContactAction
:
Equatable
{
case
verifyTapped
case
didVerify
(
VerifyContactState
.
Result
)
}
public
struct
VerifyContactEnvironment
{
public
init
(
messenger
:
Messenger
,
db
:
DBManagerGetDB
,
mainQueue
:
AnySchedulerOf
<
DispatchQueue
>
,
bgQueue
:
AnySchedulerOf
<
DispatchQueue
>
)
{
self
.
messenger
=
messenger
self
.
db
=
db
self
.
mainQueue
=
mainQueue
self
.
bgQueue
=
bgQueue
}
public
var
messenger
:
Messenger
public
var
db
:
DBManagerGetDB
public
var
mainQueue
:
AnySchedulerOf
<
DispatchQueue
>
public
var
bgQueue
:
AnySchedulerOf
<
DispatchQueue
>
}
#if DEBUG
extension
VerifyContactEnvironment
{
public
static
let
unimplemented
=
VerifyContactEnvironment
(
messenger
:
.
unimplemented
,
db
:
.
unimplemented
,
mainQueue
:
.
unimplemented
,
bgQueue
:
.
unimplemented
)
}
#endif
public
let
verifyContactReducer
=
Reducer
<
VerifyContactState
,
VerifyContactAction
,
VerifyContactEnvironment
>
{
state
,
action
,
env
in
switch
action
{
case
.
verifyTapped
:
state
.
isVerifying
=
true
state
.
result
=
nil
return
Effect
.
result
{
[
state
]
in
func
updateStatus
(
_
status
:
XXModels
.
Contact
.
AuthStatus
)
throws
{
try
env
.
db
()
.
bulkUpdateContacts
.
callAsFunction
(
.
init
(
id
:
[
try
state
.
contact
.
getId
()]),
.
init
(
authStatus
:
status
)
)
}
do
{
try
updateStatus
(
.
verificationInProgress
)
let
result
=
try
env
.
messenger
.
verifyContact
(
state
.
contact
)
try
updateStatus
(
result
?
.
verified
:
.
verificationFailed
)
return
.
success
(
.
didVerify
(
.
success
(
result
)))
}
catch
{
try
?
updateStatus
(
.
verificationFailed
)
return
.
success
(
.
didVerify
(
.
failure
(
error
.
localizedDescription
)))
}
}
.
subscribe
(
on
:
env
.
bgQueue
)
.
receive
(
on
:
env
.
mainQueue
)
.
eraseToEffect
()
case
.
didVerify
(
let
result
):
state
.
isVerifying
=
false
state
.
result
=
result
return
.
none
}
}
Loading