mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-24 10:35:19 +00:00
Cleanup
This commit is contained in:
parent
bc83c3da52
commit
88223be957
@ -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) {
|
||||||
ConfigurationMessageUtilities.forceSyncConfigurationNowIfNeeded(this@ExpirationSettingsActivity)
|
Event.SUCCESS -> {
|
||||||
finish()
|
ConfigurationMessageUtilities.forceSyncConfigurationNowIfNeeded(this@ExpirationSettingsActivity)
|
||||||
} else showToast(getString(R.string.ExpirationSettingsActivity_settings_not_updated))
|
finish()
|
||||||
|
}
|
||||||
|
Event.FAIL -> showToast(getString(R.string.ExpirationSettingsActivity_settings_not_updated))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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())
|
ExpirationTimerUpdate(mode.expirySeconds.toInt()).apply {
|
||||||
message.sender = textSecurePreferences.getLocalNumber()
|
sender = textSecurePreferences.getLocalNumber()
|
||||||
message.recipient = address.serialize()
|
recipient = address.serialize()
|
||||||
message.sentTimestamp = expiryChangeTimestampMs
|
sentTimestamp = expiryChangeTimestampMs
|
||||||
messageExpirationManager.setExpirationTimer(message, typeValue)
|
}.also { message ->
|
||||||
|
messageExpirationManager.setExpirationTimer(message, mode)
|
||||||
|
MessageSender.send(message, address)
|
||||||
|
}
|
||||||
|
|
||||||
MessageSender.send(message, address)
|
_event.send(Event.SUCCESS)
|
||||||
_event.send(Event(true))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@dagger.assisted.AssistedFactory
|
@dagger.assisted.AssistedFactory
|
||||||
|
Loading…
Reference in New Issue
Block a user