summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorKalle Lindström <karl.lindstrom@mullvad.net>2024-11-07 16:38:19 +0100
committerDavid Göransson <david.goransson@mullvad.net>2024-11-12 14:33:04 +0100
commit456a0bb7eab8920b5eda5440fdc68f598e390dcd (patch)
tree69eb0ba8f2b2ba06d5547a668ecd3c166af6eddc /android
parenteb88e35d7b3c94ad95d4fac23f85e3400d0654bb (diff)
downloadmullvadvpn-456a0bb7eab8920b5eda5440fdc68f598e390dcd.tar.xz
mullvadvpn-456a0bb7eab8920b5eda5440fdc68f598e390dcd.zip
Fix account expiry in app notif not resetting
Diffstat (limited to 'android')
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryInAppNotificationUseCase.kt8
-rw-r--r--android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryInAppNotificationUseCaseTest.kt4
-rw-r--r--android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/accountexpiry/AccountExpiryTickerFlow.kt4
3 files changed, 12 insertions, 4 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryInAppNotificationUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryInAppNotificationUseCase.kt
index 9b71297d36..014f07bf35 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryInAppNotificationUseCase.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryInAppNotificationUseCase.kt
@@ -5,7 +5,6 @@ import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
-import kotlinx.coroutines.flow.onStart
import net.mullvad.mullvadvpn.lib.shared.AccountRepository
import net.mullvad.mullvadvpn.repository.InAppNotification
import net.mullvad.mullvadvpn.service.notifications.accountexpiry.ACCOUNT_EXPIRY_CLOSE_TO_EXPIRY_THRESHOLD
@@ -24,12 +23,15 @@ class AccountExpiryInAppNotificationUseCase(private val accountRepository: Accou
tickStart = ACCOUNT_EXPIRY_CLOSE_TO_EXPIRY_THRESHOLD,
updateInterval = { ACCOUNT_EXPIRY_IN_APP_NOTIFICATION_UPDATE_INTERVAL },
)
- .map { expiresInPeriod -> InAppNotification.AccountExpiry(expiresInPeriod) }
+ .map {
+ it?.let { expiresInPeriod ->
+ InAppNotification.AccountExpiry(expiresInPeriod)
+ }
+ }
} else {
flowOf(null)
}
}
.map(::listOfNotNull)
- .onStart { emit(emptyList()) }
.distinctUntilChanged()
}
diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryInAppNotificationUseCaseTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryInAppNotificationUseCaseTest.kt
index 0749cc62b4..df337a5911 100644
--- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryInAppNotificationUseCaseTest.kt
+++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryInAppNotificationUseCaseTest.kt
@@ -119,6 +119,10 @@ class AccountExpiryInAppNotificationUseCaseTest {
advanceTimeBy(ACCOUNT_EXPIRY_IN_APP_NOTIFICATION_UPDATE_INTERVAL.millis)
assertEquals(Duration.ZERO, getExpiryNotificationDuration(expectMostRecentItem()))
expectNoEvents()
+
+ // Make sure we reset the list of notifications emitted when new time is added
+ setExpiry(DateTime.now().plus(ACCOUNT_EXPIRY_CLOSE_TO_EXPIRY_THRESHOLD).plusDays(1))
+ assertEquals(emptyList(), expectMostRecentItem())
}
}
diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/accountexpiry/AccountExpiryTickerFlow.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/accountexpiry/AccountExpiryTickerFlow.kt
index c3a444f5ed..3683096c80 100644
--- a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/accountexpiry/AccountExpiryTickerFlow.kt
+++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/accountexpiry/AccountExpiryTickerFlow.kt
@@ -10,7 +10,7 @@ fun expiryTickerFlow(
expiry: DateTime,
tickStart: Duration,
updateInterval: (expiry: DateTime) -> Duration,
-): Flow<Duration> = flow {
+): Flow<Duration?> = flow {
expiry.millisFromNow().let { expiryMillis ->
if (expiryMillis <= 0) {
// Has expired.
@@ -18,6 +18,8 @@ fun expiryTickerFlow(
return@flow
}
if (expiryMillis > tickStart.millis) {
+ // Emit null if no expiry notification should be provided.
+ emit(null)
// Delay until the time we should start emitting.
delay(expiryMillis - tickStart.millis + 1)
}