Skip to content

Commit

Permalink
Add hack to be able to refresh AccountCache from VoucherRedeemer
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Oct 23, 2023
1 parent f58efc2 commit 6117d59
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ServiceEndpoint(
val locationInfoCache = LocationInfoCache(this)
val relayListListener = RelayListListener(this)
val splitTunneling = SplitTunneling(SplitTunnelingPersistence(context), this)
val voucherRedeemer = VoucherRedeemer(this)
val voucherRedeemer = VoucherRedeemer(this, accountCache)

private val deviceRepositoryBackend = DaemonDeviceDataSource(this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.ClosedReceiveChannelException
import kotlinx.coroutines.channels.actor
import kotlinx.coroutines.channels.trySendBlocking
import net.mullvad.mullvadvpn.lib.common.util.parseAsDateTime
import net.mullvad.mullvadvpn.lib.ipc.Event
import net.mullvad.mullvadvpn.lib.ipc.Request
import net.mullvad.mullvadvpn.model.AccountExpiry
import net.mullvad.mullvadvpn.model.VoucherSubmissionResult

class VoucherRedeemer(private val endpoint: ServiceEndpoint) {
class VoucherRedeemer(private val endpoint: ServiceEndpoint, private val accountCache: AccountCache) {
private val daemon
get() = endpoint.intermittentDaemon

Expand All @@ -31,6 +34,11 @@ class VoucherRedeemer(private val endpoint: ServiceEndpoint) {
for (voucher in channel) {
val result = daemon.await().submitVoucher(voucher)

// Let AccountCache know about the new expiry
if(result is VoucherSubmissionResult.Ok) {
val accountExpiry = AccountExpiry.Available(result.submission.newExpiry.parseAsDateTime()!!)
accountCache.onAccountExpiryChange.notify(accountExpiry)
}
endpoint.sendEvent(Event.VoucherSubmissionResult(voucher, result))
}
} catch (exception: ClosedReceiveChannelException) {
Expand Down

0 comments on commit 6117d59

Please sign in to comment.