Commit 4845e64a authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

UI: new account details

- fix display username and devices for newly created account.
- add timeout for name registration. After this timeout notify
user that name registration not finished and navigate to main
interface.

Change-Id: I2882c90744470c0283f6215cbe019e29d15c9a5e
parent e225a98e
......@@ -249,6 +249,10 @@ internal enum L10n {
internal static let registerAUsername = L10n.tr("Localizable", "createAccount.RegisterAUsername")
/// Confirm password
internal static let repeatPasswordPlaceholder = L10n.tr("Localizable", "createAccount.repeatPasswordPlaceholder")
/// Username registration in progress... It could take a few moments.
internal static let timeoutMessage = L10n.tr("Localizable", "createAccount.timeoutMessage")
/// Account Created
internal static let timeoutTitle = L10n.tr("Localizable", "createAccount.timeoutTitle")
/// username already taken
internal static let usernameAlreadyTaken = L10n.tr("Localizable", "createAccount.usernameAlreadyTaken")
/// Account was created but username was not registered
......
......@@ -261,11 +261,11 @@ class MeViewModel: ViewModel, Stateable {
self.isAccountSip.value = account.type == AccountType.sip
}
return Observable.combineLatest(jamiSettings, sipSettings,
isAccountSip.asObservable()) {(jami, sip, isSip) in
if isSip == true {
return sip
}
return jami
isAccountSip.asObservable()) {(jami, sip, isSip) in
if isSip == true {
return sip
}
return jami
}
}()
......@@ -300,16 +300,22 @@ class MeViewModel: ViewModel, Stateable {
sipInfoUpdated.onNext(true)
return
}
if let accountName = account.volatileDetails?.get(withConfigKeyModel: ConfigKeyModel(withKey: ConfigKey.accountRegisteredName)),
!accountName.isEmpty {
currentAccountUserName.onNext(accountName)
} else if let userNameData = UserDefaults.standard.dictionary(forKey: registeredNamesKey),
let accountName = userNameData[account.id] as? String,
!accountName.isEmpty {
currentAccountUserName.onNext(accountName)
} else {
currentAccountUserName.onNext("")
}
self.nameService.sharedRegistrationStatus
.filter { (serviceEvent) -> Bool in
if serviceEvent.getEventInput(ServiceEventInput.accountId) != account.id {return false}
if serviceEvent.eventType != .nameRegistrationEnded {
return false
}
return true
}.subscribe(onNext: { [unowned self] _ in
if !self.userNameForAccount(account: account).isEmpty {
self.currentAccountUserName
.onNext(self.userNameForAccount(account: account))
}
}, onError: { _ in
}).disposed(by: self.tempBag)
self.currentAccountUserName
.onNext(self.userNameForAccount(account: account))
if let jamiId = AccountModelHelper.init(withAccount: account).ringId {
currentAccountJamiId.onNext(jamiId)
} else {
......@@ -326,6 +332,18 @@ class MeViewModel: ViewModel, Stateable {
}).disposed(by: self.tempBag)
}
func userNameForAccount(account: AccountModel) -> String {
if let accountName = account.volatileDetails?.get(withConfigKeyModel: ConfigKeyModel(withKey: ConfigKey.accountRegisteredName)),
!accountName.isEmpty {
return accountName
} else if let userNameData = UserDefaults.standard.dictionary(forKey: registeredNamesKey),
let accountName = userNameData[account.id] as? String,
!accountName.isEmpty {
return accountName
}
return ""
}
func linkDevice() {
self.stateSubject.onNext(MeState.linkNewDevice)
}
......@@ -420,22 +438,32 @@ class MeViewModel: ViewModel, Stateable {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01, execute: {
if let account = self.accountService.currentAccount {
self.accountService.devicesObservable(account: account)
.take(1)
.subscribe(onNext: { [unowned self] profile in
self.currentAccountDevices.onNext(profile)
}).disposed(by: self.disposeBag)
.subscribe(onNext: { [unowned self] device in
self.currentAccountDevices.onNext(device)
}).disposed(by: self.tempBag)
}
})
return self.currentAccountDevices.share()
.map { devices -> SettingsSection in
var rows: [SettingsSection.SectionRow]?
if !devices.isEmpty {
rows = [.device(device: devices[0])]
for deviceIndex in 1 ..< devices.count {
let device = devices[deviceIndex]
rows!.append (.device(device: device))
}
} else if let account = self.accountService.currentAccount,
let details = account.details {
let deviceId = details.get(withConfigKeyModel: ConfigKeyModel.init(withKey: .accountDeviceId))
let deviceName = details.get(withConfigKeyModel:
ConfigKeyModel.init(withKey: .accountDeviceName))
if deviceId.isEmpty {
return empptySection
}
rows = [.device(device:
DeviceModel(withDeviceId: deviceId,
deviceName: deviceName,
isCurrent: true))]
}
if rows != nil {
rows?.insert(.sectionHeader(title: L10n.AccountPage.devicesListHeader), at: 0)
......
......@@ -208,6 +208,9 @@ class CreateAccountViewController: UIViewController, StoryboardBased, ViewModelB
case .nameNotRegistered:
self?.hideAccountCreationHud()
self?.showNameNotRegistered()
case .timeOut:
self?.hideAccountCreationHud()
self?.showTimeOutAlert()
default:
self?.hideAccountCreationHud()
}
......@@ -302,4 +305,18 @@ class CreateAccountViewController: UIViewController, StoryboardBased, ViewModelB
alert.addAction(okAction)
self.present(alert, animated: true, completion: nil)
}
private func showTimeOutAlert() {
let alert = UIAlertController
.init(title: L10n.CreateAccount.timeoutTitle,
message: L10n.CreateAccount.timeoutMessage,
preferredStyle: .alert)
let okAction =
UIAlertAction(title: L10n.Global.ok,
style: .default) { [weak self](_: UIAlertAction!) -> Void in
self?.viewModel.finish()
}
alert.addAction(okAction)
self.present(alert, animated: true, completion: nil)
}
}
......@@ -80,6 +80,7 @@ enum AccountCreationState {
case started
case success
case nameNotRegistered
case timeOut
case error(error: AccountCreationError)
var isInProgress: Bool {
......@@ -91,6 +92,15 @@ enum AccountCreationState {
}
}
var isCompleted: Bool {
switch self {
case .unknown, .started:
return false
default:
return true
}
}
var message: String {
switch self {
case .error(let error):
......@@ -280,9 +290,9 @@ class CreateAccountViewModel: Stateable, ViewModel {
}
return
}
self.nameService.registerNameObservable(withAccount: account.id,
password: password,
name: username)
let disposable = self.nameService.registerNameObservable(withAccount: account.id,
password: password,
name: username)
.subscribe(onNext: { registered in
if registered {
self.accountCreationState.value = .success
......@@ -295,7 +305,15 @@ class CreateAccountViewModel: Stateable, ViewModel {
}
}, onError: { _ in
self.accountCreationState.value = .nameNotRegistered
}).disposed(by: self.disposeBag)
})
DispatchQueue.main
.asyncAfter(deadline: .now() + 6) {
disposable.dispose()
if self.accountCreationState.value.isCompleted {
return
}
self.accountCreationState.value = .timeOut
}
}, onError: { [unowned self] (error) in
if let error = error as? AccountCreationError {
self.accountCreationState.value = .error(error: error)
......
......@@ -86,6 +86,8 @@
"createAccount.Recommended" = "(Recommended)";
"createAccount.UsernameNotRegisteredTitle" = "Network error";
"createAccount.UsernameNotRegisteredMessage" = "Account was created but username was not registered";
"createAccount.timeoutTitle" = "Account Created";
"createAccount.timeoutMessage" = "Username registration in progress... It could take a few moments.";
//Link To Account form
"linkToAccount.waitLinkToAccountTitle" = "Account linking";
......
......@@ -625,15 +625,9 @@ class AccountsService: AccountAdapterDelegate {
func knownDevicesChanged(for account: String, devices: [String: String]) {
reloadAccounts()
let changedAccount = getAccount(fromAccountId: account)
if let changedAccount = changedAccount {
let accountHelper = AccountModelHelper(withAccount: changedAccount)
if let uri = accountHelper.ringId {
var event = ServiceEvent(withEventType: .knownDevicesChanged)
event.addEventInput(.uri, value: uri)
self.responseStream.onNext(event)
}
}
var event = ServiceEvent(withEventType: .knownDevicesChanged)
event.addEventInput(.accountId, value: account)
self.responseStream.onNext(event)
}
func exportOnRing(withPassword password: String)
......@@ -750,18 +744,15 @@ class AccountsService: AccountAdapterDelegate {
// MARK: - observable account data
func devicesObservable(account: AccountModel) -> Observable<[DeviceModel]> {
let accountHelper = AccountModelHelper(withAccount: account)
let uri = accountHelper.ringId
let accountDevices = Observable.from(optional: account.devices)
let accountDevices: Observable<[DeviceModel]> = Observable.just(account.devices)
let newDevice: Observable<[DeviceModel]> = self
.sharedResponseStream
.filter({ (event) in
return event.eventType == ServiceEventType.knownDevicesChanged &&
event.getEventInput(ServiceEventInput.uri) == uri
event.getEventInput(ServiceEventInput.accountId) == account.id
}).map({ _ in
return account.devices
})
return accountDevices.concat(newDevice)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment