Skip to content

Commit

Permalink
Merge pull request #12580 from woocommerce/issue/12539-notification-t…
Browse files Browse the repository at this point in the history
…ype-api-improvements

Issue/12539 notification type api improvements
  • Loading branch information
JorgeMucientes authored Sep 19, 2024
2 parents 39e1aea + d32fc94 commit d434516
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.woocommerce.android.e2e.screens.TabNavComponent
import com.woocommerce.android.model.Notification
import com.woocommerce.android.notifications.NotificationChannelType
import com.woocommerce.android.notifications.WooNotificationBuilder
import com.woocommerce.android.notifications.WooNotificationType.NEW_ORDER
import com.woocommerce.android.notifications.WooNotificationType.NewOrder

/**
* This is not a screen per-se, as it shows the notification drawer with a push notification.
Expand All @@ -32,7 +32,7 @@ class NotificationsScreen(private val wooNotificationBuilder: WooNotificationBui
icon = "https://s.wp.com/wp-content/mu-plugins/notes/images/update-payment-2x.png",
noteTitle = getTranslatedString(R.string.tests_notification_new_order_title),
noteMessage = getTranslatedString(R.string.tests_notification_new_order_message),
noteType = NEW_ORDER,
noteType = NewOrder,
channelType = NotificationChannelType.NEW_ORDER
),
isGroupNotification = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,13 @@ data class Notification(
val data: String? = null
) : Parcelable {
@IgnoredOnParcel
val isOrderNotification = noteType == WooNotificationType.NEW_ORDER
val isOrderNotification = noteType is WooNotificationType.NewOrder

@IgnoredOnParcel
val isReviewNotification = noteType == WooNotificationType.PRODUCT_REVIEW
val isReviewNotification = noteType is WooNotificationType.ProductReview

@IgnoredOnParcel
val isBlazeNotification = noteType == WooNotificationType.BLAZE_APPROVED_NOTE ||
noteType == WooNotificationType.BLAZE_REJECTED_NOTE ||
noteType == WooNotificationType.BLAZE_CANCELLED_NOTE ||
noteType == WooNotificationType.BLAZE_PERFORMED_NOTE
val isBlazeNotification = noteType is WooNotificationType.BlazeStatusUpdate

/**
* Notifications are grouped based on the notification type and the store the notification belongs to.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,60 @@
package com.woocommerce.android.notifications

import android.os.Parcelable
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize
import org.wordpress.android.fluxc.model.notification.NotificationModel

enum class WooNotificationType {
NEW_ORDER,
PRODUCT_REVIEW,
LOCAL_REMINDER,
BLAZE_APPROVED_NOTE,
BLAZE_REJECTED_NOTE,
BLAZE_CANCELLED_NOTE,
BLAZE_PERFORMED_NOTE,
sealed interface WooNotificationType : Parcelable {
val trackingValue: String

@Parcelize
data object NewOrder : WooNotificationType {
@IgnoredOnParcel override val trackingValue: String = "NEW_ORDER"
}

@Parcelize
data object ProductReview : WooNotificationType {
@IgnoredOnParcel override val trackingValue: String = "PRODUCT_REVIEW"
}

@Parcelize
data object LocalReminder : WooNotificationType {
@IgnoredOnParcel override val trackingValue: String = "LOCAL_REMINDER"
}

@Parcelize
sealed interface BlazeStatusUpdate : WooNotificationType, Parcelable {
@Parcelize
data object BlazeApprovedNote : BlazeStatusUpdate {
@IgnoredOnParcel override val trackingValue: String = "blaze_approved_note"
}

@Parcelize
data object BlazeRejectedNote : BlazeStatusUpdate {
@IgnoredOnParcel override val trackingValue: String = "blaze_rejected_note"
}

@Parcelize
data object BlazeCancelledNote : BlazeStatusUpdate {
@IgnoredOnParcel override val trackingValue: String = "blaze_cancelled_note"
}

@Parcelize
data object BlazePerformedNote : BlazeStatusUpdate {
@IgnoredOnParcel override val trackingValue: String = "blaze_performed_note"
}
}
}

fun NotificationModel.getWooType(): WooNotificationType {
return when (this.type) {
NotificationModel.Kind.STORE_ORDER -> WooNotificationType.NEW_ORDER
NotificationModel.Kind.COMMENT -> WooNotificationType.PRODUCT_REVIEW
NotificationModel.Kind.BLAZE_APPROVED_NOTE -> WooNotificationType.BLAZE_APPROVED_NOTE
NotificationModel.Kind.BLAZE_REJECTED_NOTE -> WooNotificationType.BLAZE_REJECTED_NOTE
NotificationModel.Kind.BLAZE_CANCELLED_NOTE -> WooNotificationType.BLAZE_CANCELLED_NOTE
NotificationModel.Kind.BLAZE_PERFORMED_NOTE -> WooNotificationType.BLAZE_PERFORMED_NOTE
else -> WooNotificationType.LOCAL_REMINDER
NotificationModel.Kind.STORE_ORDER -> WooNotificationType.NewOrder
NotificationModel.Kind.COMMENT -> WooNotificationType.ProductReview
NotificationModel.Kind.BLAZE_APPROVED_NOTE -> WooNotificationType.BlazeStatusUpdate.BlazeApprovedNote
NotificationModel.Kind.BLAZE_REJECTED_NOTE -> WooNotificationType.BlazeStatusUpdate.BlazeRejectedNote
NotificationModel.Kind.BLAZE_CANCELLED_NOTE -> WooNotificationType.BlazeStatusUpdate.BlazeCancelledNote
NotificationModel.Kind.BLAZE_PERFORMED_NOTE -> WooNotificationType.BlazeStatusUpdate.BlazePerformedNote
else -> WooNotificationType.LocalReminder
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.woocommerce.android.analytics.AnalyticsTracker
import com.woocommerce.android.model.Notification
import com.woocommerce.android.notifications.NotificationChannelType.OTHER
import com.woocommerce.android.notifications.WooNotificationBuilder
import com.woocommerce.android.notifications.WooNotificationType.LOCAL_REMINDER
import com.woocommerce.android.notifications.WooNotificationType.LocalReminder
import com.woocommerce.android.notifications.local.LocalNotificationScheduler.Companion.LOCAL_NOTIFICATION_DATA
import com.woocommerce.android.notifications.local.LocalNotificationScheduler.Companion.LOCAL_NOTIFICATION_DESC
import com.woocommerce.android.notifications.local.LocalNotificationScheduler.Companion.LOCAL_NOTIFICATION_ID
Expand Down Expand Up @@ -103,7 +103,7 @@ class LocalNotificationWorker @AssistedInject constructor(
icon = null,
noteTitle = title,
noteMessage = description,
noteType = LOCAL_REMINDER,
noteType = LocalReminder,
channelType = OTHER,
data = data
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class NotificationAnalyticsTracker @Inject constructor(
val isFromSelectedSite = selectedSite.getIfExists()?.siteId == notification.remoteSiteId
val properties = mutableMapOf<String, Any>()
properties["notification_note_id"] = notification.remoteNoteId
properties["notification_type"] = notification.noteType.name
properties["notification_type"] = notification.noteType.trackingValue
properties["push_notification_token"] = appPrefsWrapper.getFCMToken()
properties["is_from_selected_site"] = isFromSelectedSite == true
analyticsTrackerWrapper.track(stat, properties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.woocommerce.android.model.isOrderNotification
import com.woocommerce.android.model.toAppModel
import com.woocommerce.android.notifications.NotificationChannelType
import com.woocommerce.android.notifications.WooNotificationBuilder
import com.woocommerce.android.notifications.WooNotificationType.NEW_ORDER
import com.woocommerce.android.notifications.WooNotificationType.NewOrder
import com.woocommerce.android.tools.SelectedSite
import com.woocommerce.android.util.NotificationsParser
import com.woocommerce.android.util.WooLog.T.NOTIFS
Expand Down Expand Up @@ -128,7 +128,7 @@ class NotificationMessageHandler @Inject constructor(
}

private fun handleWooNotification(notification: Notification) {
val randomNumber = if (notification.noteType == NEW_ORDER) Random.nextInt() else 0
val randomNumber = if (notification.noteType == NewOrder) Random.nextInt() else 0
val localPushId = getLocalPushIdForNoteId(notification.remoteNoteId, randomNumber)
ACTIVE_NOTIFICATIONS_MAP[getLocalPushId(localPushId, randomNumber)] = notification
if (notificationBuilder.isNotificationsEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ import com.woocommerce.android.model.FeatureAnnouncement
import com.woocommerce.android.model.Notification
import com.woocommerce.android.notifications.NotificationChannelType
import com.woocommerce.android.notifications.UnseenReviewsCountHandler
import com.woocommerce.android.notifications.WooNotificationType.BLAZE_APPROVED_NOTE
import com.woocommerce.android.notifications.WooNotificationType.BLAZE_CANCELLED_NOTE
import com.woocommerce.android.notifications.WooNotificationType.BLAZE_PERFORMED_NOTE
import com.woocommerce.android.notifications.WooNotificationType.BLAZE_REJECTED_NOTE
import com.woocommerce.android.notifications.WooNotificationType.LOCAL_REMINDER
import com.woocommerce.android.notifications.WooNotificationType.NEW_ORDER
import com.woocommerce.android.notifications.WooNotificationType.PRODUCT_REVIEW
import com.woocommerce.android.notifications.WooNotificationType
import com.woocommerce.android.notifications.local.LocalNotificationType
import com.woocommerce.android.notifications.local.LocalNotificationType.BLAZE_ABANDONED_CAMPAIGN_REMINDER
import com.woocommerce.android.notifications.local.LocalNotificationType.BLAZE_NO_CAMPAIGN_REMINDER
Expand Down Expand Up @@ -196,7 +190,7 @@ class MainActivityViewModel @Inject constructor(
notificationHandler.markNotificationTapped(notification.remoteNoteId)
notificationHandler.removeNotificationByNotificationIdFromSystemsBar(localPushId)
when (notification.noteType) {
NEW_ORDER -> {
is WooNotificationType.NewOrder -> {
when {
siteStore.getSiteBySiteId(notification.remoteSiteId) != null -> triggerEvent(
ViewOrderDetail(
Expand All @@ -209,22 +203,19 @@ class MainActivityViewModel @Inject constructor(
}
}

PRODUCT_REVIEW -> {
is WooNotificationType.ProductReview -> {
analyticsTrackerWrapper.track(REVIEW_OPEN)
triggerEvent(ViewReviewDetail(notification.uniqueId))
}

BLAZE_APPROVED_NOTE,
BLAZE_REJECTED_NOTE,
BLAZE_CANCELLED_NOTE,
BLAZE_PERFORMED_NOTE -> triggerEvent(
is WooNotificationType.BlazeStatusUpdate -> triggerEvent(
ViewBlazeCampaignDetail(
campaignId = notification.uniqueId.toString(),
isOpenedFromPush = true
)
)

LOCAL_REMINDER -> error("Local reminder notification should not be handled here")
is WooNotificationType.LocalReminder -> error("Local reminder notification should not be handled here")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ class NotificationTest {
remoteSiteId = remoteSiteId,
uniqueId = 0L,
channelType = NotificationChannelType.NEW_ORDER,
noteType = WooNotificationType.NEW_ORDER
noteType = WooNotificationType.NewOrder
)

private val reviewNotification = NotificationTestUtils.generateTestNotification(
remoteNoteId = 1L,
remoteSiteId = remoteSiteId,
uniqueId = 0L,
channelType = NotificationChannelType.REVIEW,
noteType = WooNotificationType.PRODUCT_REVIEW
noteType = WooNotificationType.ProductReview
)

private val otherNotification = NotificationTestUtils.generateTestNotification(
remoteNoteId = 1L,
remoteSiteId = remoteSiteId,
uniqueId = 0L,
channelType = NotificationChannelType.OTHER,
noteType = WooNotificationType.LOCAL_REMINDER
noteType = WooNotificationType.LocalReminder
)

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,23 @@ class MainActivityViewModelTest : BaseUnitTest() {
remoteSiteId = siteModel.siteId,
uniqueId = TEST_NEW_ORDER_ID_1,
channelType = NotificationChannelType.NEW_ORDER,
noteType = WooNotificationType.NEW_ORDER
noteType = WooNotificationType.NewOrder
)

private val testReviewNotification = NotificationTestUtils.generateTestNotification(
remoteNoteId = TEST_NEW_REVIEW_REMOTE_NOTE_ID,
remoteSiteId = siteModel.siteId,
uniqueId = TEST_NEW_REVIEW_ID_1,
channelType = NotificationChannelType.REVIEW,
noteType = WooNotificationType.PRODUCT_REVIEW
noteType = WooNotificationType.ProductReview
)

private val testBlazeNotification = NotificationTestUtils.generateTestNotification(
remoteNoteId = TEST_BLAZE_REMOTE_NOTE_ID,
remoteSiteId = siteModel.siteId,
uniqueId = TEST_BLAZE_CAMPAIGN_ID_1,
channelType = NotificationChannelType.OTHER,
noteType = WooNotificationType.BLAZE_APPROVED_NOTE
noteType = WooNotificationType.BlazeStatusUpdate.BlazeApprovedNote
)

private val featureAnnouncementRepository: FeatureAnnouncementRepository = mock()
Expand Down

0 comments on commit d434516

Please sign in to comment.