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

Add support for RoW subscriptions #5327

Merged
merged 20 commits into from
Dec 2, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
move accessing shared prefs to io dispatcher
  • Loading branch information
lmac012 committed Dec 1, 2024
commit 64ca81c51f1e7b3672ba4350d0ae04a3f8b80d29
Original file line number Diff line number Diff line change
Expand Up @@ -109,29 +109,29 @@ internal class RealAuthRepository constructor(
updateSerpPromoCookie()
}

override suspend fun getAccessTokenV2(): AccessToken? {
val jwt = subscriptionsDataStore.accessTokenV2 ?: return null
val expiresAt = subscriptionsDataStore.accessTokenV2ExpiresAt ?: return null
return AccessToken(jwt, expiresAt)
override suspend fun getAccessTokenV2(): AccessToken? = withContext(dispatcherProvider.io()) {
val jwt = subscriptionsDataStore.accessTokenV2 ?: return@withContext null
val expiresAt = subscriptionsDataStore.accessTokenV2ExpiresAt ?: return@withContext null
AccessToken(jwt, expiresAt)
}

override suspend fun setRefreshTokenV2(refreshToken: RefreshToken?) {
override suspend fun setRefreshTokenV2(refreshToken: RefreshToken?) = withContext(dispatcherProvider.io()) {
subscriptionsDataStore.refreshTokenV2 = refreshToken?.jwt
subscriptionsDataStore.refreshTokenV2ExpiresAt = refreshToken?.expiresAt
}

override suspend fun getRefreshTokenV2(): RefreshToken? {
val jwt = subscriptionsDataStore.refreshTokenV2 ?: return null
val expiresAt = subscriptionsDataStore.refreshTokenV2ExpiresAt ?: return null
return RefreshToken(jwt, expiresAt)
override suspend fun getRefreshTokenV2(): RefreshToken? = withContext(dispatcherProvider.io()) {
val jwt = subscriptionsDataStore.refreshTokenV2 ?: return@withContext null
val expiresAt = subscriptionsDataStore.refreshTokenV2ExpiresAt ?: return@withContext null
RefreshToken(jwt, expiresAt)
}

override suspend fun setEntitlements(entitlements: List<Entitlement>) = withContext(dispatcherProvider.io()) {
subscriptionsDataStore.entitlements = moshi.listToJson(entitlements)
}

override suspend fun getEntitlements(): List<Entitlement> {
return subscriptionsDataStore.entitlements?.let { moshi.parseList(it) } ?: emptyList()
override suspend fun getEntitlements(): List<Entitlement> = withContext(dispatcherProvider.io()) {
subscriptionsDataStore.entitlements?.let { moshi.parseList(it) } ?: emptyList()
}

override suspend fun setAccessToken(accessToken: String?) = withContext(dispatcherProvider.io()) {
Expand Down Expand Up @@ -206,7 +206,7 @@ internal class RealAuthRepository constructor(
override suspend fun setFeatures(
basePlanId: String,
features: Set<String>,
) {
) = withContext(dispatcherProvider.io()) {
val featuresMap = subscriptionsDataStore.subscriptionFeatures
?.let(featuresAdapter::fromJson)
?.toMutableMap() ?: mutableMapOf()
Expand All @@ -216,12 +216,13 @@ internal class RealAuthRepository constructor(
subscriptionsDataStore.subscriptionFeatures = featuresAdapter.toJson(featuresMap)
}

override suspend fun getFeatures(basePlanId: String): Set<String> =
override suspend fun getFeatures(basePlanId: String): Set<String> = withContext(dispatcherProvider.io()) {
subscriptionsDataStore.subscriptionFeatures
?.let(featuresAdapter::fromJson)
?.get(basePlanId) ?: emptySet()
}

private suspend fun updateSerpPromoCookie() {
private suspend fun updateSerpPromoCookie() = withContext(dispatcherProvider.io()) {
val accessToken = subscriptionsDataStore.run { accessTokenV2 ?: accessToken }
serpPromo.injectCookie(accessToken)
}
Expand Down