Group migration refactor

This commit is contained in:
charles 2022-11-18 17:45:40 +11:00
parent 3bb19e4df8
commit 24a020b99f
4 changed files with 19 additions and 12 deletions

View File

@ -48,7 +48,7 @@ class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() {
private fun mayAddTestExpiryOption(expiryOptions: List<RadioOption>): List<RadioOption> { private fun mayAddTestExpiryOption(expiryOptions: List<RadioOption>): List<RadioOption> {
return if (BuildConfig.DEBUG) { return if (BuildConfig.DEBUG) {
val options = expiryOptions.toMutableList() val options = expiryOptions.toMutableList()
options.add(1, RadioOption("60", "1 Minute")) options.add(1, RadioOption("60", "1 Minute (for testing purposes)"))
options options
} else expiryOptions } else expiryOptions
} }
@ -123,8 +123,8 @@ class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() {
} }
} }
launch { launch {
viewModel.selectedExpirationTimer.collect { expirationTimer -> viewModel.selectedExpirationTimer.collect { option ->
val position = deleteTypeOptions.indexOfFirst { it.value.toIntOrNull() == expirationTimer } val position = viewModel.expirationTimerOptions.value.indexOfFirst { it.value == option?.value }
timerOptionAdapter.setSelectedPosition(max(0, position)) timerOptionAdapter.setSelectedPosition(max(0, position))
} }
} }

View File

@ -37,8 +37,8 @@ class ExpirationSettingsViewModel(
private val _selectedExpirationType = MutableStateFlow<ExpirationType?>(null) private val _selectedExpirationType = MutableStateFlow<ExpirationType?>(null)
val selectedExpirationType: StateFlow<ExpirationType?> = _selectedExpirationType val selectedExpirationType: StateFlow<ExpirationType?> = _selectedExpirationType
private val _selectedExpirationTimer = MutableStateFlow(0) private val _selectedExpirationTimer = MutableStateFlow(afterSendOptions.firstOrNull())
val selectedExpirationTimer: StateFlow<Int> = _selectedExpirationTimer val selectedExpirationTimer: StateFlow<RadioOption?> = _selectedExpirationTimer
private val _expirationTimerOptions = MutableStateFlow<List<RadioOption>>(emptyList()) private val _expirationTimerOptions = MutableStateFlow<List<RadioOption>>(emptyList())
val expirationTimerOptions: StateFlow<List<RadioOption>> = _expirationTimerOptions val expirationTimerOptions: StateFlow<List<RadioOption>> = _expirationTimerOptions
@ -52,7 +52,11 @@ class ExpirationSettingsViewModel(
if (recipient?.isLocalNumber == true || recipient?.isClosedGroupRecipient == true) { if (recipient?.isLocalNumber == true || recipient?.isClosedGroupRecipient == true) {
_selectedExpirationType.value = ExpirationType.DELETE_AFTER_SEND _selectedExpirationType.value = ExpirationType.DELETE_AFTER_SEND
} }
_selectedExpirationTimer.value = expirationConfig?.durationSeconds ?: 0 _selectedExpirationTimer.value = when(expirationConfig?.expirationType) {
ExpirationType.DELETE_AFTER_SEND -> afterSendOptions.find { it.value.toIntOrNull() == expirationConfig?.durationSeconds }
ExpirationType.DELETE_AFTER_READ -> afterReadOptions.find { it.value.toIntOrNull() == expirationConfig?.durationSeconds }
else -> afterSendOptions.firstOrNull()
}
} }
selectedExpirationType.mapLatest { selectedExpirationType.mapLatest {
when (it) { when (it) {
@ -70,11 +74,11 @@ class ExpirationSettingsViewModel(
} }
fun onExpirationTimerSelected(option: RadioOption) { fun onExpirationTimerSelected(option: RadioOption) {
_selectedExpirationTimer.value = option.value.toIntOrNull() ?: 0 _selectedExpirationTimer.value = option
} }
fun onSetClick() = viewModelScope.launch { fun onSetClick() = viewModelScope.launch {
val expiresIn = _selectedExpirationTimer.value val expiresIn = _selectedExpirationTimer.value?.value?.toIntOrNull() ?: 0
val expiryType = _selectedExpirationType.value?.number ?: 0 val expiryType = _selectedExpirationType.value?.number ?: 0
val expiryChangeTimestamp = System.currentTimeMillis() val expiryChangeTimestamp = System.currentTimeMillis()
threadDb.updateExpiryConfig(threadId, expiresIn, expiryType, expiryChangeTimestamp) threadDb.updateExpiryConfig(threadId, expiresIn, expiryType, expiryChangeTimestamp)

View File

@ -46,7 +46,7 @@ public class RecipientDatabase extends Database {
private static final String COLOR = "color"; private static final String COLOR = "color";
private static final String SEEN_INVITE_REMINDER = "seen_invite_reminder"; private static final String SEEN_INVITE_REMINDER = "seen_invite_reminder";
private static final String DEFAULT_SUBSCRIPTION_ID = "default_subscription_id"; private static final String DEFAULT_SUBSCRIPTION_ID = "default_subscription_id";
private static final String EXPIRE_MESSAGES = "expire_messages"; static final String EXPIRE_MESSAGES = "expire_messages";
private static final String REGISTERED = "registered"; private static final String REGISTERED = "registered";
private static final String PROFILE_KEY = "profile_key"; private static final String PROFILE_KEY = "profile_key";
private static final String SYSTEM_DISPLAY_NAME = "system_display_name"; private static final String SYSTEM_DISPLAY_NAME = "system_display_name";

View File

@ -150,9 +150,12 @@ public class ThreadDatabase extends Database {
} }
public static String getUpdateGroupConversationExpiryTypeCommand() { public static String getUpdateGroupConversationExpiryTypeCommand() {
return "UPDATE " + TABLE_NAME + " SET " + EXPIRY_TYPE + " = 1 " + return "UPDATE " + TABLE_NAME + " SET " + EXPIRY_TYPE + " = 1, " +
"WHERE " + ADDRESS + " LIKE '" + CLOSED_GROUP_PREFIX + "%'" + EXPIRES_IN + " = (SELECT " + RecipientDatabase.EXPIRE_MESSAGES + " FROM " + RecipientDatabase.TABLE_NAME +
"AND " + EXPIRES_IN + " > 0"; " WHERE " + TABLE_NAME + "." + ADDRESS + " = " + RecipientDatabase.TABLE_NAME + "." + RecipientDatabase.ADDRESS + " AND " + RecipientDatabase.EXPIRE_MESSAGES + " > 0 )" +
"WHERE " + TABLE_NAME + "." + ADDRESS + " LIKE '" + CLOSED_GROUP_PREFIX + "%' " +
"AND EXISTS (SELECT " + RecipientDatabase.EXPIRE_MESSAGES + " FROM " + RecipientDatabase.TABLE_NAME +
" WHERE " + TABLE_NAME + "." + ADDRESS + " = " + RecipientDatabase.TABLE_NAME + "." + RecipientDatabase.ADDRESS + " AND " + RecipientDatabase.EXPIRE_MESSAGES + " > 0 )";
} }
public static String getUpdateOneToOneConversationExpiryTypeCommand() { public static String getUpdateOneToOneConversationExpiryTypeCommand() {