From b46f9e1b0abe3b8e8bda1a03f962d65f28aab263 Mon Sep 17 00:00:00 2001 From: Ravi Date: Wed, 23 Nov 2022 11:52:58 +1100 Subject: [PATCH 1/7] Disable notifications on WP Disable notifications on WP app while in the migration flow to JP app --- .../migration/JetpackMigrationViewModel.kt | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModel.kt index 4f62cb7ef8fe..ab91fdbcee27 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModel.kt @@ -1,5 +1,6 @@ package org.wordpress.android.ui.main.jetpack.migration +import android.content.Intent import androidx.annotation.DrawableRes import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope @@ -10,6 +11,7 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.launch +import org.wordpress.android.BuildConfig import org.wordpress.android.R import org.wordpress.android.fluxc.store.AccountStore import org.wordpress.android.fluxc.store.SiteStore @@ -27,8 +29,11 @@ import org.wordpress.android.ui.main.jetpack.migration.JetpackMigrationViewModel import org.wordpress.android.ui.main.jetpack.migration.JetpackMigrationViewModel.UiState.Loading import org.wordpress.android.ui.utils.UiString import org.wordpress.android.ui.utils.UiString.UiStringRes +import org.wordpress.android.util.AppLog +import org.wordpress.android.util.AppLog.T import org.wordpress.android.util.GravatarUtilsWrapper import org.wordpress.android.util.SiteUtilsWrapper +import org.wordpress.android.viewmodel.ContextProvider import javax.inject.Inject @HiltViewModel @@ -37,6 +42,7 @@ class JetpackMigrationViewModel @Inject constructor( private val accountStore: AccountStore, private val siteUtilsWrapper: SiteUtilsWrapper, private val gravatarUtilsWrapper: GravatarUtilsWrapper, + private val contextProvider: ContextProvider ) : ViewModel() { private val _uiState = MutableStateFlow(Loading) val uiState: StateFlow = _uiState @@ -121,11 +127,26 @@ class JetpackMigrationViewModel @Inject constructor( @Suppress("ForbiddenComment") private fun onContinueFromNotificationsClicked() { - // TODO: Disable notifications in WP app - // See https://github.com/wordpress-mobile/WordPress-Android/pull/17371 + disableNotificationsOnWP() postDoneState() } + private fun disableNotificationsOnWP() { + AppLog.d(T.NOTIFS, "Disable Notifications") + Intent().also { intent -> + intent.action = "org.wordpress.android.broadcast.DISABLE_NOTIFICATIONS" + val appSuffix = BuildConfig.APPLICATION_ID.split(".").last() + val appPackage = if (appSuffix.isNotBlank()) { + "org.wordpress.android.${appSuffix}" + } else { + "org.wordpress.android" + } + intent.setPackage(appPackage) + AppLog.d(T.NOTIFS, intent.toString()) + contextProvider.getContext().sendBroadcast(intent, "org.wordpress.android.permission.DISABLE_NOTIFICATIONS") + } + } + private fun postDoneState() { _uiState.value = Content.Done( primaryActionButton = DonePrimaryButton(::onDoneClicked), From b8dbfb5455e1861ee9312e48946db55bc8e48202 Mon Sep 17 00:00:00 2001 From: Ravi Date: Wed, 23 Nov 2022 12:29:21 +1100 Subject: [PATCH 2/7] Update RELEASE-NOTES.txt --- RELEASE-NOTES.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index f00277532bb1..663d1c5c4e1a 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -5,6 +5,7 @@ * [*] Disable local notifications with Notification Settings switch. [https://github.com/wordpress-mobile/WordPress-Android/pull/17496] * [*] [Jetpack-only] Comments: fix a crash in My Site > Comments with Jetpack standalone plugins. [https://github.com/wordpress-mobile/WordPress-Android/pull/17456] * [*] [internal] Fix an issue preventing the text and button on the 'WordPress is Better with Jetpack' overlay to be entirely visible with big fonts. [https://github.com/wordpress-mobile/WordPress-Android/pull/17503] +* [***] [internal] Disable notifications on WP in migration flow when JP app is installed, behind a feature flag. [https://github.com/wordpress-mobile/WordPress-Android/pull/17513 and https://github.com/wordpress-mobile/WordPress-Android/pull/17371] 21.2 ----- From e62486b835a54650cf49b34229700d7e8768982e Mon Sep 17 00:00:00 2001 From: Ravi Date: Wed, 23 Nov 2022 12:37:09 +1100 Subject: [PATCH 3/7] Apply feature flag --- .../ui/main/jetpack/migration/JetpackMigrationViewModel.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModel.kt index ab91fdbcee27..b04be3b712c0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModel.kt @@ -33,6 +33,7 @@ import org.wordpress.android.util.AppLog import org.wordpress.android.util.AppLog.T import org.wordpress.android.util.GravatarUtilsWrapper import org.wordpress.android.util.SiteUtilsWrapper +import org.wordpress.android.util.config.PreventDuplicateNotifsFeatureConfig import org.wordpress.android.viewmodel.ContextProvider import javax.inject.Inject @@ -42,7 +43,8 @@ class JetpackMigrationViewModel @Inject constructor( private val accountStore: AccountStore, private val siteUtilsWrapper: SiteUtilsWrapper, private val gravatarUtilsWrapper: GravatarUtilsWrapper, - private val contextProvider: ContextProvider + private val contextProvider: ContextProvider, + private val preventDuplicateNotifsFeatureConfig: PreventDuplicateNotifsFeatureConfig ) : ViewModel() { private val _uiState = MutableStateFlow(Loading) val uiState: StateFlow = _uiState @@ -127,7 +129,7 @@ class JetpackMigrationViewModel @Inject constructor( @Suppress("ForbiddenComment") private fun onContinueFromNotificationsClicked() { - disableNotificationsOnWP() + if (preventDuplicateNotifsFeatureConfig.isEnabled()) disableNotificationsOnWP() postDoneState() } From 0c9c43d711cb764bef8c2238ae0ad943c7018ef5 Mon Sep 17 00:00:00 2001 From: Ravi Date: Thu, 24 Nov 2022 13:24:44 +1100 Subject: [PATCH 4/7] refactor reading app package --- .../ui/main/jetpack/migration/JetpackMigrationViewModel.kt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModel.kt index b0fffcb2c6e1..fb474ac6c56f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModel.kt @@ -157,12 +157,7 @@ class JetpackMigrationViewModel @Inject constructor( AppLog.d(T.NOTIFS, "Disable Notifications") Intent().also { intent -> intent.action = "org.wordpress.android.broadcast.DISABLE_NOTIFICATIONS" - val appSuffix = BuildConfig.APPLICATION_ID.split(".").last() - val appPackage = if (appSuffix.isNotBlank()) { - "org.wordpress.android.${appSuffix}" - } else { - "org.wordpress.android" - } + val appPackage = BuildConfig.APPLICATION_ID.replace("com.jetpack", "org.wordpress") intent.setPackage(appPackage) AppLog.d(T.NOTIFS, intent.toString()) contextProvider.getContext().sendBroadcast(intent, "org.wordpress.android.permission.DISABLE_NOTIFICATIONS") From 9103ccc323ab337ea1d6da157b984b2f18e0bb38 Mon Sep 17 00:00:00 2001 From: Ravi Date: Fri, 25 Nov 2022 09:57:57 +1100 Subject: [PATCH 5/7] Update notifications message copy --- WordPress/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index 966fcd873f53..60fdc33eb848 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -4253,7 +4253,7 @@ translators: %s: Select control option value e.g: "Auto, 25%". --> Need help? Notifications now come from Jetpack You’ll get all the same notifications but now they’ll come from the Jetpack app. - We’ve disabled notifications for the WordPress app. + We\'ll turn off notifications from the WordPress app. Thanks for switching to Jetpack! We’ve transferred all your data and settings. Everything is right where you left it. Please <b>delete the WordPress app</b> to<br>avoid data conflicts. From 9a891dbef391e48f1b33eb608871dbef8c9baf84 Mon Sep 17 00:00:00 2001 From: Ovi Trif Date: Fri, 25 Nov 2022 11:47:55 +0100 Subject: [PATCH 6/7] Update JetpackMigrationViewModelTest.kt --- .../main/jetpack/migration/JetpackMigrationViewModelTest.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModelTest.kt index d458c5294a88..b3411f63a69d 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationViewModelTest.kt @@ -26,6 +26,8 @@ import org.wordpress.android.ui.prefs.AppPrefsWrapper import org.wordpress.android.ui.utils.UiString.UiStringRes import org.wordpress.android.util.GravatarUtilsWrapper import org.wordpress.android.util.SiteUtilsWrapper +import org.wordpress.android.util.config.PreventDuplicateNotifsFeatureConfig +import org.wordpress.android.viewmodel.ContextProvider @RunWith(MockitoJUnitRunner::class) class JetpackMigrationViewModelTest : BaseUnitTest() { @@ -33,9 +35,13 @@ class JetpackMigrationViewModelTest : BaseUnitTest() { private val gravatarUtilsWrapper: GravatarUtilsWrapper = mock() private val appPrefsWrapper: AppPrefsWrapper = mock() private val localMigrationOrchestrator: LocalMigrationOrchestrator = mock() + private val preventDuplicateNotifsFeatureConfig: PreventDuplicateNotifsFeatureConfig = mock() + private val contextProvider: ContextProvider = mock() private val classToTest = JetpackMigrationViewModel( siteUtilsWrapper = siteUtilsWrapper, gravatarUtilsWrapper = gravatarUtilsWrapper, + contextProvider = contextProvider, + preventDuplicateNotifsFeatureConfig = preventDuplicateNotifsFeatureConfig, appPrefsWrapper = appPrefsWrapper, localMigrationOrchestrator = localMigrationOrchestrator, ) From 457871af673b641940054d50ef56e6d3bf03c4af Mon Sep 17 00:00:00 2001 From: Ovi Trif Date: Fri, 25 Nov 2022 11:49:41 +0100 Subject: [PATCH 7/7] Update build.gradle to enable PREVENT_DUPLICATE flag --- WordPress/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/build.gradle b/WordPress/build.gradle index 53784ae1a260..1a9130e71411 100644 --- a/WordPress/build.gradle +++ b/WordPress/build.gradle @@ -132,7 +132,7 @@ android { buildConfigField "boolean", "JETPACK_FEATURE_REMOVAL_PHASE_THREE", "false" buildConfigField "boolean", "JETPACK_FEATURE_REMOVAL_PHASE_FOUR", "false" buildConfigField "boolean", "JETPACK_FEATURE_REMOVAL_NEW_USERS", "false" - buildConfigField "boolean", "PREVENT_DUPLICATE_NOTIFS_REMOTE_FIELD", "false" + buildConfigField "boolean", "PREVENT_DUPLICATE_NOTIFS_REMOTE_FIELD", "true" buildConfigField "boolean", "OPEN_WEB_LINKS_WITH_JETPACK_FLOW", "false" // Override these constants in jetpack product flavor to enable/ disable features