Fix pnp settings not properly syncing or dynamically updating.

This commit is contained in:
Cody Henthorne
2025-05-13 11:24:45 -04:00
committed by Michelle Tang
parent e2bffd0fd3
commit 5d8e0e370d

View File

@@ -3,6 +3,11 @@ package org.thoughtcrime.securesms.components.settings.app.privacy.pnp
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import org.thoughtcrime.securesms.database.SignalDatabase
import org.thoughtcrime.securesms.dependencies.AppDependencies
import org.thoughtcrime.securesms.jobs.ProfileUploadJob
@@ -13,6 +18,7 @@ import org.thoughtcrime.securesms.keyvalue.PhoneNumberPrivacyValues.PhoneNumberS
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.storage.StorageSyncHelper
import kotlin.time.Duration.Companion.seconds
class PhoneNumberPrivacySettingsViewModel : ViewModel() {
@@ -25,6 +31,15 @@ class PhoneNumberPrivacySettingsViewModel : ViewModel() {
val state: State<PhoneNumberPrivacySettingsState> = _state
init {
viewModelScope.launch(Dispatchers.IO) {
while (isActive) {
refresh()
delay(5.seconds)
}
}
}
fun setNobodyCanSeeMyNumber() {
setPhoneNumberSharingEnabled(false)
}
@@ -52,6 +67,7 @@ class PhoneNumberPrivacySettingsViewModel : ViewModel() {
private fun setDiscoverableByPhoneNumber(discoverable: Boolean) {
SignalStore.phoneNumberPrivacy.phoneNumberDiscoverabilityMode = if (discoverable) PhoneNumberDiscoverabilityMode.DISCOVERABLE else PhoneNumberDiscoverabilityMode.NOT_DISCOVERABLE
SignalDatabase.recipients.markNeedsSync(Recipient.self().id)
StorageSyncHelper.scheduleSyncForDataChange()
AppDependencies.jobManager.startChain(RefreshAttributesJob()).then(RefreshOwnProfileJob()).enqueue()
refresh()