Skip to content

Commit 2fdf344

Browse files
authored
Implement deep link for profile links (#332)
1 parent 535ae09 commit 2fdf344

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,20 @@
7575
android:scheme="https" />
7676
</intent-filter>
7777

78+
<intent-filter
79+
android:autoVerify="true"
80+
android:label="Primal Profile">
81+
<action android:name="android.intent.action.VIEW" />
82+
83+
<category android:name="android.intent.category.DEFAULT" />
84+
<category android:name="android.intent.category.BROWSABLE" />
85+
86+
<data
87+
android:host="primal.net"
88+
android:pathPrefix="/p/"
89+
android:scheme="https" />
90+
</intent-filter>
91+
7892
<intent-filter android:label="Wallet Connect">
7993
<action android:name="android.intent.action.VIEW" />
8094

@@ -95,6 +109,7 @@
95109
<data android:scheme="nostrnwc+primal" />
96110
<data android:host="connect"/>
97111
</intent-filter>
112+
98113
</activity>
99114

100115
<provider

app/src/main/kotlin/net/primal/android/navigation/deeplinking/DeepLinkingHandler.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import net.primal.android.user.domain.isNwcUrl
88
import net.primal.android.user.domain.parseNWCUrl
99

1010
private val PRIMAL_NOTE_REGEX = Regex("https://.*primal.net/e/")
11+
private val PRIMAL_PROFILE_REGEX = Regex("https://.*primal.net/p/")
1112

1213
private const val NOSTR_WALLET_CONNECT_SCHEMA = "nostr+walletconnect://"
1314
private const val NOSTR_WALLET_CONNECT_ALT_SCHEMA = "nostrwalletconnect://"
@@ -22,6 +23,11 @@ fun String.parseDeepLinkOrNull(): DeepLink? =
2223
unknownNoteIdentifier.resolveNoteId()?.let { DeepLink.Note(it) }
2324
}
2425

26+
PRIMAL_PROFILE_REGEX.containsMatchIn(this) -> {
27+
val unknownProfileIdentifier = PRIMAL_PROFILE_REGEX.replace(this, "")
28+
unknownProfileIdentifier.resolveProfileId()?.let { DeepLink.Profile(it) }
29+
}
30+
2531
isNostrWalletConnectSchemaAndUrl() ->
2632
runCatching {
2733
DeepLink.NostrWalletConnect(nwc = this.parseNWCUrl())
@@ -35,6 +41,16 @@ fun String.parseDeepLinkOrNull(): DeepLink? =
3541
else -> null
3642
}
3743

44+
private fun String.resolveProfileId(): String? =
45+
when {
46+
this.startsWith("npub") -> runCatching { bech32ToHexOrThrow() }.getOrNull()
47+
this.startsWith("nprofile1") -> {
48+
val pubkey = Nip19TLV.parseUriAsNprofileOrNull(this)?.pubkey
49+
runCatching { pubkey?.bech32ToHexOrThrow() }.getOrNull()
50+
}
51+
else -> this
52+
}
53+
3854
private fun String.resolveNoteId(): String? =
3955
when {
4056
this.startsWith("note1") -> runCatching { bech32ToHexOrThrow() }.getOrNull()

0 commit comments

Comments
 (0)