Handle activity and process recreation for session
This commit is contained in:
parent
8dbd8c918b
commit
fa71eab85e
9 changed files with 186 additions and 31 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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() }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue