Standardize internal UI state property naming.

This commit is contained in:
Jeffrey Starke
2025-10-22 09:45:49 -04:00
committed by Greyson Parrelli
parent d4c266561f
commit e235ce52e5
9 changed files with 82 additions and 83 deletions

View File

@@ -11,11 +11,11 @@ import org.thoughtcrime.securesms.components.settings.app.backups.remote.BackupK
* View model for [ForgotBackupKeyFragment]
*/
class ForgotBackupKeyViewModel : ViewModel(), BackupKeyCredentialManagerHandler {
private val _uiState = MutableStateFlow(BackupKeyDisplayUiState())
val uiState: StateFlow<BackupKeyDisplayUiState> = _uiState
private val internalUiState = MutableStateFlow(BackupKeyDisplayUiState())
val uiState: StateFlow<BackupKeyDisplayUiState> = internalUiState
override fun updateBackupKeySaveState(newState: BackupKeySaveState?) {
_uiState.update { it.copy(keySaveState = newState) }
internalUiState.update { it.copy(keySaveState = newState) }
}
}

View File

@@ -18,8 +18,8 @@ class AccountSettingsViewModel : ViewModel() {
}
fun togglePinKeyboardType() {
store.update { previousState ->
previousState.copy(pinKeyboardType = previousState.pinKeyboardType.other)
store.update {
it.copy(pinKeyboardType = it.pinKeyboardType.other)
}
}

View File

@@ -22,22 +22,22 @@ import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.whispersystems.signalservice.api.AccountEntropyPool
class BackupKeyDisplayViewModel : ViewModel(), BackupKeyCredentialManagerHandler {
private val _uiState = MutableStateFlow(BackupKeyDisplayUiState())
val uiState: StateFlow<BackupKeyDisplayUiState> = _uiState.asStateFlow()
private val internalUiState = MutableStateFlow(BackupKeyDisplayUiState())
val uiState: StateFlow<BackupKeyDisplayUiState> = internalUiState.asStateFlow()
override fun updateBackupKeySaveState(newState: BackupKeySaveState?) {
_uiState.update { it.copy(keySaveState = newState) }
internalUiState.update { it.copy(keySaveState = newState) }
}
fun rotateBackupKey() {
viewModelScope.launch {
_uiState.update { it.copy(rotationState = BackupKeyRotationState.GENERATING_KEY) }
internalUiState.update { it.copy(rotationState = BackupKeyRotationState.GENERATING_KEY) }
val stagedKeyRotations = withContext(SignalDispatchers.IO) {
BackupRepository.stageBackupKeyRotations()
}
_uiState.update {
internalUiState.update {
it.copy(
accountEntropyPool = stagedKeyRotations.aep,
stagedKeyRotations = stagedKeyRotations,
@@ -49,15 +49,15 @@ class BackupKeyDisplayViewModel : ViewModel(), BackupKeyCredentialManagerHandler
fun commitBackupKey() {
viewModelScope.launch {
_uiState.update { it.copy(rotationState = BackupKeyRotationState.COMMITTING_KEY) }
internalUiState.update { it.copy(rotationState = BackupKeyRotationState.COMMITTING_KEY) }
val keyRotations = _uiState.value.stagedKeyRotations ?: error("No key rotations to commit!")
val keyRotations = internalUiState.value.stagedKeyRotations ?: error("No key rotations to commit!")
withContext(SignalDispatchers.IO) {
BackupRepository.commitAEPKeyRotation(keyRotations)
}
_uiState.update { it.copy(rotationState = BackupKeyRotationState.FINISHED) }
internalUiState.update { it.copy(rotationState = BackupKeyRotationState.FINISHED) }
}
}

View File

@@ -151,8 +151,8 @@ class ChangeNumberViewModel : ViewModel() {
}
fun togglePinKeyboardType() {
store.update { previousState ->
previousState.copy(pinKeyboardType = previousState.pinKeyboardType.other)
store.update {
it.copy(pinKeyboardType = it.pinKeyboardType.other)
}
}
@@ -442,6 +442,7 @@ class ChangeNumberViewModel : ViewModel() {
svr3Credentials = result.svr3Credentials
)
}
else -> Log.i(TAG, "Received exception during verification.", result.getCause())
}
@@ -459,6 +460,7 @@ class ChangeNumberViewModel : ViewModel() {
svr3Credentials = result.svr3Credentials
)
}
is ChangeNumberResult.SvrWrongPin -> {
store.update {
it.copy(
@@ -466,6 +468,7 @@ class ChangeNumberViewModel : ViewModel() {
)
}
}
else -> Log.i(TAG, "Received exception during change number.", result.getCause())
}

View File

@@ -32,8 +32,8 @@ class NewConversationViewModel : ViewModel() {
private val TAG = Log.tag(NewConversationViewModel::class)
}
private val _uiState = MutableStateFlow(NewConversationUiState())
val uiState: StateFlow<NewConversationUiState> = _uiState.asStateFlow()
private val internalUiState = MutableStateFlow(NewConversationUiState())
val uiState: StateFlow<NewConversationUiState> = internalUiState.asStateFlow()
private val contactsManagementRepo = ContactsManagementRepository(AppDependencies.application)
@@ -53,12 +53,12 @@ class NewConversationViewModel : ViewModel() {
}
private fun openConversation(recipientId: RecipientId) {
_uiState.update { it.copy(pendingDestination = recipientId) }
internalUiState.update { it.copy(pendingDestination = recipientId) }
}
private fun resolveAndOpenConversation(phone: PhoneNumber?) {
viewModelScope.launch {
_uiState.update { it.copy(isRefreshingRecipient = true) }
internalUiState.update { it.copy(isRefreshingRecipient = true) }
val lookupResult = withContext(Dispatchers.IO) {
if (phone != null) {
@@ -71,7 +71,7 @@ class NewConversationViewModel : ViewModel() {
when (lookupResult) {
is RecipientRepository.LookupResult.Success -> {
val recipient = Recipient.resolved(lookupResult.recipientId)
_uiState.update { it.copy(isRefreshingRecipient = false) }
internalUiState.update { it.copy(isRefreshingRecipient = false) }
if (recipient.isRegistered && recipient.hasServiceId) {
openConversation(recipient.id)
@@ -81,7 +81,7 @@ class NewConversationViewModel : ViewModel() {
}
is RecipientRepository.LookupResult.NotFound, is RecipientRepository.LookupResult.InvalidEntry -> {
_uiState.update {
internalUiState.update {
it.copy(
isRefreshingRecipient = false,
userMessage = Info.RecipientNotSignalUser(phone)
@@ -90,7 +90,7 @@ class NewConversationViewModel : ViewModel() {
}
is RecipientRepository.LookupResult.NetworkError -> {
_uiState.update {
internalUiState.update {
it.copy(
isRefreshingRecipient = false,
userMessage = Info.NetworkError
@@ -102,7 +102,7 @@ class NewConversationViewModel : ViewModel() {
}
fun showRemoveConfirmation(recipient: Recipient) {
_uiState.update {
internalUiState.update {
it.copy(userMessage = Prompt.ConfirmRemoveRecipient(recipient))
}
}
@@ -111,7 +111,7 @@ class NewConversationViewModel : ViewModel() {
contactsManagementRepo.hideContact(recipient).await()
refresh()
_uiState.update {
internalUiState.update {
it.copy(
shouldResetContactsList = true,
userMessage = Info.RecipientRemoved(recipient)
@@ -120,7 +120,7 @@ class NewConversationViewModel : ViewModel() {
}
fun showBlockConfirmation(recipient: Recipient) {
_uiState.update {
internalUiState.update {
it.copy(userMessage = Prompt.ConfirmBlockRecipient(recipient))
}
}
@@ -129,7 +129,7 @@ class NewConversationViewModel : ViewModel() {
contactsManagementRepo.blockContact(recipient).await()
refresh()
_uiState.update {
internalUiState.update {
it.copy(
shouldResetContactsList = true,
userMessage = Info.RecipientBlocked(recipient)
@@ -138,27 +138,27 @@ class NewConversationViewModel : ViewModel() {
}
fun onUserAlreadyInACall() {
_uiState.update { it.copy(userMessage = Info.UserAlreadyInAnotherCall) }
internalUiState.update { it.copy(userMessage = Info.UserAlreadyInAnotherCall) }
}
fun onContactsListReset() {
_uiState.update { it.copy(shouldResetContactsList = false) }
internalUiState.update { it.copy(shouldResetContactsList = false) }
}
fun refresh() {
viewModelScope.launch {
_uiState.update { it.copy(isRefreshingContacts = true) }
internalUiState.update { it.copy(isRefreshingContacts = true) }
withContext(Dispatchers.IO) {
ContactDiscovery.refreshAll(AppDependencies.application, true)
}
_uiState.update { it.copy(isRefreshingContacts = false) }
internalUiState.update { it.copy(isRefreshingContacts = false) }
}
}
fun onUserMessageDismissed() {
_uiState.update { it.copy(userMessage = null) }
internalUiState.update { it.copy(userMessage = null) }
}
}

View File

@@ -243,8 +243,8 @@ class RegistrationViewModel : ViewModel() {
}
fun togglePinKeyboardType() {
store.update { previousState ->
previousState.copy(pinKeyboardType = previousState.pinKeyboardType.other)
store.update {
it.copy(pinKeyboardType = it.pinKeyboardType.other)
}
}

View File

@@ -31,8 +31,8 @@ class ReRegisterWithPinViewModel : ViewModel() {
}
fun toggleKeyboardType() {
store.update { previousState ->
previousState.copy(pinKeyboardType = previousState.pinKeyboardType.other)
store.update {
it.copy(pinKeyboardType = it.pinKeyboardType.other)
}
}
}

View File

@@ -24,8 +24,8 @@ import org.thoughtcrime.securesms.stickers.AvailableStickerPack.DownloadStatus
class StickerManagementViewModel : ViewModel() {
private val stickerManagementRepo = StickerManagementRepository
private val _uiState = MutableStateFlow(StickerManagementUiState())
val uiState: StateFlow<StickerManagementUiState> = _uiState.asStateFlow()
private val internalUiState = MutableStateFlow(StickerManagementUiState())
val uiState: StateFlow<StickerManagementUiState> = internalUiState.asStateFlow()
private val downloadStatusByPackId: MutableStateFlow<Map<StickerPackId, DownloadStatus>> = MutableStateFlow(emptyMap())
@@ -68,12 +68,12 @@ class StickerManagementViewModel : ViewModel() {
)
}
_uiState.update { previousState ->
previousState.copy(
internalUiState.update {
it.copy(
availableBlessedPacks = availableBlessedPacks,
availableNotBlessedPacks = availableNotBlessedPacks,
installedPacks = installedPacks,
multiSelectEnabled = if (installedPacks.isEmpty()) false else previousState.multiSelectEnabled
multiSelectEnabled = if (installedPacks.isEmpty()) false else it.multiSelectEnabled
)
}
}
@@ -86,10 +86,8 @@ class StickerManagementViewModel : ViewModel() {
StickerManagementRepository.installStickerPack(packId = pack.id, packKey = pack.key, notify = true)
updatePackDownloadStatus(pack.id, DownloadStatus.Downloaded)
_uiState.update { previousState ->
previousState.copy(
actionConfirmation = StickerManagementConfirmation.InstalledPack(pack.record.title)
)
internalUiState.update {
it.copy(actionConfirmation = StickerManagementConfirmation.InstalledPack(pack.record.title))
}
delay(1500) // wait, so we show the downloaded status for a bit before removing this row from the available sticker packs list
@@ -110,11 +108,9 @@ class StickerManagementViewModel : ViewModel() {
return
}
if (_uiState.value.multiSelectEnabled) {
_uiState.update { previousState ->
previousState.copy(
userPrompt = ConfirmRemoveStickerPacksPrompt(numItemsToDelete = packIds.size)
)
if (internalUiState.value.multiSelectEnabled) {
internalUiState.update {
it.copy(userPrompt = ConfirmRemoveStickerPacksPrompt(numItemsToDelete = packIds.size))
}
} else {
uninstallStickerPacks(packIds)
@@ -122,48 +118,48 @@ class StickerManagementViewModel : ViewModel() {
}
fun onUninstallStickerPacksConfirmed(packIds: Set<StickerPackId>) {
_uiState.update { previousState -> previousState.copy(userPrompt = null) }
internalUiState.update { it.copy(userPrompt = null) }
uninstallStickerPacks(packIds)
}
fun onUninstallStickerPacksCanceled() {
_uiState.update { previousState -> previousState.copy(userPrompt = null) }
internalUiState.update { it.copy(userPrompt = null) }
}
private fun uninstallStickerPacks(packIds: Set<StickerPackId>) {
val packsToUninstall = _uiState.value.installedPacks.filter { packIds.contains(it.id) }
val packsToUninstall = internalUiState.value.installedPacks.filter { packIds.contains(it.id) }
viewModelScope.launch {
StickerManagementRepository.uninstallStickerPacks(packsToUninstall.associate { it.id to it.key })
_uiState.update { previousState ->
previousState.copy(
internalUiState.update {
it.copy(
actionConfirmation = if (packsToUninstall.size == 1) {
StickerManagementConfirmation.UninstalledPack(packsToUninstall.single().record.title)
} else {
StickerManagementConfirmation.UninstalledPacks(packsToUninstall.size)
},
selectedPackIds = previousState.selectedPackIds.minus(packIds)
selectedPackIds = it.selectedPackIds.minus(packIds)
)
}
}
}
fun updatePosition(fromIndex: Int, toIndex: Int) {
_uiState.update { it.copy(installedPacks = _uiState.value.installedPacks.swap(fromIndex, toIndex)) }
internalUiState.update { it.copy(installedPacks = internalUiState.value.installedPacks.swap(fromIndex, toIndex)) }
}
fun saveInstalledPacksSortOrder() {
viewModelScope.launch {
StickerManagementRepository.setStickerPacksOrder(_uiState.value.installedPacks.map { it.record })
StickerManagementRepository.setStickerPacksOrder(internalUiState.value.installedPacks.map { it.record })
}
}
fun toggleSelection(pack: InstalledStickerPack) {
_uiState.update { previousState ->
val wasItemSelected = previousState.selectedPackIds.contains(pack.id)
val selectedPackIds = if (wasItemSelected) previousState.selectedPackIds.minus(pack.id) else previousState.selectedPackIds.plus(pack.id)
internalUiState.update {
val wasItemSelected = it.selectedPackIds.contains(pack.id)
val selectedPackIds = if (wasItemSelected) it.selectedPackIds.minus(pack.id) else it.selectedPackIds.plus(pack.id)
previousState.copy(
it.copy(
multiSelectEnabled = selectedPackIds.isNotEmpty(),
selectedPackIds = selectedPackIds
)
@@ -171,21 +167,21 @@ class StickerManagementViewModel : ViewModel() {
}
fun toggleSelectAll() {
_uiState.update { previousState ->
previousState.copy(
internalUiState.update {
it.copy(
multiSelectEnabled = true,
selectedPackIds = if (previousState.selectedPackIds.size == previousState.installedPacks.size) {
selectedPackIds = if (it.selectedPackIds.size == it.installedPacks.size) {
emptySet()
} else {
previousState.installedPacks.map { it.id }.toSet()
it.installedPacks.map { pack -> pack.id }.toSet()
}
)
}
}
fun setMultiSelectEnabled(isEnabled: Boolean) {
_uiState.update { previousState ->
previousState.copy(
internalUiState.update {
it.copy(
multiSelectEnabled = isEnabled,
selectedPackIds = emptySet()
)
@@ -193,8 +189,8 @@ class StickerManagementViewModel : ViewModel() {
}
fun onSnackbarDismiss() {
_uiState.update { previousState ->
previousState.copy(actionConfirmation = null)
internalUiState.update {
it.copy(actionConfirmation = null)
}
}
}

View File

@@ -24,8 +24,8 @@ class StickerPackPreviewViewModelV2(
params: StickerPackParams?
) : ViewModel() {
private val stickerPreviewRepo: StickerPackPreviewRepository = StickerPackPreviewRepository()
private val _uiState = MutableStateFlow(StickerPackPreviewUiState(contentState = ContentState.Loading))
val uiState: StateFlow<StickerPackPreviewUiState> = _uiState.asStateFlow()
private val internalUiState = MutableStateFlow(StickerPackPreviewUiState(contentState = ContentState.Loading))
val uiState: StateFlow<StickerPackPreviewUiState> = internalUiState.asStateFlow()
init {
if (params != null) {
@@ -39,11 +39,11 @@ class StickerPackPreviewViewModelV2(
stickerPreviewRepo.getStickerManifest(params.id.value, params.key.value) { result ->
val stickerManifest = result.map { it.manifest }.orNull()
if (stickerManifest != null) {
_uiState.update { previousState ->
previousState.copy(
internalUiState.update {
it.copy(
contentState = ContentState.HasData(
stickerManifest = stickerManifest,
isPackInstalled = result.map { it.isInstalled }.getOrElse { false }
isPackInstalled = result.map { pack -> pack.isInstalled }.getOrElse { false }
)
)
}
@@ -68,12 +68,12 @@ class StickerPackPreviewViewModelV2(
}
private fun updateInstalledState(isInstalled: Boolean) {
_uiState.update { previousState ->
previousState.copy(
contentState = if (previousState.contentState is ContentState.HasData) {
previousState.contentState.copy(isPackInstalled = isInstalled)
internalUiState.update {
it.copy(
contentState = if (it.contentState is ContentState.HasData) {
it.contentState.copy(isPackInstalled = isInstalled)
} else {
previousState.contentState
it.contentState
},
navTarget = StickerPackPreviewUiState.NavTarget.Up(delay = 500.milliseconds)
)
@@ -81,8 +81,8 @@ class StickerPackPreviewViewModelV2(
}
private fun showDataUnavailableState() {
_uiState.update { previousState ->
previousState.copy(
internalUiState.update {
it.copy(
contentState = ContentState.DataUnavailable,
userMessage = StickerPackPreviewUiState.MessageType.STICKER_PACK_LOAD_FAILED,
navTarget = StickerPackPreviewUiState.NavTarget.Up(delay = 1.seconds)
@@ -91,11 +91,11 @@ class StickerPackPreviewViewModelV2(
}
fun setNavTargetConsumed() {
_uiState.update { previousState -> previousState.copy(navTarget = null) }
internalUiState.update { it.copy(navTarget = null) }
}
fun setUserMessageConsumed() {
_uiState.update { previousState -> previousState.copy(userMessage = null) }
internalUiState.update { it.copy(userMessage = null) }
}
}