Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-client-ios
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-client-ios
Commits
6586b303
Commit
6586b303
authored
Nov 23, 2017
by
Romain Bertozzi
Browse files
Options
Downloads
Patches
Plain Diff
me screen with new account service
Change-Id: Iac86f2a0bf643511d8a43cb1cd6b64cbe6abdb29
parent
97350685
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Ring/Ring/Features/Me/Me/MeViewController.swift
+4
-3
4 additions, 3 deletions
Ring/Ring/Features/Me/Me/MeViewController.swift
Ring/Ring/Features/Me/Me/MeViewModel.swift
+64
-73
64 additions, 73 deletions
Ring/Ring/Features/Me/Me/MeViewModel.swift
with
68 additions
and
76 deletions
Ring/Ring/Features/Me/Me/MeViewController.swift
+
4
−
3
View file @
6586b303
...
...
@@ -44,11 +44,11 @@ class MeViewController: EditProfileViewController, StoryboardBased, ViewModelBas
}
override
func
setupUI
()
{
self
.
viewModel
.
u
ser
N
ame
self
.
viewModel
.
accountU
ser
n
ame
Observable
.
bind
(
to
:
self
.
nameLabel
.
rx
.
text
)
.
disposed
(
by
:
disposeBag
)
self
.
viewModel
.
r
ingId
.
as
Observable
()
self
.
viewModel
.
accountR
ingIdObservable
.
bind
(
to
:
self
.
ringIdLabel
.
rx
.
text
)
.
disposed
(
by
:
disposeBag
)
...
...
@@ -97,7 +97,8 @@ class MeViewController: EditProfileViewController, StoryboardBased, ViewModelBas
}
let
settingsItemDataSource
=
RxTableViewSectionedReloadDataSource
<
SettingsSection
>
(
configureCell
:
configureCell
)
self
.
viewModel
.
settings
self
.
viewModel
.
accountSettingsObservable
.
bind
(
to
:
self
.
settingsTable
.
rx
.
items
(
dataSource
:
settingsItemDataSource
))
.
disposed
(
by
:
disposeBag
)
...
...
This diff is collapsed.
Click to expand it.
Ring/Ring/Features/Me/Me/MeViewModel.swift
+
64
−
73
View file @
6586b303
...
...
@@ -3,6 +3,7 @@
*
* Author: Thibault Wittemberg <thibault.wittemberg@savoirfairelinux.com>
* Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
* Author: Romain Bertozzi <romain.bertozzi@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
...
...
@@ -19,7 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
import
Foundation
import
SwiftyBeaver
import
RxSwift
import
RxDataSources
...
...
@@ -68,92 +69,82 @@ enum SettingsSection: SectionModelType {
}
}
class
MeViewModel
:
ViewModel
,
Stateable
{
final
class
MeViewModel
:
ViewModel
,
Stateable
{
// MARK: - Rx Stateable
private
let
stateSubject
=
PublishSubject
<
State
>
()
lazy
var
userName
:
Observable
<
String
?
>
=
{
// return username if exists, is no start name lookup
let
accountName
=
self
.
accountService
.
currentAccount
?
.
volatileDetails
?
.
get
(
withConfigKeyModel
:
ConfigKeyModel
(
withKey
:
ConfigKey
.
accountRegisteredName
))
if
accountName
!=
nil
&&
!
accountName
!.
isEmpty
{
return
Observable
.
from
(
optional
:
accountName
)
}
guard
let
account
=
self
.
accountService
.
currentAccount
else
{
return
Observable
.
from
(
optional
:
accountName
)
}
let
accountHelper
=
AccountModelHelper
(
withAccount
:
account
)
guard
let
uri
=
accountHelper
.
ringId
else
{
return
Observable
.
from
(
optional
:
accountName
)
}
let
time
=
DispatchTime
.
now
()
+
2
DispatchQueue
.
main
.
asyncAfter
(
deadline
:
time
)
{
self
.
nameService
.
lookupAddress
(
withAccount
:
""
,
nameserver
:
""
,
address
:
uri
)
}
return
self
.
nameService
.
usernameLookupStatus
.
filter
({
lookupNameResponse
in
return
lookupNameResponse
.
address
!=
nil
&&
lookupNameResponse
.
address
==
uri
&&
lookupNameResponse
.
state
==
.
found
})
.
map
({
lookupNameResponse
in
return
lookupNameResponse
.
name
})
lazy
var
state
:
Observable
<
State
>
=
{
return
self
.
stateSubject
.
asObservable
()
}()
lazy
var
ringId
:
Observable
<
String
?
>
=
{
return
Observable
.
from
(
optional
:
self
.
accountService
.
currentAccount
?
.
details
?
.
get
(
withConfigKeyModel
:
ConfigKeyModel
(
withKey
:
.
accountUsername
)))
private
let
disposeBag
=
DisposeBag
()
private
let
accountService
:
NewAccountsService
private
let
nameService
:
NameService
private
let
log
=
SwiftyBeaver
.
self
private
let
accountUsername
=
Variable
<
String
>
(
""
)
lazy
var
accountUsernameObservable
:
Observable
<
String
>
=
{
return
self
.
accountUsername
.
asObservable
()
}()
lazy
var
state
:
Observable
<
State
>
=
{
return
self
.
stateSubject
.
asObservable
()
private
let
accountRingId
=
Variable
<
String
>
(
""
)
lazy
var
accountRingIdObservable
:
Observable
<
String
>
=
{
return
self
.
accountRingId
.
asObservable
()
}()
let
disposeBag
=
DisposeBag
()
let
accountService
:
AccountsService
let
nameService
:
NameService
//table section
lazy
var
settings
:
Observable
<
[
SettingsSection
]
>
=
{
if
let
account
=
self
.
accountService
.
currentAccount
{
let
accountHelper
=
AccountModelHelper
(
withAccount
:
account
)
let
uri
=
accountHelper
.
ringId
let
devices
=
Observable
.
from
(
optional
:
account
.
devices
)
let
accountDevice
:
Observable
<
[
DeviceModel
]
>
=
self
.
accountService
.
sharedResponseStream
.
filter
({
(
event
)
in
return
event
.
eventType
==
ServiceEventType
.
knownDevicesChanged
&&
event
.
getEventInput
(
ServiceEventInput
.
uri
)
==
uri
})
.
map
({
_
in
return
account
.
devices
})
return
devices
.
concat
(
accountDevice
)
.
map
{
devices
in
let
addNewDevice
=
SettingsSection
.
linkNewDevice
(
header
:
""
,
items
:
[
SettingsSection
.
SectionRow
.
linkNew
]
)
var
rows
:
[
SettingsSection
.
SectionRow
]?
private
let
accountSettings
=
Variable
<
[
SettingsSection
]
>
([]
)
lazy
var
accountSettingsObservable
:
Observable
<
[
SettingsSection
]
>
=
{
return
self
.
accountSettings
.
asObservable
(
)
}()
if
!
devices
.
isEmpty
{
rows
=
[
SettingsSection
.
SectionRow
.
device
(
device
:
devices
[
0
])]
for
i
in
1
..<
devices
.
count
{
let
device
=
devices
[
i
]
rows
!.
append
(
SettingsSection
.
SectionRow
.
device
(
device
:
device
))
}
}
required
init
(
with
injectionBag
:
InjectionBag
)
{
self
.
accountService
=
injectionBag
.
newAccountsService
self
.
nameService
=
injectionBag
.
nameService
if
rows
!=
nil
{
let
devicesSection
=
SettingsSection
.
linkedDevices
(
header
:
L10n
.
Accountpage
.
devicesListHeader
,
items
:
rows
!
)
return
[
devicesSection
,
addNewDevice
]
self
.
accountService
.
currentAccount
()
.
do
(
onNext
:
{
[
weak
self
]
(
account
)
in
let
accountUsernameKey
=
ConfigKeyModel
(
withKey
:
ConfigKey
.
accountUsername
)
let
ringId
=
account
.
details
?
.
get
(
withConfigKeyModel
:
accountUsernameKey
)
self
?
.
accountRingId
.
value
=
ringId
??
"No RingId found"
let
addNewDevice
=
SettingsSection
.
linkNewDevice
(
header
:
""
,
items
:
[
SettingsSection
.
SectionRow
.
linkNew
])
var
rows
:
[
SettingsSection
.
SectionRow
]
if
!
account
.
devices
.
isEmpty
{
rows
=
[
SettingsSection
.
SectionRow
.
device
(
device
:
account
.
devices
[
0
])]
for
i
in
1
..<
account
.
devices
.
count
{
let
device
=
account
.
devices
[
i
]
rows
.
append
(
SettingsSection
.
SectionRow
.
device
(
device
:
device
))
}
let
devicesSection
=
SettingsSection
.
linkedDevices
(
header
:
L10n
.
Accountpage
.
devicesListHeader
,
items
:
rows
)
self
?
.
accountSettings
.
value
=
[
devicesSection
,
addNewDevice
]
}
else
{
return
[
addNewDevice
]
self
?
.
accountSettings
.
value
=
[
addNewDevice
]
}
},
onError
:
{
[
weak
self
]
(
error
)
in
self
?
.
accountRingId
.
value
=
"No RingId found"
self
?
.
log
.
error
(
"No RingId found -
\(
error
.
localizedDescription
)
"
)
})
.
flatMap
{
(
account
)
->
PrimitiveSequence
<
SingleTrait
,
String
>
in
let
registeredNameKey
=
ConfigKeyModel
(
withKey
:
ConfigKey
.
accountRegisteredName
)
if
let
registeredName
=
account
.
volatileDetails
?
.
get
(
withConfigKeyModel
:
registeredNameKey
)
{
return
Single
.
just
(
registeredName
)
}
else
{
//TODO: call nameserver single
return
Single
.
just
(
""
)
}
}
return
Observable
.
just
([
SettingsSection
]())
}()
required
init
(
with
injectionBag
:
InjectionBag
)
{
self
.
accountService
=
injectionBag
.
accountService
self
.
nameService
=
injectionBag
.
nameService
.
subscribe
(
onSuccess
:
{
[
weak
self
]
(
username
)
in
self
?
.
accountUsername
.
value
=
username
},
onError
:
{
[
weak
self
]
(
error
)
in
self
?
.
accountUsername
.
value
=
"No username found"
self
?
.
log
.
error
(
"No username found -
\(
error
.
localizedDescription
)
"
)
})
.
disposed
(
by
:
self
.
disposeBag
)
}
func
linkDevice
()
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment