mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 12:07:28 +00:00
Handle activity and process recreation for session
This commit is contained in:
+1
-1
@@ -23,7 +23,7 @@ import kotlinx.coroutines.flow.Flow
|
||||
interface MatrixAuthenticationService {
|
||||
fun isLoggedIn(): Flow<Boolean>
|
||||
suspend fun getLatestSessionId(): SessionId?
|
||||
suspend fun restoreSession(): MatrixClient?
|
||||
suspend fun restoreSession(sessionId: SessionId): MatrixClient?
|
||||
fun getHomeserver(): String?
|
||||
fun getHomeserverOrDefault(): String
|
||||
suspend fun setHomeserver(homeserver: String)
|
||||
|
||||
+2
-2
@@ -52,8 +52,8 @@ class RustMatrixAuthenticationService @Inject constructor(
|
||||
sessionStore.getLatestSession()?.sessionId()
|
||||
}
|
||||
|
||||
override suspend fun restoreSession() = withContext(coroutineDispatchers.io) {
|
||||
sessionStore.getLatestSession()
|
||||
override suspend fun restoreSession(sessionId: SessionId) = withContext(coroutineDispatchers.io) {
|
||||
sessionStore.getSession(sessionId)
|
||||
?.let { session ->
|
||||
try {
|
||||
ClientBuilder()
|
||||
|
||||
+6
@@ -26,6 +26,7 @@ import com.squareup.anvil.annotations.ContributesBinding
|
||||
import io.element.android.libraries.di.AppScope
|
||||
import io.element.android.libraries.di.ApplicationContext
|
||||
import io.element.android.libraries.di.SingleIn
|
||||
import io.element.android.libraries.matrix.core.SessionId
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.flow.map
|
||||
@@ -94,6 +95,11 @@ class PreferencesSessionStore @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getSession(sessionId: SessionId): Session? {
|
||||
//TODO we should have a proper session management
|
||||
return getLatestSession()
|
||||
}
|
||||
|
||||
override suspend fun reset() {
|
||||
store.edit { it.clear() }
|
||||
}
|
||||
|
||||
+2
@@ -16,12 +16,14 @@
|
||||
|
||||
package io.element.android.libraries.matrix.session
|
||||
|
||||
import io.element.android.libraries.matrix.core.SessionId
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import org.matrix.rustcomponents.sdk.Session
|
||||
|
||||
interface SessionStore {
|
||||
fun isLoggedIn(): Flow<Boolean>
|
||||
suspend fun storeData(session: Session)
|
||||
suspend fun getSession(sessionId: SessionId): Session?
|
||||
suspend fun getLatestSession(): Session?
|
||||
suspend fun reset()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user