mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +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(
|
RadioOption(
|
||||||
value = "-1",
|
value = "-1",
|
||||||
title = getString(R.string.expiration_off),
|
title = getString(R.string.expiration_off),
|
||||||
|
enabled = viewModel.uiState.value.isSelfAdmin,
|
||||||
contentDescription = getString(R.string.AccessibilityId_disable_disappearing_messages)
|
contentDescription = getString(R.string.AccessibilityId_disable_disappearing_messages)
|
||||||
),
|
),
|
||||||
RadioOption(
|
RadioOption(
|
||||||
value = ExpirationType.DELETE_AFTER_READ_VALUE.toString(),
|
value = ExpirationType.DELETE_AFTER_READ_VALUE.toString(),
|
||||||
title = getString(R.string.expiration_type_disappear_after_read),
|
title = getString(R.string.expiration_type_disappear_after_read),
|
||||||
subtitle = getString(R.string.expiration_type_disappear_after_read_description),
|
subtitle = getString(R.string.expiration_type_disappear_after_read_description),
|
||||||
|
enabled = viewModel.uiState.value.isSelfAdmin,
|
||||||
contentDescription = getString(R.string.AccessibilityId_disappear_after_read_option)
|
contentDescription = getString(R.string.AccessibilityId_disappear_after_read_option)
|
||||||
),
|
),
|
||||||
RadioOption(
|
RadioOption(
|
||||||
value = ExpirationType.DELETE_AFTER_SEND_VALUE.toString(),
|
value = ExpirationType.DELETE_AFTER_SEND_VALUE.toString(),
|
||||||
title = getString(R.string.expiration_type_disappear_after_send),
|
title = getString(R.string.expiration_type_disappear_after_send),
|
||||||
subtitle = getString(R.string.expiration_type_disappear_after_send_description),
|
subtitle = getString(R.string.expiration_type_disappear_after_send_description),
|
||||||
|
enabled = viewModel.uiState.value.isSelfAdmin,
|
||||||
contentDescription = getString(R.string.AccessibilityId_disappear_after_send_option)
|
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.TextSecurePreferences
|
||||||
import org.session.libsession.utilities.recipients.Recipient
|
import org.session.libsession.utilities.recipients.Recipient
|
||||||
import org.session.libsignal.protos.SignalServiceProtos.Content.ExpirationType
|
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.Storage
|
||||||
import org.thoughtcrime.securesms.database.ThreadDatabase
|
import org.thoughtcrime.securesms.database.ThreadDatabase
|
||||||
import org.thoughtcrime.securesms.preferences.RadioOption
|
import org.thoughtcrime.securesms.preferences.RadioOption
|
||||||
@ -31,6 +32,7 @@ class ExpirationSettingsViewModel(
|
|||||||
private val textSecurePreferences: TextSecurePreferences,
|
private val textSecurePreferences: TextSecurePreferences,
|
||||||
private val messageExpirationManager: MessageExpirationManagerProtocol,
|
private val messageExpirationManager: MessageExpirationManagerProtocol,
|
||||||
private val threadDb: ThreadDatabase,
|
private val threadDb: ThreadDatabase,
|
||||||
|
private val groupDb: GroupDatabase,
|
||||||
private val storage: Storage
|
private val storage: Storage
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
@ -56,8 +58,14 @@ class ExpirationSettingsViewModel(
|
|||||||
expirationConfig = storage.getExpirationConfiguration(threadId)
|
expirationConfig = storage.getExpirationConfiguration(threadId)
|
||||||
val recipient = threadDb.getRecipientForThreadId(threadId)
|
val recipient = threadDb.getRecipientForThreadId(threadId)
|
||||||
_recipient.value = recipient
|
_recipient.value = recipient
|
||||||
_uiState.update {
|
val groupInfo = if (recipient?.isClosedGroupRecipient == true) {
|
||||||
it.copy(showExpirationTypeSelector = !ExpirationConfiguration.isNewConfigEnabled || (recipient?.isContactRecipient == true && !recipient.isLocalNumber))
|
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) {
|
_selectedExpirationType.value = if (ExpirationConfiguration.isNewConfigEnabled) {
|
||||||
if (recipient?.isLocalNumber == true || recipient?.isClosedGroupRecipient == true) {
|
if (recipient?.isLocalNumber == true || recipient?.isClosedGroupRecipient == true) {
|
||||||
@ -82,9 +90,9 @@ class ExpirationSettingsViewModel(
|
|||||||
}
|
}
|
||||||
}.onEach { options ->
|
}.onEach { options ->
|
||||||
_expirationTimerOptions.value = if (ExpirationConfiguration.isNewConfigEnabled && (recipient.value?.isLocalNumber == true || recipient.value?.isClosedGroupRecipient == true)) {
|
_expirationTimerOptions.value = if (ExpirationConfiguration.isNewConfigEnabled && (recipient.value?.isLocalNumber == true || recipient.value?.isClosedGroupRecipient == true)) {
|
||||||
options
|
options.map { it.copy(enabled = _uiState.value.isSelfAdmin) }
|
||||||
} else {
|
} else {
|
||||||
options.slice(1 until options.size)
|
options.slice(1 until options.size).map { it.copy(enabled = _uiState.value.isSelfAdmin) }
|
||||||
}
|
}
|
||||||
}.launchIn(viewModelScope)
|
}.launchIn(viewModelScope)
|
||||||
}
|
}
|
||||||
@ -141,6 +149,7 @@ class ExpirationSettingsViewModel(
|
|||||||
private val textSecurePreferences: TextSecurePreferences,
|
private val textSecurePreferences: TextSecurePreferences,
|
||||||
private val messageExpirationManager: MessageExpirationManagerProtocol,
|
private val messageExpirationManager: MessageExpirationManagerProtocol,
|
||||||
private val threadDb: ThreadDatabase,
|
private val threadDb: ThreadDatabase,
|
||||||
|
private val groupDb: GroupDatabase,
|
||||||
private val storage: Storage
|
private val storage: Storage
|
||||||
) : ViewModelProvider.Factory {
|
) : ViewModelProvider.Factory {
|
||||||
|
|
||||||
@ -152,6 +161,7 @@ class ExpirationSettingsViewModel(
|
|||||||
textSecurePreferences,
|
textSecurePreferences,
|
||||||
messageExpirationManager,
|
messageExpirationManager,
|
||||||
threadDb,
|
threadDb,
|
||||||
|
groupDb,
|
||||||
storage
|
storage
|
||||||
) as T
|
) as T
|
||||||
}
|
}
|
||||||
@ -159,6 +169,7 @@ class ExpirationSettingsViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
data class ExpirationSettingsUiState(
|
data class ExpirationSettingsUiState(
|
||||||
|
val isSelfAdmin: Boolean = false,
|
||||||
val showExpirationTypeSelector: Boolean = false,
|
val showExpirationTypeSelector: Boolean = false,
|
||||||
val settingsSaved: Boolean? = null
|
val settingsSaved: Boolean? = null
|
||||||
)
|
)
|
||||||
|
@ -12,6 +12,6 @@ class ExpirationConfiguration(
|
|||||||
val expirationType: ExpirationType? = ExpirationType.valueOf(expirationTypeValue)
|
val expirationType: ExpirationType? = ExpirationType.valueOf(expirationTypeValue)
|
||||||
|
|
||||||
companion object {
|
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…
Reference in New Issue
Block a user