Fix the case when a valid homeserver url can't be extracted from the MXID (#182)
* Fix the case when a valid homeserver url can't be extracted from the mxid * Add changelog * Add `use` to Rust SDK calls in loginto automatically free memory from Rust objects
This commit is contained in:
committed by
GitHub
parent
0c8d8b62f8
commit
126ad1c8cc
1
changelog.d/182.bugfix
Normal file
1
changelog.d/182.bugfix
Normal file
@@ -0,0 +1 @@
|
||||
Fix the case when a valid homeserver url can't be extracted from the MXID
|
||||
@@ -38,6 +38,7 @@ import org.matrix.rustcomponents.sdk.AuthenticationService
|
||||
import org.matrix.rustcomponents.sdk.Client
|
||||
import org.matrix.rustcomponents.sdk.ClientBuilder
|
||||
import org.matrix.rustcomponents.sdk.Session
|
||||
import org.matrix.rustcomponents.sdk.use
|
||||
import timber.log.Timber
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
@@ -63,22 +64,21 @@ class RustMatrixAuthenticationService @Inject constructor(
|
||||
}
|
||||
|
||||
override suspend fun restoreSession(sessionId: SessionId) = withContext(coroutineDispatchers.io) {
|
||||
sessionStore.getSession(sessionId.value)
|
||||
?.let { sessionData ->
|
||||
try {
|
||||
ClientBuilder()
|
||||
.basePath(baseDirectory.absolutePath)
|
||||
.username(sessionData.userId)
|
||||
.build().apply {
|
||||
restoreSession(sessionData.toSession())
|
||||
}
|
||||
} catch (throwable: Throwable) {
|
||||
logError(throwable)
|
||||
null
|
||||
}
|
||||
}?.let {
|
||||
createMatrixClient(it)
|
||||
val sessionData = sessionStore.getSession(sessionId.value)
|
||||
if (sessionData != null) {
|
||||
try {
|
||||
val client = ClientBuilder()
|
||||
.basePath(baseDirectory.absolutePath)
|
||||
.homeserverUrl(sessionData.homeserverUrl)
|
||||
.username(sessionData.userId)
|
||||
.use { it.build() }
|
||||
client.restoreSession(sessionData.toSession())
|
||||
createMatrixClient(client)
|
||||
} catch (throwable: Throwable) {
|
||||
logError(throwable)
|
||||
null
|
||||
}
|
||||
} else null
|
||||
}
|
||||
|
||||
override fun getHomeserverDetails(): StateFlow<MatrixHomeServerDetails?> = currentHomeserver
|
||||
@@ -101,9 +101,9 @@ class RustMatrixAuthenticationService @Inject constructor(
|
||||
Timber.e(failure, "Fail login")
|
||||
throw failure
|
||||
}
|
||||
val session = client.session()
|
||||
sessionStore.storeData(session.toSessionData())
|
||||
SessionId(session.userId)
|
||||
val sessionData = client.use { it.session().toSessionData() }
|
||||
sessionStore.storeData(sessionData)
|
||||
SessionId(sessionData.userId)
|
||||
}
|
||||
|
||||
private fun createMatrixClient(client: Client): MatrixClient {
|
||||
|
||||
Reference in New Issue
Block a user