Skip to content

Commit

Permalink
Shared add notification id to notification context (#665)
Browse files Browse the repository at this point in the history
^ALTAPPS-984
  • Loading branch information
ivan-magda authored Sep 20, 2023
1 parent f58e2b8 commit 4d25700
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ extension NotificationsService {
case pushNotificationData
case image
case fcmOptions = "fcm_options"
case notificationID = "notification_id"
}
}

Expand Down Expand Up @@ -177,6 +178,9 @@ extension NotificationsService {
}

// Set necessary keys to aps dict (see shared PushNotificationData.kt)
if let notificationID = userInfo[PayloadKey.notificationID.rawValue] {
apsDict[PayloadKey.notificationID.rawValue] = notificationID
}
if let badgeID = userInfo[PayloadKey.badge.rawValue] {
apsDict[PayloadKey.badge.rawValue] = badgeID
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import org.hyperskill.app.notification.remote.domain.model.PushNotificationData
* "context":
* {
* "type": "STREAK_THREE" || "SELECT_FIRST_TRACK" || ...,
* "group": "Routine learning" || "Re-engagement" || ...
* "category": "Routine learning" || "Re-engagement" || ...,
* "image": "https://hyperskill.org/image.png",
* "notification_id": "12345"
* }
* }
* ```
Expand All @@ -36,10 +38,6 @@ class PushNotificationClickedHyperskillAnalyticEvent(
) {
override val params: Map<String, Any>
get() = super.params + mapOf(
PARAM_CONTEXT to mapOf(
PushNotificationHyperskillAnalyticParams.PARAM_TYPE to pushNotificationData.typeString,
PushNotificationHyperskillAnalyticParams.PARAM_CATEGORY to pushNotificationData.categoryString,
PushNotificationHyperskillAnalyticParams.PARAM_IMAGE to pushNotificationData.image
)
PARAM_CONTEXT to PushNotificationDataAnalyticContextMapper.map(pushNotificationData)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.hyperskill.app.notification.remote.domain.analytic

import org.hyperskill.app.notification.remote.domain.model.PushNotificationData
import ru.nobird.app.core.model.mapOfNotNull

internal object PushNotificationDataAnalyticContextMapper {
fun map(pushNotificationData: PushNotificationData): Map<String, Any> =
mapOfNotNull(
PushNotificationHyperskillAnalyticParams.PARAM_TYPE to pushNotificationData.typeString,
PushNotificationHyperskillAnalyticParams.PARAM_CATEGORY to pushNotificationData.categoryString,
PushNotificationHyperskillAnalyticParams.PARAM_IMAGE to pushNotificationData.image,
PushNotificationHyperskillAnalyticParams.PARAM_NOTIFICATION_ID to pushNotificationData.notificationId
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ internal object PushNotificationHyperskillAnalyticParams {
const val PARAM_TYPE = "type"
const val PARAM_CATEGORY = "category"
const val PARAM_IMAGE = "image"
const val PARAM_NOTIFICATION_ID = "notification_id"
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import org.hyperskill.app.notification.remote.domain.model.PushNotificationData
* "context":
* {
* "type": "STREAK_THREE" || "SELECT_FIRST_TRACK" || ...,
* "group": "Routine learning" || "Re-engagement" || ...
* "category": "Routine learning" || "Re-engagement" || ...,
* "image": "https://hyperskill.org/image.png",
* "notification_id": "12345"
* }
* }
* ```
Expand All @@ -36,9 +38,6 @@ class PushNotificationShownHyperskillAnalyticEvent(
) {
override val params: Map<String, Any>
get() = super.params + mapOf(
PARAM_CONTEXT to mapOf(
PushNotificationHyperskillAnalyticParams.PARAM_TYPE to pushNotificationData.typeString,
PushNotificationHyperskillAnalyticParams.PARAM_CATEGORY to pushNotificationData.categoryString
)
PARAM_CONTEXT to PushNotificationDataAnalyticContextMapper.map(pushNotificationData)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import kotlinx.serialization.Serializable

@Serializable
data class PushNotificationData(
@SerialName("notification_id")
val notificationId: String? = null,
@SerialName("category")
val typeString: String,
@SerialName("thread-id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class AppFeatureTest {
AppFeature.Message.UserAccountStatus(
Profile.stub(isGuest = true, trackId = 1),
PushNotificationData(
PushNotificationType.STREAK_NEW.name,
PushNotificationCategory.CONTINUE_LEARNING.backendName!!
typeString = PushNotificationType.STREAK_NEW.name,
categoryString = PushNotificationCategory.CONTINUE_LEARNING.backendName!!
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class NotificationClickHandlingFeatureTest {
NotificationClickHandlingFeature.State,
NotificationClickHandlingFeature.Message.NotificationClicked(
PushNotificationData(
PushNotificationType.STREAK_NEW.name,
PushNotificationCategory.CONTINUE_LEARNING.backendName!!
typeString = PushNotificationType.STREAK_NEW.name,
categoryString = PushNotificationCategory.CONTINUE_LEARNING.backendName!!
),
isUserAuthorized = false,
notificationLaunchedApp = true
Expand All @@ -38,8 +38,8 @@ class NotificationClickHandlingFeatureTest {
NotificationClickHandlingFeature.State,
NotificationClickHandlingFeature.Message.NotificationClicked(
PushNotificationData(
PushNotificationType.STREAK_NEW.name,
PushNotificationCategory.CONTINUE_LEARNING.backendName!!
typeString = PushNotificationType.STREAK_NEW.name,
categoryString = PushNotificationCategory.CONTINUE_LEARNING.backendName!!
),
isUserAuthorized = true,
notificationLaunchedApp = true
Expand Down

0 comments on commit 4d25700

Please sign in to comment.