refactor: moving radio indexes out of expiration configuration

This commit is contained in:
0x330a 2023-07-27 14:22:10 +10:00
parent 0e30d14b96
commit 87d76b21da
No known key found for this signature in database
GPG Key ID: 267811D6E6A2698C
3 changed files with 21 additions and 5 deletions

View File

@ -71,7 +71,7 @@ class ExpirationSettingsViewModel(
if (recipient?.isLocalNumber == true || recipient?.isClosedGroupRecipient == true) { if (recipient?.isLocalNumber == true || recipient?.isClosedGroupRecipient == true) {
ExpirationType.DELETE_AFTER_SEND.number ExpirationType.DELETE_AFTER_SEND.number
} else { } else {
expirationConfig?.expirationTypeValue ?: -1 expirationConfig?.typeRadioIndex() ?: -1
} }
} else { } else {
expirationConfig?.expirationTypeValue?.let { 0 /* Legacy */ } ?: -1 expirationConfig?.expirationTypeValue?.let { 0 /* Legacy */ } ?: -1
@ -111,10 +111,10 @@ class ExpirationSettingsViewModel(
if (typeValue == 0) { if (typeValue == 0) {
typeValue = ExpirationType.DELETE_AFTER_READ_VALUE typeValue = ExpirationType.DELETE_AFTER_READ_VALUE
} }
val expiryType = typeValue val expiryType = typeValue.expiry()
val expirationTimer = _selectedExpirationTimer.value?.value?.toIntOrNull() ?: 0 val expirationTimer = _selectedExpirationTimer.value?.value?.toIntOrNull() ?: 0
val address = recipient.value?.address 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 { _uiState.update {
it.copy(settingsSaved = false) it.copy(settingsSaved = false)
} }
@ -177,3 +177,18 @@ data class ExpirationSettingsUiState(
val showExpirationTypeSelector: Boolean = false, val showExpirationTypeSelector: Boolean = false,
val settingsSaved: Boolean? = null 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()
}

View File

@ -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)) { return if (recipient.isContactRecipient && recipient.address.serialize().startsWith(IdPrefix.STANDARD.value)) {
// read it from contacts config if exists // read it from contacts config if exists
configFactory.contacts?.get(recipient.address.serialize())?.let { contact -> configFactory.contacts?.get(recipient.address.serialize())?.let { contact ->
val mode = contact.expiryMode
ExpirationConfiguration(threadId, mode.expirySeconds,)
contact.expiryMode contact.expiryMode
} }
} else if (recipient.isClosedGroupRecipient) { } else if (recipient.isClosedGroupRecipient) {

View File

@ -5,10 +5,9 @@ import org.session.libsignal.protos.SignalServiceProtos.Content.ExpirationType
class ExpirationConfiguration( class ExpirationConfiguration(
val threadId: Long = -1, val threadId: Long = -1,
val durationSeconds: Int = 0, val durationSeconds: Int = 0,
val expirationTypeValue: Int = -1, val expirationType: ExpirationType? = null,
val updatedTimestampMs: Long = 0 val updatedTimestampMs: Long = 0
) { ) {
val expirationType: ExpirationType? = ExpirationType.valueOf(expirationTypeValue)
val isEnabled = durationSeconds > 0 && expirationType != null val isEnabled = durationSeconds > 0 && expirationType != null
companion object { companion object {