Commit 09a6a64a authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

account: save registered name

Save registered name in the user defaults, so it as always available
if registration was successful.

Change-Id: I973c424071894dd77c731edecd0f184241877c16
parent c200e535
......@@ -101,6 +101,10 @@ class MeViewModel: ViewModel, Stateable {
if let accountName = accountName, !accountName.isEmpty {
return Observable.just(accountName)
}
if let userNameData = UserDefaults.standard.dictionary(forKey: self.nameService.registeredNamesKey),
let name = userNameData[account.id] as? String, !name.isEmpty {
return Observable.just(name)
}
let accountHelper = AccountModelHelper(withAccount: account)
guard let uri = accountHelper.ringId else {
return Observable.just("")
......
......@@ -155,9 +155,6 @@ class AccountsService: AccountAdapterDelegate {
//~ Registering to the accountAdatpter with self as delegate in order to receive delegation
//~ callbacks.
AccountAdapter.delegate = self
NotificationCenter.default.addObserver(self, selector: #selector(self.saveAccountConfiguration(_:)),
name: NSNotification.Name(rawValue: NotificationName.nameRegistered.rawValue),
object: nil)
}
fileprivate func loadAccountsFromDaemon() {
......@@ -407,14 +404,6 @@ class AccountsService: AccountAdapterDelegate {
}
}
@objc func saveAccountConfiguration(_ notification: NSNotification) {
guard let accountID = notification.userInfo?[NotificationUserInfoKeys.accountID.rawValue] as? String else {
return
}
let accountDetails = self.getAccountDetails(fromAccountId: accountID)
self.setAccountDetails(forAccountId: accountID, withDetails: accountDetails)
}
/**
Gets the known Ring devices of an account from the daemon.
......
......@@ -47,6 +47,8 @@ class NameService: NameRegistrationAdapterDelegate {
fileprivate let lookupNameCallDelay = 0.5
let registeredNamesKey = "REGISTERED_NAMES_KEY"
/**
Status of the current username validation request
*/
......@@ -117,9 +119,12 @@ class NameService: NameRegistrationAdapterDelegate {
internal func nameRegistrationEnded(with response: NameRegistrationResponse) {
if response.state == .success {
var data = [String: String]()
data[NotificationUserInfoKeys.accountID.rawValue] = response.accountId
NotificationCenter.default.post(name: NSNotification.Name(NotificationName.nameRegistered.rawValue), object: nil, userInfo: data)
var registeredNames = [String: String]()
if let userNameData = UserDefaults.standard.dictionary(forKey: registeredNamesKey) as? [String: String] {
registeredNames = userNameData
}
registeredNames[response.accountId] = response.name
UserDefaults.standard.set(registeredNames, forKey: registeredNamesKey)
log.debug("Registred name : \(response.name ?? "no name")")
} else {
log.debug("Name Registration failed. State = \(response.state.rawValue)")
......
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