core, mobile: logic for enabling disappearing messages (#1588)

* core: logic for enabled for disappearing messages

* refactor

* update feature enabled in UI
This commit is contained in:
Evgeny Poberezkin
2022-12-16 10:27:59 +00:00
committed by GitHub
parent 6b8705e9f4
commit 8786e2147a
6 changed files with 30 additions and 15 deletions
@@ -2101,10 +2101,10 @@ data class FeatureEnabled(
get() = if (forUser) SimplexGreen else if (forContact) WarningYellow else HighOrLowlight
companion object {
fun enabled(user: ChatPreference, contact: ChatPreference): FeatureEnabled =
fun enabled(asymmetric: Boolean, user: ChatPreference, contact: ChatPreference): FeatureEnabled =
when {
user.allow == FeatureAllowed.ALWAYS && contact.allow == FeatureAllowed.NO -> FeatureEnabled(forUser = false, forContact = true)
user.allow == FeatureAllowed.NO && contact.allow == FeatureAllowed.ALWAYS -> FeatureEnabled(forUser = true, forContact = false)
user.allow == FeatureAllowed.ALWAYS && contact.allow == FeatureAllowed.NO -> FeatureEnabled(forUser = false, forContact = asymmetric)
user.allow == FeatureAllowed.NO && contact.allow == FeatureAllowed.ALWAYS -> FeatureEnabled(forUser = asymmetric, forContact = false)
contact.allow == FeatureAllowed.NO -> FeatureEnabled(forUser = false, forContact = false)
user.allow == FeatureAllowed.NO -> FeatureEnabled(forUser = false, forContact = false)
else -> FeatureEnabled(forUser = true, forContact = true)
@@ -2138,6 +2138,11 @@ enum class ChatFeature: Feature {
@SerialName("fullDelete") FullDelete,
@SerialName("voice") Voice;
val asymmetric: Boolean get() = when (this) {
TimedMessages -> false
else -> true
}
override val text: String
get() = when(this) {
TimedMessages -> generalGetString(R.string.timed_messages)
@@ -112,6 +112,7 @@ private fun FeatureSection(
onSelected: (ContactFeatureAllowed) -> Unit
) {
val enabled = FeatureEnabled.enabled(
feature.asymmetric,
user = ChatPreference(allow = allowFeature.value.allowed),
contact = pref.contactPreference
)