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

[JP Content Migration Flow] Adds jetpack migration email api call #17531

Merged
merged 6 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
Expand All @@ -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<UiState>(Loading)

Expand Down Expand Up @@ -146,6 +148,7 @@ class JetpackMigrationViewModel @Inject constructor(
}

private fun onDoneClicked() {
migrationEmailHelper.notifyMigrationComplete()
postActionEvent(CompleteFlow)
}

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
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