11package com.getcode.util
22
3+ import android.content.Context
34import android.content.Intent
45import android.net.Uri
56import androidx.core.net.toUri
67import cafe.adriel.voyager.core.screen.Screen
8+ import com.getcode.model.BetaFlag
9+ import com.getcode.model.PrefsBool
710import com.getcode.models.DeepLinkRequest
811import com.getcode.models.encode
912import com.getcode.navigation.screens.HomeScreen
1013import com.getcode.navigation.screens.LoginScreen
14+ import com.getcode.network.repository.BetaFlagsRepository
1115import com.getcode.network.repository.encodeBase64
1216import com.getcode.network.repository.urlDecode
17+ import com.getcode.ui.utils.getActivity
1318import com.getcode.utils.TraceType
1419import com.getcode.utils.base64EncodedData
1520import com.getcode.utils.trace
21+ import dagger.hilt.android.qualifiers.ApplicationContext
1622import kotlinx.coroutines.flow.MutableStateFlow
1723import kotlinx.serialization.json.buildJsonObject
1824import kotlinx.serialization.json.put
@@ -39,7 +45,10 @@ data class DeeplinkResult(
3945 * in favour of the latest request in the navigation graph.
4046 */
4147@Singleton
42- class DeeplinkHandler @Inject constructor() {
48+ class DeeplinkHandler @Inject constructor(
49+ @ApplicationContext private val context : Context ,
50+ private val betaFlags : BetaFlagsRepository
51+ ) {
4352 var debounceIntent: Intent ? = null
4453 set(value) {
4554 intent.value = value
@@ -49,12 +58,13 @@ class DeeplinkHandler @Inject constructor() {
4958
5059 val intent = MutableStateFlow (debounceIntent)
5160
52- fun handle (intent : Intent ? = debounceIntent): DeeplinkResult ? {
61+ suspend fun handle (intent : Intent ? = debounceIntent): DeeplinkResult ? {
62+ println (intent)
5363 val uri = when {
5464 intent?.data != null -> intent.data
5565 intent?.getStringExtra(Intent .EXTRA_TEXT ) != null -> {
5666 val sharedLink = intent.getStringExtra(Intent .EXTRA_TEXT )?.toUri() ? : return null
57- sharedLink.resolveSharedEntity
67+ sharedLink.resolveSharedEntity()
5868 }
5969
6070 else -> null
@@ -108,19 +118,19 @@ class DeeplinkHandler @Inject constructor() {
108118 * Handles converting inbound shared content with possible deeplinks
109119 * e.g sharing a tweet to trigger a tipcard flow
110120 */
111- private val Uri .resolveSharedEntity: Uri
112- get() {
113- // https:// x.com/<username>/status/<tweetId>
114- return when {
115- this .host == " x.com " || this .host == " twitter.com " -> {
121+ private suspend fun Uri.resolveSharedEntity () : Uri {
122+ when {
123+ this .host == " x.com" || this .host == " twitter.com " -> {
124+ // https://x.com/<username>/status/<tweetId>
125+ if (betaFlags.isEnabled( PrefsBool . SHARE_TWEET_TO_TIP )) {
116126 // convert shared tweets to owner's tip card
117127 val username = pathSegments.firstOrNull() ? : return this
118- Uri .parse(Linkify .tipCard(username, " x" ))
128+ return Uri .parse(Linkify .tipCard(username, " x" ))
119129 }
120-
121- else -> this
122130 }
123131 }
132+ return this
133+ }
124134
125135 private val Uri .deeplinkType: Type
126136 get() {
0 commit comments