mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 20:15:21 +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) {
|
||||||
|
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))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user