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