mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 13:08:46 +00:00
Fix pnp settings not properly syncing or dynamically updating.
This commit is contained in:
committed by
Michelle Tang
parent
e2bffd0fd3
commit
5d8e0e370d
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user