mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 21:32:34 +00:00
Avoid code duplication
This commit is contained in:
@@ -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(
|
||||||
|
|||||||
Reference in New Issue
Block a user