From d6dd7a82f1dec8161c1fb65e2704caf046c085b6 Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Wed, 16 Aug 2023 16:25:25 +1000 Subject: [PATCH] fix: error with legacy type and set type check --- .../expiration/ExpirationSettingsViewModel.kt | 17 ++++++++++++----- 1 file changed, 12 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 b00e177a25..a275ac3b9b 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 @@ -58,7 +58,10 @@ class ExpirationSettingsViewModel( init { // SETUP viewModelScope.launch { - expirationConfig = storage.getExpirationConfiguration(threadId) + expirationConfig = storage.getExpirationConfiguration(threadId)?.let { + if (ExpirationConfiguration.isNewConfigEnabled) it + else if (it) + } val expirationType = expirationConfig?.expiryMode val recipient = threadDb.getRecipientForThreadId(threadId) _recipient.value = recipient @@ -121,8 +124,12 @@ class ExpirationSettingsViewModel( fun onSetClick() = viewModelScope.launch { val expiryMode = _selectedExpirationTimer.value?.value ?: ExpiryMode.NONE + val typeValue = expiryMode.let { + if (it is ExpiryMode.Legacy) ExpiryMode.AfterRead(it.expirySeconds) + else it + } val address = recipient.value?.address - if (address == null || (expirationConfig?.expiryMode != expiryMode)) { + if (address == null || (expirationConfig?.expiryMode == typeValue)) { _uiState.update { it.copy(settingsSaved = false) } @@ -130,13 +137,13 @@ class ExpirationSettingsViewModel( } val expiryChangeTimestampMs = SnodeAPI.nowWithOffset - storage.setExpirationConfiguration(ExpirationConfiguration(threadId, expiryMode, expiryChangeTimestampMs)) + storage.setExpirationConfiguration(ExpirationConfiguration(threadId, typeValue, expiryChangeTimestampMs)) - val message = ExpirationTimerUpdate(expiryMode.expirySeconds.toInt()) + val message = ExpirationTimerUpdate(typeValue.expirySeconds.toInt()) message.sender = textSecurePreferences.getLocalNumber() message.recipient = address.serialize() message.sentTimestamp = expiryChangeTimestampMs - messageExpirationManager.setExpirationTimer(message, expiryMode) + messageExpirationManager.setExpirationTimer(message, typeValue) MessageSender.send(message, address) _uiState.update {