Fix conflict when manually enabled an older profile with a schedule overlap with a newer profile.

fork-5.53.8
Cody Henthorne 2021-12-09 14:50:37 -05:00
rodzic 76539ff0f2
commit c30a43ef45
3 zmienionych plików z 24 dodań i 5 usunięć

Wyświetl plik

@ -80,7 +80,8 @@ class EditNotificationProfileScheduleViewModel(
repository.manuallyToggleProfile(profileId, schedule) repository.manuallyToggleProfile(profileId, schedule)
.toSingleDefault(r) .toSingleDefault(r)
} else { } else {
Single.just(r) repository.updateManuallyEnabledDataIfNecessary(profileId, schedule)
.toSingleDefault(r)
} }
} }
} }

Wyświetl plik

@ -15,6 +15,8 @@ import org.thoughtcrime.securesms.notifications.profiles.NotificationProfile
import org.thoughtcrime.securesms.notifications.profiles.NotificationProfileSchedule import org.thoughtcrime.securesms.notifications.profiles.NotificationProfileSchedule
import org.thoughtcrime.securesms.notifications.profiles.NotificationProfiles import org.thoughtcrime.securesms.notifications.profiles.NotificationProfiles
import org.thoughtcrime.securesms.recipients.RecipientId import org.thoughtcrime.securesms.recipients.RecipientId
import org.thoughtcrime.securesms.util.toLocalDateTime
import org.thoughtcrime.securesms.util.toMillis
/** /**
* One stop shop for all your Notification Profile data needs. * One stop shop for all your Notification Profile data needs.
@ -112,9 +114,9 @@ class NotificationProfilesRepository {
SignalStore.notificationProfileValues().lastProfilePopupTime = 0 SignalStore.notificationProfileValues().lastProfilePopupTime = 0
} else { } else {
val inScheduledWindow = schedule.isCurrentlyActive(now) val inScheduledWindow = schedule.isCurrentlyActive(now)
SignalStore.notificationProfileValues().manuallyEnabledProfile = if (inScheduledWindow) 0 else profileId SignalStore.notificationProfileValues().manuallyEnabledProfile = profileId
SignalStore.notificationProfileValues().manuallyEnabledUntil = if (inScheduledWindow) 0 else Long.MAX_VALUE SignalStore.notificationProfileValues().manuallyEnabledUntil = if (inScheduledWindow) schedule.endDateTime(now.toLocalDateTime()).toMillis() else Long.MAX_VALUE
SignalStore.notificationProfileValues().manuallyDisabledAt = if (inScheduledWindow) 0 else now SignalStore.notificationProfileValues().manuallyDisabledAt = now
} }
} }
.doOnComplete { ApplicationDependencies.getDatabaseObserver().notifyNotificationProfileObservers() } .doOnComplete { ApplicationDependencies.getDatabaseObserver().notifyNotificationProfileObservers() }
@ -131,5 +133,21 @@ class NotificationProfilesRepository {
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
} }
fun updateManuallyEnabledDataIfNecessary(profileId: Long, schedule: NotificationProfileSchedule, now: Long = System.currentTimeMillis()): Completable {
return Completable.fromAction {
val profiles = database.getProfiles()
val activeProfile = NotificationProfiles.getActiveProfile(profiles, now)
if (profileId == activeProfile?.id) {
val inScheduledWindow = schedule.isCurrentlyActive(now)
SignalStore.notificationProfileValues().manuallyEnabledProfile = if (inScheduledWindow) profileId else 0
SignalStore.notificationProfileValues().manuallyEnabledUntil = if (inScheduledWindow) schedule.endDateTime(now.toLocalDateTime()).toMillis() else Long.MAX_VALUE
SignalStore.notificationProfileValues().manuallyDisabledAt = if (inScheduledWindow) now else 0
}
}
.doOnComplete { ApplicationDependencies.getDatabaseObserver().notifyNotificationProfileObservers() }
.subscribeOn(Schedulers.io())
}
class NotificationProfileNotFoundException : Throwable() class NotificationProfileNotFoundException : Throwable()
} }

Wyświetl plik

@ -60,7 +60,7 @@ data class NotificationProfileSchedule(
} }
fun endDateTime(now: LocalDateTime): LocalDateTime { fun endDateTime(now: LocalDateTime): LocalDateTime {
return end.toLocalDateTime(now) return end.toLocalDateTime(now).plusDays(if (end < start) 1 else 0)
} }
} }