Skip to content

Commit

Permalink
Merge pull request #17513 from wordpress-mobile/Jetpack-Focus-Disable…
Browse files Browse the repository at this point in the history
…-notifications-from-Jetpack-app

Disable notifications on WP app in migration flow on JP app
  • Loading branch information
irfano authored Nov 25, 2022
2 parents 5154971 + 36a6fd2 commit 132ca7f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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]
* [*] [internal] Avoid truncation of the 'Try the new Jetpack app' button text on the Jetpack Powered bottom sheets with big fonts. [https://github.com/wordpress-mobile/WordPress-Android/pull/17511]

21.2
Expand Down
2 changes: 1 addition & 1 deletion WordPress/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,6 +11,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.combineTransform
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch
import org.wordpress.android.BuildConfig
import org.wordpress.android.R
import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.localcontentmigration.LocalMigrationState
Expand Down Expand Up @@ -40,14 +42,20 @@ import org.wordpress.android.ui.main.jetpack.migration.JetpackMigrationViewModel
import org.wordpress.android.ui.prefs.AppPrefsWrapper
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.util.config.PreventDuplicateNotifsFeatureConfig
import org.wordpress.android.viewmodel.ContextProvider
import javax.inject.Inject

@HiltViewModel
class JetpackMigrationViewModel @Inject constructor(
private val siteUtilsWrapper: SiteUtilsWrapper,
private val gravatarUtilsWrapper: GravatarUtilsWrapper,
private val contextProvider: ContextProvider,
private val preventDuplicateNotifsFeatureConfig: PreventDuplicateNotifsFeatureConfig,
private val appPrefsWrapper: AppPrefsWrapper,
private val localMigrationOrchestrator: LocalMigrationOrchestrator,
private val migrationEmailHelper: MigrationEmailHelper,
Expand Down Expand Up @@ -156,13 +164,22 @@ 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
if (preventDuplicateNotifsFeatureConfig.isEnabled()) disableNotificationsOnWP()
notificationContinueClickedFlow.value = true
}

private fun disableNotificationsOnWP() {
AppLog.d(T.NOTIFS, "Disable Notifications")
Intent().also { intent ->
intent.action = "org.wordpress.android.broadcast.DISABLE_NOTIFICATIONS"
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")
}
}

private fun onDoneClicked() {
migrationEmailHelper.notifyMigrationComplete()
appPrefsWrapper.setJetpackMigrationCompleted(true)
Expand Down
2 changes: 1 addition & 1 deletion WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4253,7 +4253,7 @@ translators: %s: Select control option value e.g: "Auto, 25%". -->
<string name="jp_migration_help_button">Need help?</string>
<string name="jp_migration_notifications_title">Notifications now come from Jetpack</string>
<string name="jp_migration_notifications_subtitle">You’ll get all the same notifications but now they’ll come from the Jetpack app.</string>
<string name="jp_migration_notifications_disabled_in_wp_message">We’ve disabled notifications for the WordPress app.</string>
<string name="jp_migration_notifications_disabled_in_wp_message">We\'ll turn off notifications from the WordPress app.</string>
<string name="jp_migration_done_title">Thanks for switching to Jetpack!</string>
<string name="jp_migration_done_subtitle">We’ve transferred all your data and settings. Everything is right where you left it.</string>
<string name="jp_migration_done_delete_wp_message">Please &lt;b&gt;delete the WordPress app&lt;/b&gt; to&lt;br&gt;avoid data conflicts.</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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() {
Expand All @@ -35,9 +37,13 @@ class JetpackMigrationViewModelTest : BaseUnitTest() {
private val appPrefsWrapper: AppPrefsWrapper = mock()
private val localMigrationOrchestrator: LocalMigrationOrchestrator = mock()
private val migrationEmailHelper: MigrationEmailHelper = 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,
migrationEmailHelper = migrationEmailHelper
Expand Down

0 comments on commit 132ca7f

Please sign in to comment.