From 40105a7027896e1fcd1fd8b9aa4779c05ab7dc11 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Thu, 24 Nov 2022 16:59:45 +0200 Subject: [PATCH 1/5] Adds FluxC version reference --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index a1b5d5b49eea..90cd8c54032e 100644 --- a/build.gradle +++ b/build.gradle @@ -24,7 +24,7 @@ ext { coroutinesVersion = '1.5.2' androidxWorkVersion = "2.7.0" - fluxCVersion = 'trunk-c0c1d3d56d09eec19e668eb6e2f3bcff648c644f' + fluxCVersion = '2576-eb71ab74f6da2b1951a1464d2f86723bea0507ad' appCompatVersion = '1.0.2' androidxCoreVersion = '1.3.2' From 7287dc879030609324d9b70a22f7c6f9a85829d4 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Thu, 24 Nov 2022 17:02:22 +0200 Subject: [PATCH 2/5] Calls migration api --- .../MigrationEmailHelper.kt | 29 +++++++++++++++++++ .../migration/JetpackMigrationViewModel.kt | 3 ++ 2 files changed, 32 insertions(+) create mode 100644 WordPress/src/main/java/org/wordpress/android/localcontentmigration/MigrationEmailHelper.kt diff --git a/WordPress/src/main/java/org/wordpress/android/localcontentmigration/MigrationEmailHelper.kt b/WordPress/src/main/java/org/wordpress/android/localcontentmigration/MigrationEmailHelper.kt new file mode 100644 index 000000000000..2d1458239188 --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/localcontentmigration/MigrationEmailHelper.kt @@ -0,0 +1,29 @@ +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.modules.BG_THREAD +import javax.inject.Inject +import javax.inject.Named +import kotlin.coroutines.CoroutineContext + +class MigrationEmailHelper @Inject constructor( + private val jetpackMigrationStore: JetpackMigrationStore, + @Named(BG_THREAD) private val bgDispatcher: CoroutineDispatcher, +) : CoroutineScope { + private val job = Job() + override val coroutineContext: CoroutineContext + get() = bgDispatcher + job + + fun notifyMigrationComplete() = launch(bgDispatcher) { + when (jetpackMigrationStore.migrationComplete()) { + is Success -> {} + is Error -> {} + } + } +} 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 670ab7ea915a..397b87f2105d 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 @@ -17,6 +17,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.DonePrimaryButton import org.wordpress.android.ui.main.jetpack.migration.JetpackMigrationViewModel.ActionButton.ErrorPrimaryButton @@ -43,6 +44,7 @@ class JetpackMigrationViewModel @Inject constructor( private val siteUtilsWrapper: SiteUtilsWrapper, private val gravatarUtilsWrapper: GravatarUtilsWrapper, private val localMigrationOrchestrator: LocalMigrationOrchestrator, + private val migrationEmailHelper: MigrationEmailHelper, ) : ViewModel() { private val _uiState = MutableStateFlow(Loading) @@ -146,6 +148,7 @@ class JetpackMigrationViewModel @Inject constructor( } private fun onDoneClicked() { + migrationEmailHelper.notifyMigrationComplete() postActionEvent(CompleteFlow) } From 0e1caae103d77787214421a13b52cfede87db7b8 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Thu, 24 Nov 2022 17:03:30 +0200 Subject: [PATCH 3/5] Adds analytics tracking --- .../ContentMigrationAnalyticsTracker.kt | 8 ++++++++ .../android/localcontentmigration/MigrationEmailHelper.kt | 8 +++++--- .../org/wordpress/android/analytics/AnalyticsTracker.java | 2 ++ .../android/analytics/AnalyticsTrackerNosara.java | 4 ++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/localcontentmigration/ContentMigrationAnalyticsTracker.kt b/WordPress/src/main/java/org/wordpress/android/localcontentmigration/ContentMigrationAnalyticsTracker.kt index 74fb3e93d63b..247b88ed1007 100644 --- a/WordPress/src/main/java/org/wordpress/android/localcontentmigration/ContentMigrationAnalyticsTracker.kt +++ b/WordPress/src/main/java/org/wordpress/android/localcontentmigration/ContentMigrationAnalyticsTracker.kt @@ -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 @@ -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" diff --git a/WordPress/src/main/java/org/wordpress/android/localcontentmigration/MigrationEmailHelper.kt b/WordPress/src/main/java/org/wordpress/android/localcontentmigration/MigrationEmailHelper.kt index 2d1458239188..fc3f597bc0c0 100644 --- a/WordPress/src/main/java/org/wordpress/android/localcontentmigration/MigrationEmailHelper.kt +++ b/WordPress/src/main/java/org/wordpress/android/localcontentmigration/MigrationEmailHelper.kt @@ -7,6 +7,7 @@ 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 @@ -14,6 +15,7 @@ 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() @@ -21,9 +23,9 @@ class MigrationEmailHelper @Inject constructor( get() = bgDispatcher + job fun notifyMigrationComplete() = launch(bgDispatcher) { - when (jetpackMigrationStore.migrationComplete()) { - is Success -> {} - is Error -> {} + when (val result = jetpackMigrationStore.migrationComplete()) { + is Success -> migrationAnalyticsTracker.trackMigrationEmailSuccess() + is Error -> migrationAnalyticsTracker.trackMigrationEmailFailed(EmailError(result.error?.message)) } } } diff --git a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java index 8a8abcb5fba0..c1e7d4163bc9 100644 --- a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java +++ b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java @@ -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, diff --git a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java index 997b7e0fada0..bd04664b8da5 100644 --- a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java +++ b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java @@ -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: From 9736ace3f10540b870d701b8ee83c6917cbe327e Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Fri, 25 Nov 2022 10:13:57 +0200 Subject: [PATCH 4/5] Updates FluxC version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 90cd8c54032e..3727c4314160 100644 --- a/build.gradle +++ b/build.gradle @@ -24,7 +24,7 @@ ext { coroutinesVersion = '1.5.2' androidxWorkVersion = "2.7.0" - fluxCVersion = '2576-eb71ab74f6da2b1951a1464d2f86723bea0507ad' + fluxCVersion = 'trunk-9266d1b01317fcecf068e737e51a07186a1baf8f' appCompatVersion = '1.0.2' androidxCoreVersion = '1.3.2' From 929ea9746a9c246067db1f1ee6f57d918a9c0ae4 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Fri, 25 Nov 2022 11:13:38 +0200 Subject: [PATCH 5/5] Fixes compile error in tests --- .../ui/main/jetpack/migration/JetpackMigrationViewModelTest.kt | 3 +++ 1 file changed, 3 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..5ae81c3ceebb 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 @@ -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 @@ -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