mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-27 06:29:54 +00:00
Remove old manual overrides for notification profiles.
This commit is contained in:
committed by
Greyson Parrelli
parent
f518862dc3
commit
be41c2e8cb
@@ -1,9 +1,13 @@
|
||||
package org.thoughtcrime.securesms.notifications.profiles
|
||||
|
||||
import android.content.Context
|
||||
import org.signal.core.util.concurrent.SignalExecutors
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase
|
||||
import org.thoughtcrime.securesms.keyvalue.NotificationProfileValues
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.storage.StorageSyncHelper
|
||||
import org.thoughtcrime.securesms.util.formatHours
|
||||
import org.thoughtcrime.securesms.util.toLocalDateTime
|
||||
import org.thoughtcrime.securesms.util.toLocalTime
|
||||
@@ -34,6 +38,13 @@ object NotificationProfiles {
|
||||
profile.schedule.startDateTime(localNow).toMillis(zoneId.toOffset()) > storeValues.manuallyDisabledAt
|
||||
}
|
||||
|
||||
if (shouldClearManualOverride(manualProfile, scheduledProfile)) {
|
||||
SignalExecutors.UNBOUNDED.execute {
|
||||
SignalDatabase.recipients.markNeedsSync(Recipient.self().id)
|
||||
StorageSyncHelper.scheduleSyncForDataChange()
|
||||
}
|
||||
}
|
||||
|
||||
if (manualProfile == null || scheduledProfile == null) {
|
||||
return manualProfile ?: scheduledProfile
|
||||
}
|
||||
@@ -45,6 +56,24 @@ object NotificationProfiles {
|
||||
}
|
||||
}
|
||||
|
||||
private fun shouldClearManualOverride(manualProfile: NotificationProfile?, scheduledProfile: NotificationProfile?): Boolean {
|
||||
val storeValues: NotificationProfileValues = SignalStore.notificationProfile
|
||||
var shouldScheduleSync = false
|
||||
|
||||
if (manualProfile == null && storeValues.manuallyEnabledProfile != 0L) {
|
||||
storeValues.manuallyEnabledProfile = 0
|
||||
storeValues.manuallyEnabledUntil = 0
|
||||
shouldScheduleSync = true
|
||||
}
|
||||
|
||||
if (scheduledProfile != null && storeValues.manuallyDisabledAt != 0L) {
|
||||
storeValues.manuallyDisabledAt = 0
|
||||
shouldScheduleSync = true
|
||||
}
|
||||
|
||||
return shouldScheduleSync
|
||||
}
|
||||
|
||||
fun getActiveProfileDescription(context: Context, profile: NotificationProfile, now: Long = System.currentTimeMillis()): String {
|
||||
val storeValues: NotificationProfileValues = SignalStore.notificationProfile
|
||||
|
||||
|
||||
@@ -218,10 +218,12 @@ object StorageSyncHelper {
|
||||
endAtTimestampMs = endTimestamp
|
||||
)
|
||||
)
|
||||
} else {
|
||||
} else if (SignalStore.notificationProfile.manuallyDisabledAt != 0L) {
|
||||
AccountRecord.NotificationProfileManualOverride(
|
||||
disabledAtTimestampMs = SignalStore.notificationProfile.manuallyDisabledAt
|
||||
)
|
||||
} else {
|
||||
AccountRecord.NotificationProfileManualOverride()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ class NotificationProfilesTest {
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
notificationProfileValues = mockk()
|
||||
notificationProfileValues = mockk(relaxed = true)
|
||||
every { notificationProfileValues.manuallyEnabledUntil } returns 0
|
||||
every { notificationProfileValues.manuallyDisabledAt } returns 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user