This commit is contained in:
andrew 2023-08-31 12:45:35 +09:30
parent bc83c3da52
commit 88223be957
2 changed files with 23 additions and 19 deletions

View File

@ -97,10 +97,13 @@ class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() {
lifecycleScope.launch { lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) { repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.event.collect { viewModel.event.collect {
if (it.saveSuccess) { when (it) {
Event.SUCCESS -> {
ConfigurationMessageUtilities.forceSyncConfigurationNowIfNeeded(this@ExpirationSettingsActivity) ConfigurationMessageUtilities.forceSyncConfigurationNowIfNeeded(this@ExpirationSettingsActivity)
finish() finish()
} else showToast(getString(R.string.ExpirationSettingsActivity_settings_not_updated)) }
Event.FAIL -> showToast(getString(R.string.ExpirationSettingsActivity_settings_not_updated))
}
} }
} }
} }

View File

@ -34,9 +34,9 @@ import kotlin.time.Duration.Companion.days
import kotlin.time.Duration.Companion.hours import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.minutes
data class Event( enum class Event {
val saveSuccess: Boolean SUCCESS, FAIL
) }
data class State( data class State(
val isGroup: Boolean = false, val isGroup: Boolean = false,
@ -125,28 +125,29 @@ class ExpirationSettingsViewModel(
override fun onSetClick() = viewModelScope.launch { override fun onSetClick() = viewModelScope.launch {
val state = _state.value val state = _state.value
val expiryMode = state.expiryMode ?: ExpiryMode.NONE val mode = (state.expiryMode ?: ExpiryMode.NONE).let {
val typeValue = expiryMode.let {
if (it is ExpiryMode.Legacy) ExpiryMode.AfterRead(it.expirySeconds) if (it is ExpiryMode.Legacy) ExpiryMode.AfterRead(it.expirySeconds)
else it else it
} }
val address = state.address val address = state.address
if (address == null || expirationConfig?.expiryMode == typeValue) { if (address == null || expirationConfig?.expiryMode == mode) {
_event.send(Event(false)) _event.send(Event.FAIL)
return@launch return@launch
} }
val expiryChangeTimestampMs = SnodeAPI.nowWithOffset val expiryChangeTimestampMs = SnodeAPI.nowWithOffset
storage.setExpirationConfiguration(ExpirationConfiguration(threadId, typeValue, expiryChangeTimestampMs)) storage.setExpirationConfiguration(ExpirationConfiguration(threadId, mode, expiryChangeTimestampMs))
val message = ExpirationTimerUpdate(typeValue.expirySeconds.toInt())
message.sender = textSecurePreferences.getLocalNumber()
message.recipient = address.serialize()
message.sentTimestamp = expiryChangeTimestampMs
messageExpirationManager.setExpirationTimer(message, typeValue)
ExpirationTimerUpdate(mode.expirySeconds.toInt()).apply {
sender = textSecurePreferences.getLocalNumber()
recipient = address.serialize()
sentTimestamp = expiryChangeTimestampMs
}.also { message ->
messageExpirationManager.setExpirationTimer(message, mode)
MessageSender.send(message, address) MessageSender.send(message, address)
_event.send(Event(true)) }
_event.send(Event.SUCCESS)
} }
@dagger.assisted.AssistedFactory @dagger.assisted.AssistedFactory