Simplify code

This commit is contained in:
Benoit Marty 2020-02-20 18:05:53 +01:00
parent d867b1345f
commit b85c76b172
2 changed files with 8 additions and 20 deletions

View File

@ -144,14 +144,6 @@ object MatrixPatterns {
* @return null if not found or if matrixId is null
*/
fun extractServerNameFromId(matrixId: String?): String? {
if (matrixId == null) {
return null
}
val index = matrixId.indexOf(":")
return if (index == -1) {
null
} else matrixId.substring(index + 1)
return matrixId?.substringAfter(":", missingDelimiterValue = "")?.takeIf { it.isNotEmpty() }
}
}

View File

@ -297,15 +297,11 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
if (isRoomJoined) {
setState { copy(tombstoneEventHandling = Success(roomId)) }
} else {
val viaServer = MatrixPatterns.extractServerNameFromId(action.event.senderId).let {
if (it.isNullOrBlank()) {
emptyList()
} else {
listOf(it)
}
}
val viaServers = MatrixPatterns.extractServerNameFromId(action.event.senderId)
?.let { listOf(it) }
.orEmpty()
session.rx()
.joinRoom(roomId, viaServers = viaServer)
.joinRoom(roomId, viaServers = viaServers)
.map { roomId }
.execute {
copy(tombstoneEventHandling = it)