Skip to content

Commit

Permalink
Implement deep link for profile links (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmedalijaK authored Feb 21, 2025
1 parent 535ae09 commit 2fdf344
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@
android:scheme="https" />
</intent-filter>

<intent-filter
android:autoVerify="true"
android:label="Primal Profile">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="primal.net"
android:pathPrefix="/p/"
android:scheme="https" />
</intent-filter>

<intent-filter android:label="Wallet Connect">
<action android:name="android.intent.action.VIEW" />

Expand All @@ -95,6 +109,7 @@
<data android:scheme="nostrnwc+primal" />
<data android:host="connect"/>
</intent-filter>

</activity>

<provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import net.primal.android.user.domain.isNwcUrl
import net.primal.android.user.domain.parseNWCUrl

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

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

PRIMAL_PROFILE_REGEX.containsMatchIn(this) -> {
val unknownProfileIdentifier = PRIMAL_PROFILE_REGEX.replace(this, "")
unknownProfileIdentifier.resolveProfileId()?.let { DeepLink.Profile(it) }
}

isNostrWalletConnectSchemaAndUrl() ->
runCatching {
DeepLink.NostrWalletConnect(nwc = this.parseNWCUrl())
Expand All @@ -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()
Expand Down

0 comments on commit 2fdf344

Please sign in to comment.