mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 09:49:30 +01:00
Inline the pnp feature flag.
This commit is contained in:
committed by
Cody Henthorne
parent
8ad77ac7aa
commit
c359ddf3c8
@@ -25,7 +25,6 @@ import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId
|
||||
import org.thoughtcrime.securesms.registration.RegistrationUtil
|
||||
import org.thoughtcrime.securesms.storage.StorageSyncHelper
|
||||
import org.thoughtcrime.securesms.util.FeatureFlags
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||
import org.thoughtcrime.securesms.util.Util
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress
|
||||
@@ -70,7 +69,7 @@ object ContactDiscovery {
|
||||
context = context,
|
||||
descriptor = "refresh-all",
|
||||
refresh = {
|
||||
ContactDiscoveryRefreshV2.refreshAll(context, useCompat = FeatureFlags.cdsCompatMode())
|
||||
ContactDiscoveryRefreshV2.refreshAll(context)
|
||||
},
|
||||
removeSystemContactLinksIfMissing = true,
|
||||
notifyOfNewUsers = notifyOfNewUsers,
|
||||
@@ -87,9 +86,7 @@ object ContactDiscovery {
|
||||
refreshRecipients(
|
||||
context = context,
|
||||
descriptor = "refresh-multiple",
|
||||
refresh = {
|
||||
ContactDiscoveryRefreshV2.refresh(context, recipients, useCompat = FeatureFlags.cdsCompatMode())
|
||||
},
|
||||
refresh = { ContactDiscoveryRefreshV2.refresh(context, recipients) },
|
||||
removeSystemContactLinksIfMissing = false,
|
||||
notifyOfNewUsers = notifyOfNewUsers
|
||||
)
|
||||
@@ -103,9 +100,7 @@ object ContactDiscovery {
|
||||
val result: RefreshResult = refreshRecipients(
|
||||
context = context,
|
||||
descriptor = "refresh-single",
|
||||
refresh = {
|
||||
ContactDiscoveryRefreshV2.refresh(context, listOf(recipient), useCompat = FeatureFlags.cdsCompatMode(), timeoutMs = timeoutMs)
|
||||
},
|
||||
refresh = { ContactDiscoveryRefreshV2.refresh(context, listOf(recipient), timeoutMs = timeoutMs) },
|
||||
removeSystemContactLinksIfMissing = false,
|
||||
notifyOfNewUsers = notifyOfNewUsers
|
||||
)
|
||||
|
||||
@@ -44,7 +44,7 @@ object ContactDiscoveryRefreshV2 {
|
||||
@WorkerThread
|
||||
@Synchronized
|
||||
@JvmStatic
|
||||
fun refreshAll(context: Context, useCompat: Boolean, timeoutMs: Long? = null): ContactDiscovery.RefreshResult {
|
||||
fun refreshAll(context: Context, timeoutMs: Long? = null): ContactDiscovery.RefreshResult {
|
||||
val recipientE164s: Set<String> = SignalDatabase.recipients.getAllE164s().sanitize()
|
||||
val systemE164s: Set<String> = SystemContactsRepository.getAllDisplayNumbers(context).toE164s(context).sanitize()
|
||||
|
||||
@@ -53,7 +53,6 @@ object ContactDiscoveryRefreshV2 {
|
||||
systemE164s = systemE164s,
|
||||
inputPreviousE164s = SignalDatabase.cds.getAllE164s(),
|
||||
isPartialRefresh = false,
|
||||
useCompat = useCompat,
|
||||
timeoutMs = timeoutMs
|
||||
)
|
||||
}
|
||||
@@ -62,14 +61,14 @@ object ContactDiscoveryRefreshV2 {
|
||||
@WorkerThread
|
||||
@Synchronized
|
||||
@JvmStatic
|
||||
fun refresh(context: Context, inputRecipients: List<Recipient>, useCompat: Boolean, timeoutMs: Long? = null): ContactDiscovery.RefreshResult {
|
||||
fun refresh(context: Context, inputRecipients: List<Recipient>, timeoutMs: Long? = null): ContactDiscovery.RefreshResult {
|
||||
val recipients: List<Recipient> = inputRecipients.map { it.resolve() }
|
||||
val inputE164s: Set<String> = recipients.mapNotNull { it.e164.orElse(null) }.toSet().sanitize()
|
||||
|
||||
return if (inputE164s.size > MAXIMUM_ONE_OFF_REQUEST_SIZE) {
|
||||
Log.i(TAG, "List of specific recipients to refresh is too large! (Size: ${recipients.size}). Doing a full refresh instead.")
|
||||
|
||||
val fullResult: ContactDiscovery.RefreshResult = refreshAll(context, useCompat = useCompat, timeoutMs = timeoutMs)
|
||||
val fullResult: ContactDiscovery.RefreshResult = refreshAll(context, timeoutMs = timeoutMs)
|
||||
val inputIds: Set<RecipientId> = recipients.map { it.id }.toSet()
|
||||
|
||||
ContactDiscovery.RefreshResult(
|
||||
@@ -82,7 +81,6 @@ object ContactDiscoveryRefreshV2 {
|
||||
systemE164s = inputE164s,
|
||||
inputPreviousE164s = emptySet(),
|
||||
isPartialRefresh = true,
|
||||
useCompat = useCompat,
|
||||
timeoutMs = timeoutMs
|
||||
)
|
||||
}
|
||||
@@ -94,10 +92,9 @@ object ContactDiscoveryRefreshV2 {
|
||||
systemE164s: Set<String>,
|
||||
inputPreviousE164s: Set<String>,
|
||||
isPartialRefresh: Boolean,
|
||||
useCompat: Boolean,
|
||||
timeoutMs: Long? = null
|
||||
): ContactDiscovery.RefreshResult {
|
||||
val tag = "refreshInternal-${if (useCompat) "compat" else "v2"}"
|
||||
val tag = "refreshInternal-v2"
|
||||
val stopwatch = Stopwatch(tag)
|
||||
|
||||
val previousE164s: Set<String> = if (SignalStore.misc().cdsToken != null && !isPartialRefresh) inputPreviousE164s else emptySet()
|
||||
@@ -127,7 +124,6 @@ object ContactDiscoveryRefreshV2 {
|
||||
previousE164s,
|
||||
newE164s,
|
||||
SignalDatabase.recipients.getAllServiceIdProfileKeyPairs(),
|
||||
useCompat,
|
||||
Optional.ofNullable(token),
|
||||
BuildConfig.CDSI_MRENCLAVE,
|
||||
timeoutMs
|
||||
@@ -165,10 +161,6 @@ object ContactDiscoveryRefreshV2 {
|
||||
val registeredIds: MutableSet<RecipientId> = mutableSetOf()
|
||||
val rewrites: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
if (useCompat && !response.isCompatResponse()) {
|
||||
Log.w(TAG, "Was told to useCompat, but the server responded with a non-compat response! Assuming the server has shut off compat mode.")
|
||||
}
|
||||
|
||||
val transformed: Map<String, CdsV2Result> = response.results.mapValues { entry -> CdsV2Result(entry.value.pni, entry.value.aci.orElse(null)) }
|
||||
val fuzzyOutput: OutputResult<CdsV2Result> = FuzzyPhoneNumberHelper.generateOutput(transformed, fuzzyInput)
|
||||
|
||||
@@ -238,13 +230,4 @@ object ContactDiscoveryRefreshV2 {
|
||||
val nearestThousand = (this.toDouble() / 1000).roundToInt()
|
||||
return "~${nearestThousand}k"
|
||||
}
|
||||
|
||||
/**
|
||||
* Responses that respect useCompat will have an ACI for every user. If it doesn't, it means is a PNP response where some accounts may only have PNI's.
|
||||
* There may come a day when we request compat mode but the server refuses to allow it, so we need to be able to detect when that happens to fallback
|
||||
* to the PNP behavior.
|
||||
*/
|
||||
private fun CdsiV2Service.Response.isCompatResponse(): Boolean {
|
||||
return this.results.values.all { it.hasAci() }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user