crypto: Use a when instead of a big if/else statement

This commit is contained in:
Damir Jelić 2021-06-25 08:13:19 +02:00
parent 948aa1a141
commit b53b0a0093

View file

@ -706,26 +706,30 @@ internal class DefaultCryptoService @Inject constructor(
// Notify the our listeners about room keys so decryption is retried.
if (toDeviceEvents.events != null) {
toDeviceEvents.events.forEach { event ->
if (event.type == EventType.ROOM_KEY) {
when (event.type) {
EventType.ROOM_KEY -> {
val content = event.getClearContent().toModel<RoomKeyContent>() ?: return@forEach
val roomId = content.sessionId ?: return@forEach
val sessionId = content.sessionId
notifyRoomKeyReceival(roomId, sessionId)
} else if (event.type == EventType.FORWARDED_ROOM_KEY) {
notifyRoomKeyReceived(roomId, sessionId)
}
EventType.FORWARDED_ROOM_KEY -> {
val content = event.getClearContent().toModel<ForwardedRoomKeyContent>() ?: return@forEach
val roomId = content.sessionId ?: return@forEach
val sessionId = content.sessionId
notifyRoomKeyReceival(roomId, sessionId)
} else {
notifyRoomKeyReceived(roomId, sessionId)
}
else -> {
this.verificationService?.onEvent(event)
}
}
}
}
}
private suspend fun preshareRoomKey(roomId: String, roomMembers: List<String>) {
keyClaimLock.withLock {