mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Better code
This commit is contained in:
parent
3b0624ea40
commit
3ee5a7f54d
@ -56,23 +56,23 @@ object PermalinkParser {
|
|||||||
|
|
||||||
val identifier = params.getOrNull(0)
|
val identifier = params.getOrNull(0)
|
||||||
val extraParameter = params.getOrNull(1)
|
val extraParameter = params.getOrNull(1)
|
||||||
if (identifier.isNullOrEmpty()) {
|
|
||||||
return PermalinkData.FallbackLink(uri)
|
|
||||||
}
|
|
||||||
return when {
|
return when {
|
||||||
|
identifier.isNullOrEmpty() -> PermalinkData.FallbackLink(uri)
|
||||||
MatrixPatterns.isUserId(identifier) -> PermalinkData.UserLink(userId = identifier)
|
MatrixPatterns.isUserId(identifier) -> PermalinkData.UserLink(userId = identifier)
|
||||||
MatrixPatterns.isGroupId(identifier) -> PermalinkData.GroupLink(groupId = identifier)
|
MatrixPatterns.isGroupId(identifier) -> PermalinkData.GroupLink(groupId = identifier)
|
||||||
MatrixPatterns.isRoomId(identifier) -> {
|
MatrixPatterns.isRoomId(identifier) -> {
|
||||||
val eventId = extraParameter.takeIf {
|
PermalinkData.RoomLink(
|
||||||
!it.isNullOrEmpty() && MatrixPatterns.isEventId(it)
|
roomIdOrAlias = identifier,
|
||||||
}
|
isRoomAlias = false,
|
||||||
PermalinkData.RoomLink(roomIdOrAlias = identifier, isRoomAlias = false, eventId = eventId)
|
eventId = extraParameter.takeIf { !it.isNullOrEmpty() && MatrixPatterns.isEventId(it) }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
MatrixPatterns.isRoomAlias(identifier) -> {
|
MatrixPatterns.isRoomAlias(identifier) -> {
|
||||||
val eventId = extraParameter.takeIf {
|
PermalinkData.RoomLink(
|
||||||
!it.isNullOrEmpty() && MatrixPatterns.isEventId(it)
|
roomIdOrAlias = identifier,
|
||||||
}
|
isRoomAlias = true,
|
||||||
PermalinkData.RoomLink(roomIdOrAlias = identifier, isRoomAlias = true, eventId = eventId)
|
eventId = extraParameter.takeIf { !it.isNullOrEmpty() && MatrixPatterns.isEventId(it) }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
else -> PermalinkData.FallbackLink(uri)
|
else -> PermalinkData.FallbackLink(uri)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user