mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-28 02:37:46 +00:00
Only allow admins to change disappearing messages config
This commit is contained in:
parent
1f0a0760ba
commit
cdbf76c0f1
@ -168,18 +168,21 @@ class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() {
|
||||
RadioOption(
|
||||
value = "-1",
|
||||
title = getString(R.string.expiration_off),
|
||||
enabled = viewModel.uiState.value.isSelfAdmin,
|
||||
contentDescription = getString(R.string.AccessibilityId_disable_disappearing_messages)
|
||||
),
|
||||
RadioOption(
|
||||
value = ExpirationType.DELETE_AFTER_READ_VALUE.toString(),
|
||||
title = getString(R.string.expiration_type_disappear_after_read),
|
||||
subtitle = getString(R.string.expiration_type_disappear_after_read_description),
|
||||
enabled = viewModel.uiState.value.isSelfAdmin,
|
||||
contentDescription = getString(R.string.AccessibilityId_disappear_after_read_option)
|
||||
),
|
||||
RadioOption(
|
||||
value = ExpirationType.DELETE_AFTER_SEND_VALUE.toString(),
|
||||
title = getString(R.string.expiration_type_disappear_after_send),
|
||||
subtitle = getString(R.string.expiration_type_disappear_after_send_description),
|
||||
enabled = viewModel.uiState.value.isSelfAdmin,
|
||||
contentDescription = getString(R.string.AccessibilityId_disappear_after_send_option)
|
||||
)
|
||||
)
|
||||
|
@ -20,6 +20,7 @@ import org.session.libsession.utilities.SSKEnvironment.MessageExpirationManagerP
|
||||
import org.session.libsession.utilities.TextSecurePreferences
|
||||
import org.session.libsession.utilities.recipients.Recipient
|
||||
import org.session.libsignal.protos.SignalServiceProtos.Content.ExpirationType
|
||||
import org.thoughtcrime.securesms.database.GroupDatabase
|
||||
import org.thoughtcrime.securesms.database.Storage
|
||||
import org.thoughtcrime.securesms.database.ThreadDatabase
|
||||
import org.thoughtcrime.securesms.preferences.RadioOption
|
||||
@ -31,6 +32,7 @@ class ExpirationSettingsViewModel(
|
||||
private val textSecurePreferences: TextSecurePreferences,
|
||||
private val messageExpirationManager: MessageExpirationManagerProtocol,
|
||||
private val threadDb: ThreadDatabase,
|
||||
private val groupDb: GroupDatabase,
|
||||
private val storage: Storage
|
||||
) : ViewModel() {
|
||||
|
||||
@ -56,8 +58,14 @@ class ExpirationSettingsViewModel(
|
||||
expirationConfig = storage.getExpirationConfiguration(threadId)
|
||||
val recipient = threadDb.getRecipientForThreadId(threadId)
|
||||
_recipient.value = recipient
|
||||
_uiState.update {
|
||||
it.copy(showExpirationTypeSelector = !ExpirationConfiguration.isNewConfigEnabled || (recipient?.isContactRecipient == true && !recipient.isLocalNumber))
|
||||
val groupInfo = if (recipient?.isClosedGroupRecipient == true) {
|
||||
groupDb.getGroup(recipient.address.toGroupString()).orNull()
|
||||
} else null
|
||||
_uiState.update { currentUiState ->
|
||||
currentUiState.copy(
|
||||
isSelfAdmin = groupInfo?.admins?.any{ it.serialize() == textSecurePreferences.getLocalNumber() } == true,
|
||||
showExpirationTypeSelector = !ExpirationConfiguration.isNewConfigEnabled || (recipient?.isContactRecipient == true && !recipient.isLocalNumber)
|
||||
)
|
||||
}
|
||||
_selectedExpirationType.value = if (ExpirationConfiguration.isNewConfigEnabled) {
|
||||
if (recipient?.isLocalNumber == true || recipient?.isClosedGroupRecipient == true) {
|
||||
@ -82,9 +90,9 @@ class ExpirationSettingsViewModel(
|
||||
}
|
||||
}.onEach { options ->
|
||||
_expirationTimerOptions.value = if (ExpirationConfiguration.isNewConfigEnabled && (recipient.value?.isLocalNumber == true || recipient.value?.isClosedGroupRecipient == true)) {
|
||||
options
|
||||
options.map { it.copy(enabled = _uiState.value.isSelfAdmin) }
|
||||
} else {
|
||||
options.slice(1 until options.size)
|
||||
options.slice(1 until options.size).map { it.copy(enabled = _uiState.value.isSelfAdmin) }
|
||||
}
|
||||
}.launchIn(viewModelScope)
|
||||
}
|
||||
@ -141,6 +149,7 @@ class ExpirationSettingsViewModel(
|
||||
private val textSecurePreferences: TextSecurePreferences,
|
||||
private val messageExpirationManager: MessageExpirationManagerProtocol,
|
||||
private val threadDb: ThreadDatabase,
|
||||
private val groupDb: GroupDatabase,
|
||||
private val storage: Storage
|
||||
) : ViewModelProvider.Factory {
|
||||
|
||||
@ -152,6 +161,7 @@ class ExpirationSettingsViewModel(
|
||||
textSecurePreferences,
|
||||
messageExpirationManager,
|
||||
threadDb,
|
||||
groupDb,
|
||||
storage
|
||||
) as T
|
||||
}
|
||||
@ -159,6 +169,7 @@ class ExpirationSettingsViewModel(
|
||||
}
|
||||
|
||||
data class ExpirationSettingsUiState(
|
||||
val isSelfAdmin: Boolean = false,
|
||||
val showExpirationTypeSelector: Boolean = false,
|
||||
val settingsSaved: Boolean? = null
|
||||
)
|
||||
|
@ -12,6 +12,6 @@ class ExpirationConfiguration(
|
||||
val expirationType: ExpirationType? = ExpirationType.valueOf(expirationTypeValue)
|
||||
|
||||
companion object {
|
||||
val isNewConfigEnabled = true /* TODO: System.currentTimeMillis() > 1_674_000_000_000 // 18/01/2023 */
|
||||
val isNewConfigEnabled = true /* TODO: System.currentTimeMillis() > 1_676_851_200_000 // 13/02/2023 */
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user