Skip to content

Add support for chat deep link with chatContext #1971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.google.firebase.messaging.RemoteMessage
import com.hedvig.android.core.common.android.notification.setupNotificationChannel
import com.hedvig.android.logger.LogPriority
import com.hedvig.android.logger.logcat
import com.hedvig.android.navigation.core.AppDestination
import com.hedvig.android.navigation.core.HedvigDeepLinkContainer
import com.hedvig.android.notification.core.NotificationSender
import com.hedvig.android.notification.core.sendHedvigNotification
Expand Down Expand Up @@ -98,7 +99,10 @@ class ChatNotificationSender(
style: NotificationCompat.MessagingStyle,
alertOnlyOnce: Boolean = false,
) {
val chatIntent = Intent(Intent.ACTION_VIEW, Uri.parse(hedvigDeepLinkContainer.chat))
val chatIntent = Intent(
Intent.ACTION_VIEW,
Uri.parse(hedvigDeepLinkContainer.chat.createDeepLinkRoute(AppDestination.Chat.ChatContext.CLAIMS)),
)

val pendingIntent: PendingIntent? = TaskStackBuilder
.create(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fun NavGraphBuilder.chatGraph(
) {
composable<AppDestination.Chat>(
deepLinks = listOf(
navDeepLink { uriPattern = hedvigDeepLinkContainer.chat },
navDeepLink { uriPattern = hedvigDeepLinkContainer.chat.uriPattern },
),
enterTransition = { slideIntoContainer(towards = AnimatedContentTransitionScope.SlideDirection.Up) },
exitTransition = { slideOutOfContainer(towards = AnimatedContentTransitionScope.SlideDirection.Down) },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.hedvig.android.navigation.core

import com.hedvig.android.core.buildconstants.HedvigBuildConstants
import kotlinx.serialization.descriptors.elementNames

interface HedvigDeepLinkContainer {
val home: String // Home destination, the start destination of the app
val insurances: String // The insurances destination, which also shows cross sells
val forever: String // The forever/referrals destination, showing the existing discount and the unique code
val profile: String // The profile screen, which acts as a gateway to several app settings
val eurobonus: String // The destination allowing to edit your current Eurobonus (SAS) number
val chat: String // Hedvig Chat
val chat: HedvigDeepLinkWithParameters<AppDestination.Chat.ChatContext?> // Hedvig Chat
val connectPayment: String // Screen where the member can connect their payment method to Hedvig to pay for insurance
val directDebit: String // Same as connectPayment but to support an old link to it
val payments: String // The payments screen, showing the payments history and the upcoming payment information
Expand All @@ -17,6 +18,11 @@ interface HedvigDeepLinkContainer {
val helpCenterQuestion: String // A specific question inside the help center
}

interface HedvigDeepLinkWithParameters<Params> {
val uriPattern: String
fun createDeepLinkRoute(params: Params): String
}

internal class HedvigDeepLinkContainerImpl(
hedvigBuildConstants: HedvigBuildConstants,
) : HedvigDeepLinkContainer {
Expand All @@ -28,15 +34,35 @@ internal class HedvigDeepLinkContainerImpl(
override val forever: String = "$baseDeepLinkDomain/forever"
override val profile: String = "$baseDeepLinkDomain/profile"
override val eurobonus: String = "$baseDeepLinkDomain/eurobonus"
override val chat: String = "$baseDeepLinkDomain/chat"
override val chat: HedvigDeepLinkWithParameters<AppDestination.Chat.ChatContext?> =
object : HedvigDeepLinkWithParameters<AppDestination.Chat.ChatContext?> {
val chatContextParameterName = run {
val elements = AppDestination.Chat.serializer().descriptor.elementNames.toList()
val chatContextName = elements.first()
require(elements.size == 1 && chatContextName == "chatContext") {
"If the Chat destination object changes, the way the deep link is created needs to be updated along with it"
}
elements
}
override val uriPattern: String = "$baseDeepLinkDomain/chat?$chatContextParameterName={$chatContextParameterName}"
override fun createDeepLinkRoute(params: AppDestination.Chat.ChatContext?): String {
val chatContext = params
if (chatContext == null) {
return "$baseDeepLinkDomain/chat"
} else {
val enumIndex = chatContext.ordinal
return "$baseDeepLinkDomain/chat?$chatContextParameterName=$enumIndex\""
}
}
}
override val connectPayment: String = "$baseDeepLinkDomain/connect-payment"
override val directDebit: String = "$baseDeepLinkDomain/direct-debit"
override val payments: String = "$baseDeepLinkDomain/payments"
override val helpCenter: String = "$baseDeepLinkDomain/help-center"

// Sample url: https://hedvigdevelop.page.link/help-center/topic?id=1
override val helpCenterCommonTopic: String = "$baseDeepLinkDomain/help-center/topic&id={id}"
override val helpCenterCommonTopic: String = "$baseDeepLinkDomain/help-center/topic?id={id}"

// Sample url: https://hedvigdevelop.page.link/help-center/question?id=2
override val helpCenterQuestion: String = "$baseDeepLinkDomain/help-center/question&id={id}"
override val helpCenterQuestion: String = "$baseDeepLinkDomain/help-center/question?id={id}"
}