From 87d76b21da3a9a37bef3db7254fb1d96f2add2eb Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Thu, 27 Jul 2023 14:22:10 +1000 Subject: [PATCH] refactor: moving radio indexes out of expiration configuration --- .../expiration/ExpirationSettingsViewModel.kt | 21 ++++++++++++++++--- .../securesms/database/Storage.kt | 2 ++ .../messages/ExpirationConfiguration.kt | 3 +-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModel.kt index d559d42b84..e0c06054c8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/expiration/ExpirationSettingsViewModel.kt @@ -71,7 +71,7 @@ class ExpirationSettingsViewModel( if (recipient?.isLocalNumber == true || recipient?.isClosedGroupRecipient == true) { ExpirationType.DELETE_AFTER_SEND.number } else { - expirationConfig?.expirationTypeValue ?: -1 + expirationConfig?.typeRadioIndex() ?: -1 } } else { expirationConfig?.expirationTypeValue?.let { 0 /* Legacy */ } ?: -1 @@ -111,10 +111,10 @@ class ExpirationSettingsViewModel( if (typeValue == 0) { typeValue = ExpirationType.DELETE_AFTER_READ_VALUE } - val expiryType = typeValue + val expiryType = typeValue.expiry() val expirationTimer = _selectedExpirationTimer.value?.value?.toIntOrNull() ?: 0 val address = recipient.value?.address - if (address == null || (expirationConfig?.expirationTypeValue == expiryType && expirationConfig?.durationSeconds == expirationTimer)) { + if (address == null || (expirationConfig?.typeRadioIndex() == typeValue && expirationConfig?.durationSeconds == expirationTimer)) { _uiState.update { it.copy(settingsSaved = false) } @@ -177,3 +177,18 @@ data class ExpirationSettingsUiState( val showExpirationTypeSelector: Boolean = false, val settingsSaved: Boolean? = null ) + +fun ExpirationConfiguration?.typeRadioIndex(): Int { + if (this == null || expirationType == null) return -1 + return when { + expirationType == ExpirationType.DELETE_AFTER_READ -> ExpirationType.DELETE_AFTER_READ_VALUE + else -> -1 + } + + return if (expirationType == ) +} + +fun Int.expiry(): ExpirationType? { + if (this == -1) return null + TODO() +} \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt index bef21ddfb5..74801bb1be 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -1675,6 +1675,8 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co return if (recipient.isContactRecipient && recipient.address.serialize().startsWith(IdPrefix.STANDARD.value)) { // read it from contacts config if exists configFactory.contacts?.get(recipient.address.serialize())?.let { contact -> + val mode = contact.expiryMode + ExpirationConfiguration(threadId, mode.expirySeconds,) contact.expiryMode } } else if (recipient.isClosedGroupRecipient) { diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/ExpirationConfiguration.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/ExpirationConfiguration.kt index cfaa2bd084..0b5e81a7a0 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/ExpirationConfiguration.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/ExpirationConfiguration.kt @@ -5,10 +5,9 @@ import org.session.libsignal.protos.SignalServiceProtos.Content.ExpirationType class ExpirationConfiguration( val threadId: Long = -1, val durationSeconds: Int = 0, - val expirationTypeValue: Int = -1, + val expirationType: ExpirationType? = null, val updatedTimestampMs: Long = 0 ) { - val expirationType: ExpirationType? = ExpirationType.valueOf(expirationTypeValue) val isEnabled = durationSeconds > 0 && expirationType != null companion object {