Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 894e8429 authored by Abhishek Aggarwal's avatar Abhishek Aggarwal
Browse files

refactor(auth): collapse StoreType onto AuthStore

parent 90db4fb3
Loading
Loading
Loading
Loading
+1 −9
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import androidx.annotation.StringRes
import foundation.e.apps.R
import foundation.e.apps.data.ResultSupreme
import foundation.e.apps.data.enums.Source
import foundation.e.apps.data.login.core.StoreType
import foundation.e.apps.data.login.core.toAuthError
import foundation.e.apps.data.login.exceptions.CleanApkException
import foundation.e.apps.data.login.exceptions.CleanApkIOException
@@ -100,7 +99,7 @@ fun ResultSupreme<*>.toLegacyLoadFailure(
    val resolvedMessage = message.ifBlank { "Data load error" }
    val resolvedException = exception ?: fallbackException(isTimeout(), resolvedMessage)
    val resolvedAuthError = when {
        this is ResultSupreme.Timeout || exception != null -> toAuthError(authStore.toStoreType())
        this is ResultSupreme.Timeout || exception != null -> toAuthError(authStore)
        else -> null
    }

@@ -248,13 +247,6 @@ private fun resolveExceptionKind(
    }
}

private fun AuthStore.toStoreType(): StoreType {
    return when (this) {
        AuthStore.PLAY_STORE -> StoreType.PLAY_STORE
        AuthStore.OPEN_SOURCE -> StoreType.CLEAN_APK
    }
}

private fun resolveDialogSpec(
    exception: Exception,
    kind: LegacyLoadFailureKind,
+2 −2
Original line number Diff line number Diff line
@@ -18,8 +18,8 @@
package foundation.e.apps.data.login.api

import foundation.e.apps.data.login.core.StoreAuthResult
import foundation.e.apps.data.login.core.StoreType
import foundation.e.apps.domain.auth.AuthStore

interface StoreAuthCoordinator {
    suspend fun fetchAuthResults(storesToReset: List<StoreType> = emptyList()): List<StoreAuthResult>
    suspend fun fetchAuthResults(storesToReset: List<AuthStore> = emptyList()): List<StoreAuthResult>
}
+2 −2
Original line number Diff line number Diff line
@@ -21,8 +21,8 @@ import foundation.e.apps.data.ResultSupreme
import foundation.e.apps.data.login.core.StoreActivationPolicy
import foundation.e.apps.data.login.core.StoreAuthResult
import foundation.e.apps.data.login.core.StoreAuthenticator
import foundation.e.apps.data.login.core.StoreType
import foundation.e.apps.domain.auth.AuthSession
import foundation.e.apps.domain.auth.AuthStore
import foundation.e.apps.domain.preferences.SessionRepository
import foundation.e.apps.domain.source.SourceSelectionRepository
import javax.inject.Inject
@@ -46,7 +46,7 @@ class CleanApkAuthenticator @Inject constructor(
        )
    )

    override val storeType: StoreType = StoreType.CLEAN_APK
    override val storeType: AuthStore = AuthStore.OPEN_SOURCE

    override suspend fun isStoreActive(): Boolean {
        return storeActivationPolicy.shouldActivateCleanApkAuth()
+1 −16
Original line number Diff line number Diff line
@@ -27,8 +27,7 @@ import foundation.e.apps.domain.auth.AuthError
import foundation.e.apps.domain.auth.AuthStore
import java.net.HttpURLConnection

fun ResultSupreme<*>.toAuthError(storeType: StoreType): AuthError {
    val store = storeType.toAuthStore()
fun ResultSupreme<*>.toAuthError(store: AuthStore): AuthError {
    val resolvedException = exception
    val resolvedMessage = resolveAuthMessage()
    val httpStatus = resolvedException.findHttpStatus()
@@ -97,17 +96,3 @@ internal fun Throwable?.findHttpStatus(): Int? {
    }
    return null
}

fun StoreType.toAuthStore(): AuthStore {
    return when (this) {
        StoreType.PLAY_STORE -> AuthStore.PLAY_STORE
        StoreType.CLEAN_APK -> AuthStore.OPEN_SOURCE
    }
}

fun AuthStore.toStoreType(): StoreType {
    return when (this) {
        AuthStore.PLAY_STORE -> StoreType.PLAY_STORE
        AuthStore.OPEN_SOURCE -> StoreType.CLEAN_APK
    }
}
+4 −4
Original line number Diff line number Diff line
@@ -49,13 +49,13 @@ internal fun List<StoreAuthResult>.toAuthRefreshSnapshot(
}

private fun List<StoreAuthResult>.toFaultyTokenReportPayload(): FaultyTokenReportPayload? {
    val result = firstOrNull { it.storeType == StoreType.PLAY_STORE }?.result ?: return null
    val result = firstOrNull { it.storeType == AuthStore.PLAY_STORE }?.result ?: return null
    val loginException = result.exception as? GPlayLoginException ?: return null
    if (loginException.loginMode != PlayStoreLoginMode.ANONYMOUS) {
        return null
    }

    if (result.toAuthError(StoreType.PLAY_STORE) !is AuthError.InvalidToken) {
    if (result.toAuthError(AuthStore.PLAY_STORE) !is AuthError.InvalidToken) {
        return null
    }

@@ -65,12 +65,12 @@ private fun List<StoreAuthResult>.toFaultyTokenReportPayload(): FaultyTokenRepor

private fun StoreAuthResult.toAuthRefreshEntry(): AuthRefreshEntry {
    return AuthRefreshEntry(
        store = storeType.toAuthStore(),
        store = storeType,
        result = result.toAuthResult(storeType),
    )
}

private fun ResultSupreme<AuthSession>.toAuthResult(storeType: StoreType): AuthResult<AuthSession> {
private fun ResultSupreme<AuthSession>.toAuthResult(storeType: AuthStore): AuthResult<AuthSession> {
    return when (this) {
        is ResultSupreme.Success -> {
            val session = data
Loading