From 2fdf344d8be1cf9a2330935cc5e45233a7cefed8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmedalija=20Kari=C5=A1ik?= Date: Fri, 21 Feb 2025 15:55:30 +0100 Subject: [PATCH] Implement deep link for profile links (#332) --- app/src/main/AndroidManifest.xml | 15 +++++++++++++++ .../navigation/deeplinking/DeepLinkingHandler.kt | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 968bd5cce..1a85fe035 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -75,6 +75,20 @@ android:scheme="https" /> + + + + + + + + + @@ -95,6 +109,7 @@ + { + val unknownProfileIdentifier = PRIMAL_PROFILE_REGEX.replace(this, "") + unknownProfileIdentifier.resolveProfileId()?.let { DeepLink.Profile(it) } + } + isNostrWalletConnectSchemaAndUrl() -> runCatching { DeepLink.NostrWalletConnect(nwc = this.parseNWCUrl()) @@ -35,6 +41,16 @@ fun String.parseDeepLinkOrNull(): DeepLink? = else -> null } +private fun String.resolveProfileId(): String? = + when { + this.startsWith("npub") -> runCatching { bech32ToHexOrThrow() }.getOrNull() + this.startsWith("nprofile1") -> { + val pubkey = Nip19TLV.parseUriAsNprofileOrNull(this)?.pubkey + runCatching { pubkey?.bech32ToHexOrThrow() }.getOrNull() + } + else -> this + } + private fun String.resolveNoteId(): String? = when { this.startsWith("note1") -> runCatching { bech32ToHexOrThrow() }.getOrNull()