Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -136,7 +136,8 @@ object AppPrefs {
BLAZE_CAMPAIGN_OBJECTIVE_SWITCH_CHECKED,
IS_SITE_WPCOM_SUSPENDED,
JETPACK_APP_PASSWORDS_ENABLED,
WOO_POS_LOCAL_CATALOG_ENABLED
WOO_POS_LOCAL_CATALOG_ENABLED,
WOO_CORE_PUSH_DEVICE_UUID
}

/**
Expand Down Expand Up @@ -323,6 +324,10 @@ object AppPrefs {
get() = getBoolean(UndeletablePrefKey.WOO_POS_SURVEY_NOTIFICATION_POTENTIAL_USER_SHOWN, false)
set(value) = setBoolean(UndeletablePrefKey.WOO_POS_SURVEY_NOTIFICATION_POTENTIAL_USER_SHOWN, value)

var wooCorePushDeviceUUID: String
get() = getString(DeletablePrefKey.WOO_CORE_PUSH_DEVICE_UUID, "")
set(value) = setString(DeletablePrefKey.WOO_CORE_PUSH_DEVICE_UUID, value)

fun getProductSortingChoice(currentSiteId: Int) = getString(getProductSortingKey(currentSiteId)).orNullIfEmpty()

fun setProductSortingChoice(currentSiteId: Int, value: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ open class AppPrefsWrapper @Inject constructor() {

var jetpackAppPasswordsEnabled by AppPrefs::jetpackAppPasswordsEnabled

var wooCorePushDeviceUUID by AppPrefs::wooCorePushDeviceUUID

fun getAppInstallationDate() = AppPrefs.installationDate

fun getReceiptUrl(localSiteId: Int, remoteSiteId: Long, selfHostedSiteId: Long, orderId: Long) =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.woocommerce.android.notifications.push

import com.woocommerce.android.AppPrefsWrapper
import com.woocommerce.android.BuildConfig
import com.woocommerce.android.extensions.orNullIfEmpty
import com.woocommerce.android.tools.SelectedSite
import com.woocommerce.android.util.WooLog
import org.wordpress.android.fluxc.network.rest.wpcom.wc.pushnotifications.PushNotificationsStore
import java.util.UUID
import javax.inject.Inject

class PushNotificationRepository @Inject constructor(
private val pushNotificationsStore: PushNotificationsStore,
private val selectedSite: SelectedSite,
private val appPrefsWrapper: AppPrefsWrapper
) {
suspend fun registerPushToken(token: String) {
WooLog.d(
tag = WooLog.T.NOTIFS,
message = "Registering FCM token in Woo Core instance${if (BuildConfig.DEBUG) ": $token" else ""}"
)
selectedSite.getIfExists()?.let {
val uuid = appPrefsWrapper.wooCorePushDeviceUUID.orNullIfEmpty() ?: generateAndStoreUUID()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now we are reusing the existing logic to create the device UUID. Asked Hannah here: https://wp.me/pe5sF9-4OM#comment-5081 if the current strategy is good enough.

pushNotificationsStore.registerPushToken(
site = it,
token = token,
deviceUuid = uuid // TODO review we need to add any extra info to the uuid
)
// TODO ensure any WP.com token already registered is removed
}
Comment thread
JorgeMucientes marked this conversation as resolved.
Outdated
}

private fun generateAndStoreUUID(): String {
return UUID.randomUUID().toString().also {
appPrefsWrapper.wooCorePushDeviceUUID = it
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.woocommerce.android.AppPrefsWrapper
import com.woocommerce.android.BuildConfig
import com.woocommerce.android.notifications.push.RegisterDevice.Mode.FORCEFULLY
import com.woocommerce.android.notifications.push.RegisterDevice.Mode.IF_NEEDED
import com.woocommerce.android.util.FeatureFlag
import com.woocommerce.android.util.WooLog
import org.wordpress.android.fluxc.store.AccountStore
import org.wordpress.android.fluxc.store.GetDeviceRegistrationStatus
Expand All @@ -14,6 +15,7 @@ class RegisterDevice @Inject constructor(
private val accountStore: AccountStore,
private val notificationRepository: NotificationRepository,
private val getDeviceRegistrationStatus: GetDeviceRegistrationStatus,
private val pushNotificationRepository: PushNotificationRepository
) {
suspend operator fun invoke(mode: Mode) {
when (mode) {
Expand All @@ -33,8 +35,12 @@ class RegisterDevice @Inject constructor(

private suspend fun sendToken() {
val token = appPrefsWrapper.getFCMToken()
if (accountStore.hasAccessToken() && token.isNotEmpty()) {
notificationRepository.registerDevice(token)
if (FeatureFlag.WOO_PUSH_NOTIFICATIONS_SYSTEM.isEnabled()) {
pushNotificationRepository.registerPushToken(token)
} else {
if (accountStore.hasAccessToken() && token.isNotEmpty()) {
notificationRepository.registerDevice(token)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ enum class FeatureFlag {
ORDER_CREATION_AUTO_TAX_RATE,
BOOKINGS_MVP,
POS_REFUNDS,
WOO_POS_LOCAL_CATALOG_FILE_APPROACH;
WOO_POS_LOCAL_CATALOG_FILE_APPROACH,
WOO_PUSH_NOTIFICATIONS_SYSTEM;

fun isEnabled(context: Context? = null): Boolean {
return when (this) {
Expand All @@ -26,7 +27,8 @@ enum class FeatureFlag {
BOOKINGS_MVP,
POS_REFUNDS -> PackageUtils.isDebugBuild()

WOO_POS_LOCAL_CATALOG_FILE_APPROACH -> false
WOO_POS_LOCAL_CATALOG_FILE_APPROACH,
WOO_PUSH_NOTIFICATIONS_SYSTEM -> false

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabled by default for now to avoid breaking PN for all devs until the endpoint starts working

}
}
}