Fix notification profile manually enabled and scheduled bug.

This commit is contained in:
Cody Henthorne
2022-01-03 16:34:58 -05:00
committed by Greyson Parrelli
parent 3781e1dd60
commit 0dd2397fb4
2 changed files with 19 additions and 7 deletions

View File

@@ -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
}