-
Notifications
You must be signed in to change notification settings - Fork 9
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
chore: event bus integration with push #358
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
import io.customer.messagingpush.di.pushMessageProcessor | ||
import io.customer.messagingpush.extensions.getSDKInstanceOrNull | ||
import io.customer.sdk.android.CustomerIO | ||
import io.customer.sdk.communication.Event | ||
import io.customer.sdk.core.di.SDKComponent.eventBus | ||
|
||
open class CustomerIOFirebaseMessagingService : FirebaseMessagingService() { | ||
|
||
|
@@ -91,6 +93,10 @@ | |
} | ||
|
||
private fun handleNewToken(context: Context, token: String) { | ||
eventBus.publish( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest to either create class variable or use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm i thought |
||
Event.RegisterDeviceTokenEvent(token) | ||
Check warning on line 97 in messagingpush/src/main/java/io/customer/messagingpush/CustomerIOFirebaseMessagingService.kt
|
||
) | ||
// todo: remove this | ||
context.getSDKInstanceOrNull()?.registerDeviceToken(deviceToken = token) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,16 +11,16 @@ import io.customer.messagingpush.data.model.CustomerIOParsedPushPayload | |
import io.customer.messagingpush.extensions.parcelable | ||
import io.customer.messagingpush.util.DeepLinkUtil | ||
import io.customer.messagingpush.util.PushTrackingUtil | ||
import io.customer.sdk.communication.Event | ||
import io.customer.sdk.core.di.SDKComponent.eventBus | ||
import io.customer.sdk.core.util.Logger | ||
import io.customer.sdk.data.request.MetricEvent | ||
import io.customer.sdk.extensions.takeIfNotBlank | ||
import io.customer.sdk.repository.TrackRepository | ||
|
||
internal class PushMessageProcessorImpl( | ||
private val logger: Logger, | ||
private val moduleConfig: MessagingPushModuleConfig, | ||
private val deepLinkUtil: DeepLinkUtil, | ||
private val trackRepository: TrackRepository | ||
private val deepLinkUtil: DeepLinkUtil | ||
) : PushMessageProcessor { | ||
|
||
/** | ||
|
@@ -87,10 +87,12 @@ internal class PushMessageProcessorImpl( | |
private fun trackDeliveredMetrics(deliveryId: String, deliveryToken: String) { | ||
// Track delivered event only if auto-tracking is enabled | ||
if (moduleConfig.autoTrackPushEvents) { | ||
trackRepository.trackMetric( | ||
deliveryID = deliveryId, | ||
deviceToken = deliveryToken, | ||
event = MetricEvent.delivered | ||
eventBus.publish( | ||
Event.TrackPushMetricEvent( | ||
event = MetricEvent.delivered.name, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be outside the scope of this PR, but curious if there is a reason for using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
End goal would be to create another |
||
deliveryId = deliveryId, | ||
deviceToken = deliveryToken | ||
) | ||
) | ||
} | ||
} | ||
|
@@ -119,10 +121,12 @@ internal class PushMessageProcessorImpl( | |
|
||
private fun trackNotificationClickMetrics(payload: CustomerIOParsedPushPayload) { | ||
if (moduleConfig.autoTrackPushEvents) { | ||
trackRepository.trackMetric( | ||
deliveryID = payload.cioDeliveryId, | ||
event = MetricEvent.opened, | ||
deviceToken = payload.cioDeliveryToken | ||
eventBus.publish( | ||
Event.TrackPushMetricEvent( | ||
event = MetricEvent.opened.name, | ||
deliveryId = payload.cioDeliveryId, | ||
deviceToken = payload.cioDeliveryToken | ||
) | ||
) | ||
} | ||
} | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package io.customer.messagingpush | ||
|
||
import android.os.Bundle | ||
import io.customer.messagingpush.util.PushTrackingUtil | ||
import io.customer.messagingpush.util.PushTrackingUtilImpl | ||
import io.customer.sdk.communication.Event | ||
import io.customer.sdk.communication.EventBus | ||
import io.customer.sdk.core.di.SDKComponent | ||
import io.customer.sdk.data.request.MetricEvent | ||
import io.customer.sdk.extensions.random | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import org.amshove.kluent.shouldBe | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
|
||
class PushTrackingUtilTest { | ||
|
||
private lateinit var eventBus: EventBus | ||
private lateinit var util: PushTrackingUtil | ||
|
||
@BeforeEach | ||
fun setup() { | ||
util = PushTrackingUtilImpl() | ||
eventBus = mockk(relaxed = true) | ||
SDKComponent.overrideDependency(EventBus::class.java, eventBus) | ||
} | ||
|
||
@Test | ||
fun parseLaunchedActivityForTracking_givenBundleWithoutDeliveryData_expectDoNoTrackPush() { | ||
val givenBundle = mockk<Bundle>() | ||
every { givenBundle.getString("foo") } returns "randomString" | ||
every { givenBundle.getString(PushTrackingUtil.DELIVERY_ID_KEY) } returns null | ||
every { givenBundle.getString(PushTrackingUtil.DELIVERY_TOKEN_KEY) } returns null | ||
|
||
val result = util.parseLaunchedActivityForTracking(givenBundle) | ||
|
||
result shouldBe false | ||
|
||
verify(exactly = 0) { eventBus.publish(any<Event.TrackPushMetricEvent>()) } | ||
} | ||
|
||
@Test | ||
fun parseLaunchedActivityForTracking_givenBundleWithDeliveryData_expectTrackPush() { | ||
val givenDeliveryId = String.random | ||
val givenDeviceToken = String.random | ||
|
||
val givenBundle = mockk<Bundle>() | ||
every { givenBundle.getString(PushTrackingUtil.DELIVERY_ID_KEY) } returns givenDeliveryId | ||
every { givenBundle.getString(PushTrackingUtil.DELIVERY_TOKEN_KEY) } returns givenDeviceToken | ||
|
||
val result = util.parseLaunchedActivityForTracking(givenBundle) | ||
|
||
result shouldBe true | ||
|
||
verify(exactly = 1) { | ||
eventBus.publish( | ||
Event.TrackPushMetricEvent( | ||
deliveryId = givenDeliveryId, | ||
event = MetricEvent.opened.name, | ||
deviceToken = givenDeviceToken | ||
) | ||
) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For future, once we have all modules using JUnit5, we can pull these changes up to common gradle file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, that's the plan 👍