Skip to content

Commit

Permalink
Implement deep link for article links (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmedalijaK authored Feb 21, 2025
1 parent 2fdf344 commit 5c328f6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
14 changes: 14 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 Article">
<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="/a/"
android:scheme="https" />
</intent-filter>

<intent-filter
android:autoVerify="true"
android:label="Primal Profile">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,11 @@ fun SharedTransitionScope.PrimalAppNavigation() {
)
}

is DeepLink.Article -> {
navController.popBackStack()
navController.navigateToArticleDetails(deepLink.naddr)
}

null -> navController.navigateToHome()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ sealed class DeepLink {
data class NostrWalletConnect(val nwc: net.primal.android.user.domain.NostrWalletConnect) : DeepLink()
data class Profile(val pubkey: String) : DeepLink()
data class Note(val noteId: String) : DeepLink()
data class Article(val naddr: String) : DeepLink()
data class PrimalNWC(val primalWalletNwc: PrimalWalletNwc) : DeepLink()
}
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_ARTICLE_REGEX = Regex("https://.*primal.net/a/")
private val PRIMAL_PROFILE_REGEX = Regex("https://.*primal.net/p/")

private const val NOSTR_WALLET_CONNECT_SCHEMA = "nostr+walletconnect://"
Expand All @@ -28,6 +29,11 @@ fun String.parseDeepLinkOrNull(): DeepLink? =
unknownProfileIdentifier.resolveProfileId()?.let { DeepLink.Profile(it) }
}

PRIMAL_ARTICLE_REGEX.containsMatchIn(this) -> {
val unknownArticleIdentifier = PRIMAL_ARTICLE_REGEX.replace(this, "")
unknownArticleIdentifier.let { DeepLink.Article(it) }
}

isNostrWalletConnectSchemaAndUrl() ->
runCatching {
DeepLink.NostrWalletConnect(nwc = this.parseNWCUrl())
Expand Down

0 comments on commit 5c328f6

Please sign in to comment.