InvalidToken: notify the app - WIP
This commit is contained in:
parent
d5935a13ac
commit
18649ebddb
|
@ -16,7 +16,8 @@
|
|||
|
||||
package im.vector.matrix.android.api.failure
|
||||
|
||||
// This data class will be sent to the bus
|
||||
data class ConsentNotGivenError(
|
||||
val consentUri: String
|
||||
)
|
||||
// This class will be sent to the bus
|
||||
sealed class GlobalError {
|
||||
data class InvalidToken(val softLogout: Boolean) : GlobalError()
|
||||
data class ConsentNotGivenError(val consentUri: String) : GlobalError()
|
||||
}
|
|
@ -19,7 +19,7 @@ package im.vector.matrix.android.api.session
|
|||
import androidx.annotation.MainThread
|
||||
import androidx.lifecycle.LiveData
|
||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
||||
import im.vector.matrix.android.api.failure.ConsentNotGivenError
|
||||
import im.vector.matrix.android.api.failure.GlobalError
|
||||
import im.vector.matrix.android.api.pushrules.PushRuleService
|
||||
import im.vector.matrix.android.api.session.cache.CacheService
|
||||
import im.vector.matrix.android.api.session.content.ContentUploadStateTracker
|
||||
|
@ -136,13 +136,10 @@ interface Session :
|
|||
*/
|
||||
interface Listener {
|
||||
/**
|
||||
* The access token is not valid anymore
|
||||
* Possible cases:
|
||||
* - The access token is not valid anymore,
|
||||
* - a M_CONSENT_NOT_GIVEN error has been received from the homeserver
|
||||
*/
|
||||
fun onInvalidToken()
|
||||
|
||||
/**
|
||||
* A M_CONSENT_NOT_GIVEN error has been received from the homeserver
|
||||
*/
|
||||
fun onConsentNotGivenError(consentNotGivenError: ConsentNotGivenError)
|
||||
fun onGlobalError(globalError: GlobalError)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@ package im.vector.matrix.android.internal.network
|
|||
|
||||
import com.squareup.moshi.JsonDataException
|
||||
import com.squareup.moshi.JsonEncodingException
|
||||
import im.vector.matrix.android.api.failure.ConsentNotGivenError
|
||||
import im.vector.matrix.android.api.failure.Failure
|
||||
import im.vector.matrix.android.api.failure.GlobalError
|
||||
import im.vector.matrix.android.api.failure.MatrixError
|
||||
import im.vector.matrix.android.internal.di.MoshiProvider
|
||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||
|
@ -99,7 +99,11 @@ private fun toFailure(errorBody: ResponseBody?, httpCode: Int): Failure {
|
|||
if (matrixError != null) {
|
||||
if (matrixError.code == MatrixError.M_CONSENT_NOT_GIVEN && !matrixError.consentUri.isNullOrBlank()) {
|
||||
// Also send this error to the bus, for a global management
|
||||
EventBus.getDefault().post(ConsentNotGivenError(matrixError.consentUri))
|
||||
EventBus.getDefault().post(GlobalError.ConsentNotGivenError(matrixError.consentUri))
|
||||
} else if (matrixError.code == MatrixError.M_UNAUTHORIZED) {
|
||||
// TODO Check that this is ok during the login flow
|
||||
// Also send this error to the bus, for a global management
|
||||
EventBus.getDefault().post(GlobalError.InvalidToken(matrixError.isSoftLogout == true))
|
||||
}
|
||||
|
||||
return Failure.ServerError(matrixError, httpCode)
|
||||
|
|
|
@ -23,7 +23,7 @@ import androidx.lifecycle.LiveData
|
|||
import dagger.Lazy
|
||||
import im.vector.matrix.android.api.MatrixCallback
|
||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
||||
import im.vector.matrix.android.api.failure.ConsentNotGivenError
|
||||
import im.vector.matrix.android.api.failure.GlobalError
|
||||
import im.vector.matrix.android.api.pushrules.PushRuleService
|
||||
import im.vector.matrix.android.api.session.InitialSyncProgressService
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
|
@ -170,8 +170,8 @@ internal class DefaultSession @Inject constructor(override val sessionParams: Se
|
|||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
fun onConsentNotGivenError(consentNotGivenError: ConsentNotGivenError) {
|
||||
sessionListeners.dispatchConsentNotGiven(consentNotGivenError)
|
||||
fun onGlobalError(globalError: GlobalError) {
|
||||
sessionListeners.dispatchGlobalError(globalError)
|
||||
}
|
||||
|
||||
override fun contentUrlResolver() = contentUrlResolver
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package im.vector.matrix.android.internal.session
|
||||
|
||||
import im.vector.matrix.android.api.failure.ConsentNotGivenError
|
||||
import im.vector.matrix.android.api.failure.GlobalError
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -36,10 +36,10 @@ internal class SessionListeners @Inject constructor() {
|
|||
}
|
||||
}
|
||||
|
||||
fun dispatchConsentNotGiven(consentNotGivenError: ConsentNotGivenError) {
|
||||
fun dispatchGlobalError(globalError: GlobalError) {
|
||||
synchronized(listeners) {
|
||||
listeners.forEach {
|
||||
it.onConsentNotGivenError(consentNotGivenError)
|
||||
it.onGlobalError(globalError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ import butterknife.Unbinder
|
|||
import com.airbnb.mvrx.MvRx
|
||||
import com.bumptech.glide.util.Util
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import im.vector.matrix.android.api.failure.GlobalError
|
||||
import im.vector.riotx.BuildConfig
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.di.*
|
||||
|
@ -153,9 +154,8 @@ abstract class VectorBaseActivity : AppCompatActivity(), HasScreenInjector {
|
|||
})
|
||||
|
||||
sessionListener = getVectorComponent().sessionListener()
|
||||
sessionListener.consentNotGivenLiveData.observeEvent(this) {
|
||||
consentNotGivenHelper.displayDialog(it.consentUri,
|
||||
activeSessionHolder.getActiveSession().sessionParams.homeServerConnectionConfig.homeServerUri.host ?: "")
|
||||
sessionListener.globalErrorLiveData.observeEvent(this) {
|
||||
handleGlobalError(it)
|
||||
}
|
||||
|
||||
doBeforeSetContentView()
|
||||
|
@ -180,6 +180,15 @@ abstract class VectorBaseActivity : AppCompatActivity(), HasScreenInjector {
|
|||
}
|
||||
}
|
||||
|
||||
private fun handleGlobalError(globalError: GlobalError) {
|
||||
when (globalError) {
|
||||
is GlobalError.InvalidToken -> TODO()
|
||||
is GlobalError.ConsentNotGivenError ->
|
||||
consentNotGivenHelper.displayDialog(globalError.consentUri,
|
||||
activeSessionHolder.getActiveSession().sessionParams.homeServerConnectionConfig.homeServerUri.host ?: "")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
unBinder?.unbind()
|
||||
|
|
|
@ -18,27 +18,21 @@ package im.vector.riotx.features.session
|
|||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import im.vector.matrix.android.api.failure.ConsentNotGivenError
|
||||
import im.vector.matrix.android.api.failure.GlobalError
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.riotx.core.extensions.postLiveEvent
|
||||
import im.vector.riotx.core.utils.LiveEvent
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class SessionListener @Inject constructor() : Session.Listener {
|
||||
|
||||
private val _consentNotGivenLiveData = MutableLiveData<LiveEvent<ConsentNotGivenError>>()
|
||||
val consentNotGivenLiveData: LiveData<LiveEvent<ConsentNotGivenError>>
|
||||
get() = _consentNotGivenLiveData
|
||||
private val _globalErrorLiveData = MutableLiveData<LiveEvent<GlobalError>>()
|
||||
val globalErrorLiveData: LiveData<LiveEvent<GlobalError>>
|
||||
get() = _globalErrorLiveData
|
||||
|
||||
override fun onInvalidToken() {
|
||||
// TODO Handle this error
|
||||
Timber.e("Token is not valid anymore: handle this properly")
|
||||
}
|
||||
|
||||
override fun onConsentNotGivenError(consentNotGivenError: ConsentNotGivenError) {
|
||||
_consentNotGivenLiveData.postLiveEvent(consentNotGivenError)
|
||||
override fun onGlobalError(globalError: GlobalError) {
|
||||
_globalErrorLiveData.postLiveEvent(globalError)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue