Implement default times

This commit is contained in:
andrew 2023-08-31 12:57:28 +09:30
parent 4e424384be
commit 58c4467749
2 changed files with 16 additions and 2 deletions

View File

@ -62,7 +62,6 @@ import org.thoughtcrime.securesms.ui.Divider
import org.thoughtcrime.securesms.ui.LocalExtraColors import org.thoughtcrime.securesms.ui.LocalExtraColors
import org.thoughtcrime.securesms.ui.PreviewTheme import org.thoughtcrime.securesms.ui.PreviewTheme
import org.thoughtcrime.securesms.ui.ThemeResPreviewParameterProvider import org.thoughtcrime.securesms.ui.ThemeResPreviewParameterProvider
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
import javax.inject.Inject import javax.inject.Inject
import kotlin.math.min import kotlin.math.min

View File

@ -111,8 +111,18 @@ class ExpirationSettingsViewModel(
} }
} }
/**
* When enabling Disappearing Messages (for screens which provide the `Delete Type` options) the default `Timer` selection should be:
* Disappear After Read: `12 Hours`
* Disappear After Send: `1 Day`
* Legacy: `1 Day`
* */
override fun setType(type: ExpiryType) { override fun setType(type: ExpiryType) {
_state.update { it.copy(expiryMode = type.mode(0)) } if (state.value.expiryType == type) return
_state.update {
it.copy(expiryMode = type.defaultMode())
}
} }
override fun setTime(seconds: Long) { override fun setTime(seconds: Long) {
@ -300,6 +310,11 @@ enum class ExpiryType(private val createMode: (Long) -> ExpiryMode) {
AFTER_READ(ExpiryMode::AfterRead); AFTER_READ(ExpiryMode::AfterRead);
fun mode(seconds: Long) = createMode(seconds) fun mode(seconds: Long) = createMode(seconds)
fun defaultMode() = when(this) {
AFTER_READ -> 43200L
else -> 86400L
}.let { mode(it) }
} }
private val ExpiryMode.type: ExpiryType get() = when(this) { private val ExpiryMode.type: ExpiryType get() = when(this) {