Skip to content
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

Disable notifications on WP app in migration flow on JP app #17513

Merged
merged 10 commits into from
Nov 25, 2022
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]

21.2
-----
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.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
Expand All @@ -27,8 +29,12 @@ 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.util.config.PreventDuplicateNotifsFeatureConfig
import org.wordpress.android.viewmodel.ContextProvider
import javax.inject.Inject

@HiltViewModel
Expand All @@ -37,6 +43,8 @@ class JetpackMigrationViewModel @Inject constructor(
private val accountStore: AccountStore,
private val siteUtilsWrapper: SiteUtilsWrapper,
private val gravatarUtilsWrapper: GravatarUtilsWrapper,
private val contextProvider: ContextProvider,
private val preventDuplicateNotifsFeatureConfig: PreventDuplicateNotifsFeatureConfig
) : ViewModel() {
private val _uiState = MutableStateFlow<UiState>(Loading)
val uiState: StateFlow<UiState> = _uiState
Expand Down Expand Up @@ -121,11 +129,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
if (preventDuplicateNotifsFeatureConfig.isEnabled()) disableNotificationsOnWP()
postDoneState()
ovitrif marked this conversation as resolved.
Show resolved Hide resolved
}

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"
}
irfano marked this conversation as resolved.
Show resolved Hide resolved
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),
Expand Down