Skip to content

Commit

Permalink
Merge pull request #937 from Automattic/fix/sign-out-event-firing
Browse files Browse the repository at this point in the history
Only sign out user if they have not already been fully signed out
  • Loading branch information
ashiagr authored May 8, 2023
2 parents 6b57033 + 10f87b7 commit 0815969
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -613,4 +613,12 @@ interface Settings {

fun setLastSelectedSubscriptionFrequency(frequency: SubscriptionFrequency)
fun getLastSelectedSubscriptionFrequency(): SubscriptionFrequency?

// This boolean should be update to false when a user signs in and should be set to
// true once a user signs out and that sign out has been fully handled
// by the app. This field helps make sure the app fully handles signing a user
// out even if they sign out from outside the app (i.e., from the Android OS's
// account management settings).
fun setFullySignedOut(boolean: Boolean)
fun getFullySignedOut(): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class SettingsImpl @Inject constructor(
private const val CUSTOM_MEDIA_ACTIONS_VISIBLE_KEY = "CustomMediaActionsVisibleKey"
private const val LAST_SELECTED_SUBSCRIPTION_TIER_KEY = "LastSelectedSubscriptionTierKey"
private const val LAST_SELECTED_SUBSCRIPTION_FREQUENCY_KEY = "LastSelectedSubscriptionFrequencyKey"
private const val PROCESSED_SIGNOUT_KEY = "ProcessedSignout"
}

private var languageCode: String? = null
Expand Down Expand Up @@ -1402,4 +1403,11 @@ class SettingsImpl @Inject constructor(
getString(LAST_SELECTED_SUBSCRIPTION_FREQUENCY_KEY)?.let {
SubscriptionFrequency.valueOf(it)
}

override fun setFullySignedOut(boolean: Boolean) {
setBoolean(PROCESSED_SIGNOUT_KEY, boolean)
}

override fun getFullySignedOut(): Boolean =
getBoolean(PROCESSED_SIGNOUT_KEY, true)
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ class SyncManagerImpl @Inject constructor(
val loginResult = try {
val response = loginFunction()
val result = handleTokenResponse(loginIdentity = loginIdentity, response = response)

settings.setFullySignedOut(false)

LoginResult.Success(result)
} catch (ex: Exception) {
Timber.e(ex, "Failed to sign in with Pocket Casts")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,28 +91,27 @@ class UserManagerImpl @Inject constructor(

@OptIn(DelicateCoroutinesApi::class)
override fun signOut(playbackManager: PlaybackManager, wasInitiatedByUser: Boolean) {
val wasSignedIn = syncManager.isLoggedIn()

LogBuffer.i(LogBuffer.TAG_BACKGROUND_TASKS, "Signing out")
subscriptionManager.clearCachedStatus()
syncManager.signOut {
settings.clearPlusPreferences()
GlobalScope.launch {
userEpisodeManager.removeCloudStatusFromFiles(playbackManager)
}
if (wasInitiatedByUser || !settings.getFullySignedOut()) {
LogBuffer.i(LogBuffer.TAG_BACKGROUND_TASKS, "Signing out")
subscriptionManager.clearCachedStatus()
syncManager.signOut {
settings.clearPlusPreferences()
GlobalScope.launch {
userEpisodeManager.removeCloudStatusFromFiles(playbackManager)
}

settings.setMarketingOptIn(false)
settings.setMarketingOptInNeedsSync(false)
settings.setEndOfYearModalHasBeenShown(false)
if (wasSignedIn) {
settings.setMarketingOptIn(false)
settings.setMarketingOptInNeedsSync(false)
settings.setEndOfYearModalHasBeenShown(false)
analyticsTracker.track(
AnalyticsEvent.USER_SIGNED_OUT,
mapOf(KEY_USER_INITIATED to wasInitiatedByUser)
)
analyticsTracker.flush()
analyticsTracker.clearAllData()
analyticsTracker.refreshMetadata()
}
analyticsTracker.flush()
analyticsTracker.clearAllData()
analyticsTracker.refreshMetadata()
}
settings.setFullySignedOut(true)
}
}

0 comments on commit 0815969

Please sign in to comment.