Skip to content

Commit

Permalink
Merge pull request #17531 from wordpress-mobile/task/add-jetpack-migr…
Browse files Browse the repository at this point in the history
…ation-email-api-call

[JP Content Migration Flow] Adds jetpack migration email api call
  • Loading branch information
Antonis Lilis authored Nov 25, 2022
2 parents 927fe8c + 929ea97 commit 296b8fe
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.wordpress.android.localcontentmigration

import org.wordpress.android.analytics.AnalyticsTracker.Stat
import org.wordpress.android.localcontentmigration.ContentMigrationAnalyticsTracker.ErrorType.Companion.ERROR_TYPE
import org.wordpress.android.localcontentmigration.ContentMigrationAnalyticsTracker.ErrorType.EmailError
import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper
import javax.inject.Inject

Expand All @@ -11,8 +12,15 @@ class ContentMigrationAnalyticsTracker @Inject constructor(
fun trackContentMigrationFailed(errorType: ErrorType) =
analyticsTracker.track(Stat.SHARED_LOGIN_FAILED, mapOf(ERROR_TYPE to errorType.value))

fun trackMigrationEmailSuccess() =
analyticsTracker.track(Stat.MIGRATION_EMAIL_TRIGGERED)

fun trackMigrationEmailFailed(errorType: EmailError) =
analyticsTracker.track(Stat.MIGRATION_EMAIL_FAILED, mapOf(ERROR_TYPE to errorType.value))

sealed class ErrorType(val value: String) {
object LocalDraftContent : ErrorType("local_draft_content_is_present")
class EmailError(val error: String?) : ErrorType(error ?: "unknown_email_error")

companion object {
const val ERROR_TYPE = "error_type"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.wordpress.android.localcontentmigration

import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import org.wordpress.android.fluxc.store.mobile.JetpackMigrationStore
import org.wordpress.android.fluxc.store.mobile.MigrationCompleteFetchedPayload.Error
import org.wordpress.android.fluxc.store.mobile.MigrationCompleteFetchedPayload.Success
import org.wordpress.android.localcontentmigration.ContentMigrationAnalyticsTracker.ErrorType.EmailError
import org.wordpress.android.modules.BG_THREAD
import javax.inject.Inject
import javax.inject.Named
import kotlin.coroutines.CoroutineContext

class MigrationEmailHelper @Inject constructor(
private val jetpackMigrationStore: JetpackMigrationStore,
private val migrationAnalyticsTracker: ContentMigrationAnalyticsTracker,
@Named(BG_THREAD) private val bgDispatcher: CoroutineDispatcher,
) : CoroutineScope {
private val job = Job()
override val coroutineContext: CoroutineContext
get() = bgDispatcher + job

fun notifyMigrationComplete() = launch(bgDispatcher) {
when (val result = jetpackMigrationStore.migrationComplete()) {
is Success -> migrationAnalyticsTracker.trackMigrationEmailSuccess()
is Error -> migrationAnalyticsTracker.trackMigrationEmailFailed(EmailError(result.error?.message))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.wordpress.android.localcontentmigration.LocalMigrationState.Finished.
import org.wordpress.android.localcontentmigration.LocalMigrationState.Finished.Successful
import org.wordpress.android.localcontentmigration.LocalMigrationState.Initial
import org.wordpress.android.localcontentmigration.LocalMigrationState.Migrating
import org.wordpress.android.localcontentmigration.MigrationEmailHelper
import org.wordpress.android.sharedlogin.resolver.LocalMigrationOrchestrator
import org.wordpress.android.ui.main.jetpack.migration.JetpackMigrationViewModel.ActionButton.DeletePrimaryButton
import org.wordpress.android.ui.main.jetpack.migration.JetpackMigrationViewModel.ActionButton.DeleteSecondaryButton
Expand Down Expand Up @@ -49,6 +50,7 @@ class JetpackMigrationViewModel @Inject constructor(
private val gravatarUtilsWrapper: GravatarUtilsWrapper,
private val appPrefsWrapper: AppPrefsWrapper,
private val localMigrationOrchestrator: LocalMigrationOrchestrator,
private val migrationEmailHelper: MigrationEmailHelper,
) : ViewModel() {
private val _uiState = MutableStateFlow<UiState>(Loading)

Expand Down Expand Up @@ -162,6 +164,7 @@ class JetpackMigrationViewModel @Inject constructor(
}

private fun onDoneClicked() {
migrationEmailHelper.notifyMigrationComplete()
appPrefsWrapper.setJetpackMigrationCompleted(true)
postActionEvent(CompleteFlow)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.mockito.junit.MockitoJUnitRunner
import org.mockito.kotlin.mock
import org.wordpress.android.BaseUnitTest
import org.wordpress.android.R
import org.wordpress.android.localcontentmigration.MigrationEmailHelper
import org.wordpress.android.sharedlogin.resolver.LocalMigrationOrchestrator
import org.wordpress.android.test
import org.wordpress.android.ui.main.jetpack.migration.JetpackMigrationViewModel.ActionButton.DeletePrimaryButton
Expand All @@ -33,11 +34,13 @@ class JetpackMigrationViewModelTest : BaseUnitTest() {
private val gravatarUtilsWrapper: GravatarUtilsWrapper = mock()
private val appPrefsWrapper: AppPrefsWrapper = mock()
private val localMigrationOrchestrator: LocalMigrationOrchestrator = mock()
private val migrationEmailHelper: MigrationEmailHelper = mock()
private val classToTest = JetpackMigrationViewModel(
siteUtilsWrapper = siteUtilsWrapper,
gravatarUtilsWrapper = gravatarUtilsWrapper,
appPrefsWrapper = appPrefsWrapper,
localMigrationOrchestrator = localMigrationOrchestrator,
migrationEmailHelper = migrationEmailHelper
)

// region ViewModel
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ext {
coroutinesVersion = '1.5.2'
androidxWorkVersion = "2.7.0"

fluxCVersion = 'trunk-c0c1d3d56d09eec19e668eb6e2f3bcff648c644f'
fluxCVersion = 'trunk-9266d1b01317fcecf068e737e51a07186a1baf8f'

appCompatVersion = '1.0.2'
androidxCoreVersion = '1.3.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,8 @@ public enum Stat {
SHARED_LOGIN_START,
SHARED_LOGIN_SUCCESS,
SHARED_LOGIN_FAILED,
MIGRATION_EMAIL_TRIGGERED,
MIGRATION_EMAIL_FAILED,
CONTENT_MIGRATION_FAILED,
USER_FLAGS_START,
USER_FLAGS_SUCCESS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2393,6 +2393,10 @@ public static String getEventNameForStat(AnalyticsTracker.Stat stat) {
return "shared_login_success";
case SHARED_LOGIN_FAILED:
return "shared_login_failed";
case MIGRATION_EMAIL_FAILED:
return "migration_email_failed";
case MIGRATION_EMAIL_TRIGGERED:
return "migration_email_triggered";
case CONTENT_MIGRATION_FAILED:
return "content_migration_failed";
case USER_FLAGS_START:
Expand Down

0 comments on commit 296b8fe

Please sign in to comment.