Avoid code duplication

This commit is contained in:
Benoit Marty 2025-08-06 16:13:07 +02:00
parent 1a335698c0
commit 37786352ba

View file

@ -42,12 +42,7 @@ class MatrixSessionCache @Inject constructor(
init { init {
authenticationService.listenToNewMatrixClients { matrixClient -> authenticationService.listenToNewMatrixClients { matrixClient ->
val syncOrchestrator = syncOrchestratorFactory.create(matrixClient) onMatrixClient(matrixClient)
sessionIdsToMatrixSession[matrixClient.sessionId] = InMemoryMatrixSession(
matrixClient = matrixClient,
syncOrchestrator = syncOrchestrator,
)
syncOrchestrator.start()
} }
} }
@ -105,17 +100,21 @@ class MatrixSessionCache @Inject constructor(
Timber.d("Restore matrix session: $sessionId") Timber.d("Restore matrix session: $sessionId")
return authenticationService.restoreSession(sessionId) return authenticationService.restoreSession(sessionId)
.onSuccess { matrixClient -> .onSuccess { matrixClient ->
val syncOrchestrator = syncOrchestratorFactory.create(matrixClient) onMatrixClient(matrixClient)
sessionIdsToMatrixSession[matrixClient.sessionId] = InMemoryMatrixSession(
matrixClient = matrixClient,
syncOrchestrator = syncOrchestrator,
)
syncOrchestrator.start()
} }
.onFailure { .onFailure {
Timber.e(it, "Fail to restore session") Timber.e(it, "Fail to restore session")
} }
} }
private fun onMatrixClient(matrixClient: MatrixClient) {
val syncOrchestrator = syncOrchestratorFactory.create(matrixClient)
sessionIdsToMatrixSession[matrixClient.sessionId] = InMemoryMatrixSession(
matrixClient = matrixClient,
syncOrchestrator = syncOrchestrator,
)
syncOrchestrator.start()
}
} }
private data class InMemoryMatrixSession( private data class InMemoryMatrixSession(