From cc6263b20f5dce54cdf337b5499210686d5d002b Mon Sep 17 00:00:00 2001 From: ganfra Date: Fri, 28 May 2021 10:29:21 +0200 Subject: [PATCH] Fix crash on signout --- .../android/sdk/internal/session/SessionListeners.kt | 8 +++++--- newsfragment/3424.bugfix | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 newsfragment/3424.bugfix diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/SessionListeners.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/SessionListeners.kt index 5f529b3e66..d5c661b1e4 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/SessionListeners.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/SessionListeners.kt @@ -20,6 +20,7 @@ import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.internal.SessionManager import org.matrix.android.sdk.internal.di.SessionId +import timber.log.Timber import javax.inject.Inject @SessionScope @@ -43,15 +44,16 @@ internal class SessionListeners @Inject constructor( fun dispatch(block: (Session, Session.Listener) -> Unit) { synchronized(listeners) { - val session = getSession() + val session = getSession() ?: return Unit.also { + Timber.w("You don't have any attached session") + } listeners.forEach { tryOrNull { block(session, it) } } } } - private fun getSession(): Session { + private fun getSession(): Session? { return sessionManager.getSessionComponent(sessionId)?.session() - ?: throw IllegalStateException("No session found with this id.") } } diff --git a/newsfragment/3424.bugfix b/newsfragment/3424.bugfix new file mode 100644 index 0000000000..db66595cbd --- /dev/null +++ b/newsfragment/3424.bugfix @@ -0,0 +1 @@ +Fix app crashing when signing out \ No newline at end of file