avoiding null unwrapping by merging the contains check with eagerly throwing if the session component is missing

This commit is contained in:
Adam Brown 2021-11-08 17:14:00 +00:00
parent 528c5a3671
commit 9c1d6e0484
1 changed files with 2 additions and 4 deletions

View File

@ -52,10 +52,8 @@ internal class SessionManager @Inject constructor(private val matrixComponent: M
}
fun stopSession(sessionId: String) {
if (sessionComponents.containsKey(sessionId).not()) {
throw RuntimeException("You don't have a session for id $sessionId")
}
sessionComponents[sessionId]!!.session().stopSync()
val sessionComponent = sessionComponents[sessionId] ?: throw RuntimeException("You don't have a session for id $sessionId")
sessionComponent.session().stopSync()
}
fun getOrCreateSessionComponent(sessionParams: SessionParams): SessionComponent {