Skip to content

Commit

Permalink
Skip sending account expiry missing events when failing to fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
sabercodic authored and albin-mullvad committed Nov 15, 2023
1 parent 2baf3f0 commit 365b1b9
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ class AccountCache(private val endpoint: ServiceEndpoint) {

registerHandler(Request.FetchAccountExpiry::class) { _ ->
jobTracker.newBackgroundJob("fetchAccountExpiry") {
accountExpiry =
cachedAccountToken?.let { fetchAccountExpiry(it) } ?: AccountExpiry.Missing
val token = cachedAccountToken ?: return@newBackgroundJob
val newAccountExpiry = fetchAccountExpiry(token) ?: return@newBackgroundJob
accountExpiry = newAccountExpiry
}
}

Expand Down Expand Up @@ -141,6 +142,7 @@ class AccountCache(private val endpoint: ServiceEndpoint) {

private suspend fun doLogout() {
daemon.await().logoutAccount()
accountExpiry = AccountExpiry.Missing
accountHistory = fetchAccountHistory()
}

Expand All @@ -154,15 +156,15 @@ class AccountCache(private val endpoint: ServiceEndpoint) {
}
}

private suspend fun fetchAccountExpiry(accountToken: String): AccountExpiry {
private suspend fun fetchAccountExpiry(accountToken: String): AccountExpiry? {
return fetchAccountData(accountToken).let { result ->
if (result is GetAccountDataResult.Ok) {
result.accountData.expiry.parseAsDateTime()?.let { parsedDateTime ->
AccountExpiry.Available(parsedDateTime)
when (result) {
is GetAccountDataResult.Ok -> {
result.accountData.expiry.parseAsDateTime()?.let { AccountExpiry.Available(it) }
}
?: AccountExpiry.Missing
} else {
AccountExpiry.Missing
GetAccountDataResult.InvalidAccount -> AccountExpiry.Missing
GetAccountDataResult.OtherError -> null
GetAccountDataResult.RpcError -> null
}
}
}
Expand Down

0 comments on commit 365b1b9

Please sign in to comment.