Skip to content
Snippets Groups Projects
Commit 1fa8b540 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

registrationstate: use enum

Change-Id: I6e8eaa4e34268a315766034f090f304d4dca4f03
parent c4586253
Branches
Tags
No related merge requests found
...@@ -131,10 +131,7 @@ class AccountWizardPresenter @Inject constructor( ...@@ -131,10 +131,7 @@ class AccountWizardPresenter @Inject constructor(
if (accountCreationModel.isLink) { if (accountCreationModel.isLink) {
view!!.displayProgress(true) view!!.displayProgress(true)
mCompositeDisposable.add(newAccount mCompositeDisposable.add(newAccount
.filter { a: Account -> .filter { a: Account -> a.registrationState != AccountConfig.RegistrationState.INITIALIZING }
val newState = a.registrationState
!(newState.isEmpty() || newState.contentEquals(AccountConfig.STATE_INITIALIZING))
}
.firstOrError() .firstOrError()
.observeOn(mUiScheduler) .observeOn(mUiScheduler)
.subscribe({ acc: Account -> .subscribe({ acc: Account ->
...@@ -143,7 +140,7 @@ class AccountWizardPresenter @Inject constructor( ...@@ -143,7 +140,7 @@ class AccountWizardPresenter @Inject constructor(
if (view != null) { if (view != null) {
view.displayProgress(false) view.displayProgress(false)
val newState = acc.registrationState val newState = acc.registrationState
if (newState.contentEquals(AccountConfig.STATE_ERROR_GENERIC)) { if (newState == AccountConfig.RegistrationState.ERROR_GENERIC) {
mCreatingAccount = false mCreatingAccount = false
if (accountCreationModel.archive == null) view.displayCannotBeFoundError() else view.displayGenericError() if (accountCreationModel.archive == null) view.displayCannotBeFoundError() else view.displayGenericError()
} else { } else {
...@@ -189,10 +186,7 @@ class AccountWizardPresenter @Inject constructor( ...@@ -189,10 +186,7 @@ class AccountWizardPresenter @Inject constructor(
//mCreationError = false; //mCreationError = false;
val account = BehaviorSubject.create<Account>() val account = BehaviorSubject.create<Account>()
account.onErrorComplete() account.onErrorComplete()
.filter { a: Account -> .filter { a: Account -> a.registrationState != AccountConfig.RegistrationState.INITIALIZING }
val newState = a.registrationState
!(newState.isEmpty() || newState.contentEquals(AccountConfig.STATE_INITIALIZING))
}
.firstElement() .firstElement()
.subscribe { a: Account -> .subscribe { a: Account ->
if (!model.isLink && a.isJami && model.username.isNotEmpty()) if (!model.isLink && a.isJami && model.username.isNotEmpty())
...@@ -212,9 +206,7 @@ class AccountWizardPresenter @Inject constructor( ...@@ -212,9 +206,7 @@ class AccountWizardPresenter @Inject constructor(
fun profileCreated(model: AccountCreationModel, saveProfile: Boolean) { fun profileCreated(model: AccountCreationModel, saveProfile: Boolean) {
view!!.blockOrientation() view!!.blockOrientation()
view!!.displayProgress(true) view!!.displayProgress(true)
var newAccount = model.accountObservable!!.filter { a: Account -> var newAccount = model.accountObservable!!.filter { a: Account -> a.registrationState != AccountConfig.RegistrationState.INITIALIZING
val newState = a.registrationState
!(newState.isEmpty() || newState.contentEquals(AccountConfig.STATE_INITIALIZING))
} }
.firstOrError() .firstOrError()
if (saveProfile) { if (saveProfile) {
...@@ -229,12 +221,10 @@ class AccountWizardPresenter @Inject constructor( ...@@ -229,12 +221,10 @@ class AccountWizardPresenter @Inject constructor(
val view = view val view = view
if (view != null) { if (view != null) {
view.displayProgress(false) view.displayProgress(false)
val newState = account.registrationState when (account.registrationState) {
Log.w(TAG, "newState $newState") AccountConfig.RegistrationState.ERROR_GENERIC -> view.displayGenericError()
when (newState) { AccountConfig.RegistrationState.UNREGISTERED -> { }
AccountConfig.STATE_ERROR_GENERIC -> view.displayGenericError() AccountConfig.RegistrationState.ERROR_NETWORK -> view.displayNetworkError()
AccountConfig.STATE_UNREGISTERED -> { }
AccountConfig.STATE_ERROR_NETWORK -> view.displayNetworkError()
else -> {} else -> {}
} }
view.displaySuccessDialog() view.displaySuccessDialog()
......
...@@ -107,16 +107,16 @@ class SIPCreationPresenter @Inject constructor( ...@@ -107,16 +107,16 @@ class SIPCreationPresenter @Inject constructor(
override fun onNext(account: Account) { override fun onNext(account: Account) {
mAccount = account mAccount = account
when (account.registrationState) { when (account.registrationState) {
AccountConfig.STATE_REGISTERED, AccountConfig.STATE_SUCCESS, AccountConfig.STATE_READY -> { AccountConfig.RegistrationState.REGISTERED -> {
saveProfile(account.accountId) saveProfile(account.accountId)
view?.showRegistrationSuccess() view?.showRegistrationSuccess()
dispose() dispose()
} }
AccountConfig.STATE_ERROR_NETWORK -> { AccountConfig.RegistrationState.ERROR_NETWORK -> {
view?.showRegistrationNetworkError() view?.showRegistrationNetworkError()
dispose() dispose()
} }
AccountConfig.STATE_TRYING, AccountConfig.STATE_UNREGISTERED -> return AccountConfig.RegistrationState.TRYING, AccountConfig.RegistrationState.UNREGISTERED -> return
else -> { else -> {
view?.showRegistrationError() view?.showRegistrationError()
dispose() dispose()
......
...@@ -22,14 +22,12 @@ package net.jami.model ...@@ -22,14 +22,12 @@ package net.jami.model
import io.reactivex.rxjava3.core.* import io.reactivex.rxjava3.core.*
import io.reactivex.rxjava3.core.Observable import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.schedulers.Schedulers
import io.reactivex.rxjava3.subjects.BehaviorSubject import io.reactivex.rxjava3.subjects.BehaviorSubject
import io.reactivex.rxjava3.subjects.PublishSubject import io.reactivex.rxjava3.subjects.PublishSubject
import io.reactivex.rxjava3.subjects.Subject import io.reactivex.rxjava3.subjects.Subject
import net.jami.model.Interaction.InteractionStatus import net.jami.model.Interaction.InteractionStatus
import net.jami.services.AccountService import net.jami.services.AccountService
import net.jami.utils.Log import net.jami.utils.Log
import java.lang.IllegalStateException
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
...@@ -71,6 +69,7 @@ class Account( ...@@ -71,6 +69,7 @@ class Account(
private val contactLocations: MutableMap<Contact, Observable<ContactLocation>> = HashMap() private val contactLocations: MutableMap<Contact, Observable<ContactLocation>> = HashMap()
private val mLocationSubject: Subject<Map<Contact, Observable<ContactLocation>>> = BehaviorSubject.createDefault(contactLocations) private val mLocationSubject: Subject<Map<Contact, Observable<ContactLocation>>> = BehaviorSubject.createDefault(contactLocations)
private val mLocationStartedSubject: Subject<ContactLocationEntry> = PublishSubject.create() private val mLocationStartedSubject: Subject<ContactLocationEntry> = PublishSubject.create()
private val registrationStateSubject = BehaviorSubject.createDefault(AccountConfig.RegistrationState.UNLOADED)
var historyLoader: Single<Account>? = null var historyLoader: Single<Account>? = null
var loadedProfile: Single<Profile>? = null var loadedProfile: Single<Profile>? = null
...@@ -116,7 +115,7 @@ class Account( ...@@ -116,7 +115,7 @@ class Account(
val removed = cache.remove(key) val removed = cache.remove(key)
conversations.remove(key) conversations.remove(key)
//Conversation contactConversation = getByUri(contact.getPrimaryUri()); //Conversation contactConversation = getByUri(contact.getPrimaryUri());
Log.w(TAG, "conversationStarted " + conversation.accountId + " contact " + key + " " + removed) // Log.w(TAG, "conversationStarted " + conversation.accountId + " contact " + key + " " + removed)
/*if (contactConversation != null) { /*if (contactConversation != null) {
conversations.remove(contactConversation.getUri().getUri()); conversations.remove(contactConversation.getUri().getUri());
}*/ }*/
...@@ -453,12 +452,15 @@ class Account( ...@@ -453,12 +452,15 @@ class Account(
config.put(ConfigKey.PROXY_SERVER, proxy) config.put(ConfigKey.PROXY_SERVER, proxy)
} }
val registrationState: String val registrationState: AccountConfig.RegistrationState
get() = mVolatileDetails[ConfigKey.ACCOUNT_REGISTRATION_STATUS] get() = registrationStateSubject.blockingFirst()
val registrationStateObservable: Observable<AccountConfig.RegistrationState>
get() = registrationStateSubject
fun setRegistrationState(registeredState: String, code: Int) { fun setRegistrationState(registeredState: AccountConfig.RegistrationState, code: Int) {
mVolatileDetails.put(ConfigKey.ACCOUNT_REGISTRATION_STATUS, registeredState) //mVolatileDetails.put(ConfigKey.ACCOUNT_REGISTRATION_STATUS, registeredState)
mVolatileDetails.put(ConfigKey.ACCOUNT_REGISTRATION_STATE_CODE, code.toString()) registrationStateSubject.onNext(registeredState)
//mVolatileDetails.put(ConfigKey.ACCOUNT_REGISTRATION_STATE_CODE, code.toString())
} }
fun setVolatileDetails(volatileDetails: Map<String, String>) { fun setVolatileDetails(volatileDetails: Map<String, String>) {
...@@ -504,24 +506,17 @@ class Account( ...@@ -504,24 +506,17 @@ class Account(
val details: HashMap<String, String> val details: HashMap<String, String>
get() = config.all get() = config.all
val isTrying: Boolean val isTrying: Boolean
get() = registrationState.contentEquals(AccountConfig.STATE_TRYING) get() = registrationState == AccountConfig.RegistrationState.TRYING
val isRegistered: Boolean val isRegistered: Boolean
get() = registrationState.contentEquals(AccountConfig.STATE_READY) || registrationState.contentEquals( get() = registrationState == AccountConfig.RegistrationState.REGISTERED
AccountConfig.STATE_REGISTERED
)
val isInError: Boolean val isInError: Boolean
get() { get() {
val state = registrationState val state = registrationState
return (state.contentEquals(AccountConfig.STATE_ERROR) return (state == AccountConfig.RegistrationState.ERROR_AUTH
|| state.contentEquals(AccountConfig.STATE_ERROR_AUTH) || state == AccountConfig.RegistrationState.ERROR_GENERIC
|| state.contentEquals(AccountConfig.STATE_ERROR_CONF_STUN) || state == AccountConfig.RegistrationState.ERROR_HOST
|| state.contentEquals(AccountConfig.STATE_ERROR_EXIST_STUN) || state == AccountConfig.RegistrationState.ERROR_NETWORK
|| state.contentEquals(AccountConfig.STATE_ERROR_GENERIC) || state == AccountConfig.RegistrationState.ERROR_SERVICE_UNAVAILABLE)
|| state.contentEquals(AccountConfig.STATE_ERROR_HOST)
|| state.contentEquals(AccountConfig.STATE_ERROR_NETWORK)
|| state.contentEquals(AccountConfig.STATE_ERROR_NOT_ACCEPTABLE)
|| state.contentEquals(AccountConfig.STATE_ERROR_SERVICE_UNAVAILABLE)
|| state.contentEquals(AccountConfig.STATE_REQUEST_TIMEOUT))
} }
val isIP2IP: Boolean val isIP2IP: Boolean
get() { get() {
...@@ -562,9 +557,7 @@ class Account( ...@@ -562,9 +557,7 @@ class Account(
return if (isIP2IP) defaultNameSip.toString() else displayUri!! return if (isIP2IP) defaultNameSip.toString() else displayUri!!
} }
fun needsMigration(): Boolean { fun needsMigration(): Boolean = AccountConfig.RegistrationState.ERROR_NEED_MIGRATION == registrationState
return AccountConfig.STATE_NEED_MIGRATION == registrationState
}
val deviceId: String val deviceId: String
get() = getDetail(ConfigKey.ACCOUNT_DEVICE_ID)!! get() = getDetail(ConfigKey.ACCOUNT_DEVICE_ID)!!
......
...@@ -55,23 +55,22 @@ class AccountConfig(details: Map<String, String>) { ...@@ -55,23 +55,22 @@ class AccountConfig(details: Map<String, String>) {
const val FALSE_STR = "false" const val FALSE_STR = "false"
const val ACCOUNT_TYPE_JAMI = "RING" const val ACCOUNT_TYPE_JAMI = "RING"
const val ACCOUNT_TYPE_SIP = "SIP" const val ACCOUNT_TYPE_SIP = "SIP"
const val STATE_REGISTERED = "REGISTERED"
const val STATE_READY = "READY"
const val STATE_UNREGISTERED = "UNREGISTERED"
const val STATE_TRYING = "TRYING"
const val STATE_ERROR = "ERROR"
const val STATE_ERROR_GENERIC = "ERROR_GENERIC"
const val STATE_ERROR_AUTH = "ERROR_AUTH"
const val STATE_ERROR_NETWORK = "ERROR_NETWORK"
const val STATE_ERROR_HOST = "ERROR_HOST"
const val STATE_ERROR_CONF_STUN = "ERROR_CONF_STUN"
const val STATE_ERROR_EXIST_STUN = "ERROR_EXIST_STUN"
const val STATE_ERROR_SERVICE_UNAVAILABLE = "ERROR_SERVICE_UNAVAILABLE"
const val STATE_ERROR_NOT_ACCEPTABLE = "ERROR_NOT_ACCEPTABLE"
const val STATE_REQUEST_TIMEOUT = "Request Timeout" const val STATE_REQUEST_TIMEOUT = "Request Timeout"
const val STATE_INITIALIZING = "INITIALIZING"
const val STATE_NEED_MIGRATION = "ERROR_NEED_MIGRATION"
const val STATE_SUCCESS = "SUCCESS" const val STATE_SUCCESS = "SUCCESS"
const val STATE_INVALID = "INVALID" const val STATE_INVALID = "INVALID"
} }
enum class RegistrationState {
UNLOADED,
UNREGISTERED,
TRYING,
REGISTERED,
ERROR_GENERIC,
ERROR_AUTH,
ERROR_NETWORK,
ERROR_HOST,
ERROR_SERVICE_UNAVAILABLE,
ERROR_NEED_MIGRATION,
INITIALIZING
}
} }
\ No newline at end of file
...@@ -997,25 +997,26 @@ class AccountService( ...@@ -997,25 +997,26 @@ class AccountService(
} }
fun registrationStateChanged(accountId: String, newState: String, code: Int, detailString: String?) { fun registrationStateChanged(accountId: String, newState: String, code: Int, detailString: String?) {
//Log.d(TAG, "registrationStateChanged: " + accountId + ", " + newState + ", " + code + ", " + detailString); Log.d(TAG, "registrationStateChanged: $accountId, $newState, $code, $detailString")
val account = getAccount(accountId) ?: return val account = getAccount(accountId) ?: return
val state = AccountConfig.RegistrationState.valueOf(newState)
val oldState = account.registrationState val oldState = account.registrationState
if (oldState.contentEquals(AccountConfig.STATE_INITIALIZING) && !newState.contentEquals(AccountConfig.STATE_INITIALIZING)) { if (oldState == AccountConfig.RegistrationState.INITIALIZING && state != AccountConfig.RegistrationState.INITIALIZING) {
account.setDetails(JamiService.getAccountDetails(account.accountId).toNative()) account.setDetails(JamiService.getAccountDetails(account.accountId).toNative())
account.setCredentials(JamiService.getCredentials(account.accountId).toNative()) account.setCredentials(JamiService.getCredentials(account.accountId).toNative())
account.devices = JamiService.getKnownRingDevices(account.accountId).toNative() account.devices = JamiService.getKnownRingDevices(account.accountId).toNative()
account.setVolatileDetails(JamiService.getVolatileAccountDetails(account.accountId).toNative()) account.setVolatileDetails(JamiService.getVolatileAccountDetails(account.accountId).toNative())
} else { } else {
account.setRegistrationState(newState, code) account.setRegistrationState(state, code)
} }
if (oldState != newState) { if (oldState != state) {
observableAccounts.onNext(account) observableAccounts.onNext(account)
} }
} }
fun accountDetailsChanged(accountId: String, details: Map<String, String>) { fun accountDetailsChanged(accountId: String, details: Map<String, String>) {
val account = getAccount(accountId) ?: return val account = getAccount(accountId) ?: return
Log.d(TAG, "accountDetailsChanged: " + accountId + " " + details.size) Log.d(TAG, "accountDetailsChanged: $accountId ${details.size}")
account.setDetails(details) account.setDetails(details)
observableAccounts.onNext(account) observableAccounts.onNext(account)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment