Rework DeeplinkParser to fix a test (and fix a bug in release mode).

The test was failing in release mode because there is not check on `RoomId` format, so INVITE_LIST value ("invites") is seen as a valid RoomId.
First check for known paths, then try to parse as RoomId. The tryOrNull will return null only in debug mode, so I think we can remove it.
Error was:
value of: getFromIntent(...)
expected: InviteList(sessionId=@alice:server.org)
but was : Room(sessionId=@alice:server.org, roomId=invites, threadId=null)
	at io.element.android.libraries.deeplink.DeeplinkParserTest.nominal cases(DeeplinkParserTest.kt:54)
This commit is contained in:
Benoit Marty
2023-07-12 09:59:52 +02:00
parent 9644091f3f
commit 0740330b39

View File

@@ -18,7 +18,6 @@ package io.element.android.libraries.deeplink
import android.content.Intent
import android.net.Uri
import io.element.android.libraries.core.data.tryOrNull
import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.matrix.api.core.SessionId
import io.element.android.libraries.matrix.api.core.ThreadId
@@ -37,21 +36,15 @@ class DeeplinkParser @Inject constructor() {
if (host != HOST) return null
val pathBits = path.orEmpty().split("/").drop(1)
val sessionId = pathBits.elementAtOrNull(0)?.let(::SessionId) ?: return null
val screenPathComponent = pathBits.elementAtOrNull(1)
val roomId = tryOrNull { screenPathComponent?.let(::RoomId) }
return when {
roomId != null -> {
return when (val screenPathComponent = pathBits.elementAtOrNull(1)) {
null -> DeeplinkData.Root(sessionId)
DeepLinkPaths.INVITE_LIST -> DeeplinkData.InviteList(sessionId)
else -> {
val roomId = screenPathComponent.let(::RoomId)
val threadId = pathBits.elementAtOrNull(2)?.let(::ThreadId)
DeeplinkData.Room(sessionId, roomId, threadId)
}
screenPathComponent == DeepLinkPaths.INVITE_LIST -> {
DeeplinkData.InviteList(sessionId)
}
screenPathComponent == null -> {
DeeplinkData.Root(sessionId)
}
else -> null
}
}
}