Fix notification profile manually enabled and scheduled bug.
This commit is contained in:
parent
3781e1dd60
commit
0dd2397fb4
2 changed files with 19 additions and 7 deletions
|
@ -24,22 +24,22 @@ object NotificationProfiles {
|
|||
val storeValues: NotificationProfileValues = SignalStore.notificationProfileValues()
|
||||
val localNow: LocalDateTime = now.toLocalDateTime(zoneId)
|
||||
|
||||
val manualProfile: NotificationProfile? = profiles.firstOrNull { it.id == storeValues.manuallyEnabledProfile }
|
||||
val manualProfile: NotificationProfile? = if (now < storeValues.manuallyEnabledUntil) {
|
||||
profiles.firstOrNull { it.id == storeValues.manuallyEnabledProfile }
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
val scheduledProfile: NotificationProfile? = profiles.sortedDescending().filter { it.schedule.isCurrentlyActive(now, zoneId) }.firstOrNull { profile ->
|
||||
profile.schedule.startDateTime(localNow).toMillis(zoneId.toOffset()) > storeValues.manuallyDisabledAt
|
||||
}
|
||||
|
||||
if (manualProfile == null || scheduledProfile == null) {
|
||||
return (if (now < storeValues.manuallyEnabledUntil) manualProfile else null) ?: scheduledProfile
|
||||
return manualProfile ?: scheduledProfile
|
||||
}
|
||||
|
||||
return if (manualProfile == scheduledProfile) {
|
||||
if (storeValues.manuallyEnabledUntil == Long.MAX_VALUE || now < storeValues.manuallyEnabledUntil) {
|
||||
manualProfile
|
||||
} else {
|
||||
null
|
||||
}
|
||||
manualProfile
|
||||
} else {
|
||||
scheduledProfile
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ class NotificationProfilesTest {
|
|||
private val sunday830am: LocalDateTime = LocalDateTime.of(2021, 7, 4, 8, 30, 0)
|
||||
private val sunday9am: LocalDateTime = LocalDateTime.of(2021, 7, 4, 9, 0, 0)
|
||||
private val sunday930am: LocalDateTime = LocalDateTime.of(2021, 7, 4, 9, 30, 0)
|
||||
private val monday830am: LocalDateTime = sunday830am.plusDays(1)
|
||||
private val utc: ZoneId = ZoneId.of("UTC")
|
||||
|
||||
private val first = NotificationProfile(
|
||||
|
@ -139,4 +140,15 @@ class NotificationProfilesTest {
|
|||
val profiles = listOf(first.copy(schedule = schedule))
|
||||
assertThat("active profile is null", NotificationProfiles.getActiveProfile(profiles, sunday930am.toMillis(ZoneOffset.UTC), utc), nullValue())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when profile is manually enabled yesterday and is scheduled also for today then return profile`() {
|
||||
signalStore.dataSet.putLong(NotificationProfileValues.KEY_MANUALLY_ENABLED_PROFILE, first.id)
|
||||
signalStore.dataSet.putLong(NotificationProfileValues.KEY_MANUALLY_ENABLED_UNTIL, sunday9am.toMillis(ZoneOffset.UTC))
|
||||
signalStore.dataSet.putLong(NotificationProfileValues.KEY_MANUALLY_DISABLED_AT, sunday830am.toMillis(ZoneOffset.UTC))
|
||||
|
||||
val schedule = NotificationProfileSchedule(id = 3L, enabled = true, start = 700, end = 900, daysEnabled = setOf(DayOfWeek.SUNDAY, DayOfWeek.MONDAY))
|
||||
val profiles = listOf(first.copy(schedule = schedule))
|
||||
assertThat("active profile is first", NotificationProfiles.getActiveProfile(profiles, monday830am.toMillis(ZoneOffset.UTC), utc), `is`(profiles[0]))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue