mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Simplify code
This commit is contained in:
parent
d867b1345f
commit
b85c76b172
@ -122,9 +122,9 @@ object MatrixPatterns {
|
||||
*/
|
||||
fun isEventId(str: String?): Boolean {
|
||||
return str != null
|
||||
&& (str matches PATTERN_CONTAIN_MATRIX_EVENT_IDENTIFIER
|
||||
|| str matches PATTERN_CONTAIN_MATRIX_EVENT_IDENTIFIER_V3
|
||||
|| str matches PATTERN_CONTAIN_MATRIX_EVENT_IDENTIFIER_V4)
|
||||
&& (str matches PATTERN_CONTAIN_MATRIX_EVENT_IDENTIFIER
|
||||
|| str matches PATTERN_CONTAIN_MATRIX_EVENT_IDENTIFIER_V3
|
||||
|| str matches PATTERN_CONTAIN_MATRIX_EVENT_IDENTIFIER_V4)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -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() }
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user