Inline the RecipientMergeV2 flag.

This commit is contained in:
Greyson Parrelli
2022-10-18 12:32:49 -04:00
committed by Alex Hart
parent 367ff7c75c
commit 62d5777c39
5 changed files with 44 additions and 812 deletions

View File

@@ -435,110 +435,8 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
@JvmOverloads
fun getAndPossiblyMerge(serviceId: ServiceId?, e164: String?, changeSelf: Boolean = false): RecipientId {
return if (FeatureFlags.recipientMergeV2() || FeatureFlags.phoneNumberPrivacy()) {
getAndPossiblyMergePnp(serviceId, e164, changeSelf)
} else {
getAndPossiblyMergeLegacy(serviceId, e164, changeSelf)
}
}
@VisibleForTesting
fun getAndPossiblyMergeLegacy(serviceId: ServiceId?, e164: String?, changeSelf: Boolean = false): RecipientId {
require(!(serviceId == null && e164 == null)) { "Must provide an ACI or E164!" }
val db = writableDatabase
var transactionSuccessful = false
var remapped: Pair<RecipientId, RecipientId>? = null
var recipientsNeedingRefresh: List<RecipientId> = listOf()
var recipientChangedNumber: RecipientId? = null
db.beginTransaction()
try {
val fetch: RecipientFetch = fetchRecipient(serviceId, e164, changeSelf = changeSelf)
if (fetch.logBundle != null) {
Log.w(TAG, fetch.toString())
}
val resolvedId: RecipientId = when (fetch) {
is RecipientFetch.Match -> {
fetch.id
}
is RecipientFetch.MatchAndUpdateE164 -> {
setPhoneNumberOrThrowSilent(fetch.id, fetch.e164)
recipientsNeedingRefresh = listOf(fetch.id)
recipientChangedNumber = fetch.changedNumber
fetch.id
}
is RecipientFetch.MatchAndReassignE164 -> {
removePhoneNumber(fetch.e164Id)
setPhoneNumberOrThrowSilent(fetch.id, fetch.e164)
recipientsNeedingRefresh = listOf(fetch.id, fetch.e164Id)
recipientChangedNumber = fetch.changedNumber
fetch.id
}
is RecipientFetch.MatchAndUpdateAci -> {
markRegistered(fetch.id, fetch.serviceId)
recipientsNeedingRefresh = listOf(fetch.id)
fetch.id
}
is RecipientFetch.MatchAndInsertAci -> {
val id = db.insert(TABLE_NAME, null, buildContentValuesForNewUser(null, fetch.serviceId))
RecipientId.from(id)
}
is RecipientFetch.MatchAndMerge -> {
remapped = Pair(fetch.e164Id, fetch.sidId)
val mergedId: RecipientId = merge(fetch.sidId, fetch.e164Id)
recipientsNeedingRefresh = listOf(mergedId)
recipientChangedNumber = fetch.changedNumber
mergedId
}
is RecipientFetch.Insert -> {
val id = db.insert(TABLE_NAME, null, buildContentValuesForNewUser(fetch.e164, fetch.serviceId))
RecipientId.from(id)
}
is RecipientFetch.InsertAndReassignE164 -> {
removePhoneNumber(fetch.e164Id)
recipientsNeedingRefresh = listOf(fetch.e164Id)
val id = db.insert(TABLE_NAME, null, buildContentValuesForNewUser(fetch.e164, fetch.serviceId))
RecipientId.from(id)
}
}
transactionSuccessful = true
db.setTransactionSuccessful()
return resolvedId
} finally {
db.endTransaction()
if (transactionSuccessful) {
if (recipientsNeedingRefresh.isNotEmpty()) {
recipientsNeedingRefresh.forEach { ApplicationDependencies.getDatabaseObserver().notifyRecipientChanged(it) }
RetrieveProfileJob.enqueue(recipientsNeedingRefresh.toSet())
}
if (remapped != null) {
Recipient.live(remapped.first).refresh(remapped.second)
ApplicationDependencies.getRecipientCache().remap(remapped.first, remapped.second)
}
if (recipientsNeedingRefresh.isNotEmpty() || remapped != null) {
StorageSyncHelper.scheduleSyncForDataChange()
RecipientId.clearCache()
}
if (recipientChangedNumber != null) {
ApplicationDependencies.getJobManager().add(RecipientChangedNumberJob(recipientChangedNumber))
}
}
}
}
@VisibleForTesting
fun getAndPossiblyMergePnp(serviceId: ServiceId?, e164: String?, changeSelf: Boolean = false): RecipientId {
require(!(serviceId == null && e164 == null)) { "Must provide an ACI or E164!" }
return getAndPossiblyMergePnp(serviceId = serviceId, pni = null, e164 = e164, pniVerified = false, changeSelf = changeSelf)
return getAndPossiblyMerge(serviceId = serviceId, pni = null, e164 = e164, pniVerified = false, changeSelf = changeSelf)
}
/**
@@ -550,10 +448,10 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
throw AssertionError()
}
return getAndPossiblyMergePnp(serviceId = serviceId, pni = pni, e164 = e164, pniVerified = true, changeSelf = false)
return getAndPossiblyMerge(serviceId = serviceId, pni = pni, e164 = e164, pniVerified = true, changeSelf = false)
}
private fun getAndPossiblyMergePnp(serviceId: ServiceId?, pni: PNI?, e164: String?, pniVerified: Boolean = false, changeSelf: Boolean = false): RecipientId {
private fun getAndPossiblyMerge(serviceId: ServiceId?, pni: PNI?, e164: String?, pniVerified: Boolean = false, changeSelf: Boolean = false): RecipientId {
require(!(serviceId == null && e164 == null)) { "Must provide an ACI or E164!" }
if ((serviceId is PNI) && pni != null && serviceId != pni) {
@@ -2135,7 +2033,7 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
* Associates the provided IDs together. The assumption here is that all of the IDs correspond to the local user and have been verified.
*/
fun linkIdsForSelf(aci: ACI, pni: PNI, e164: String) {
getAndPossiblyMergePnp(serviceId = aci, pni = pni, e164 = e164, changeSelf = true, pniVerified = true)
getAndPossiblyMerge(serviceId = aci, pni = pni, e164 = e164, changeSelf = true, pniVerified = true)
}
/**
@@ -2147,7 +2045,7 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
db.beginTransaction()
try {
val id = Recipient.self().id
val newId = getAndPossiblyMergePnp(serviceId = SignalStore.account().requireAci(), pni = pni, e164 = e164, pniVerified = true, changeSelf = true)
val newId = getAndPossiblyMerge(serviceId = SignalStore.account().requireAci(), pni = pni, e164 = e164, pniVerified = true, changeSelf = true)
if (id == newId) {
Log.i(TAG, "[updateSelfPhone] Phone updated for self")

View File

@@ -114,6 +114,8 @@ public final class PushDecryptMessageJob extends BaseJob {
if (FeatureFlags.phoneNumberPrivacy() && result.getContent().getPniSignatureMessage().isPresent()) {
handlePniSignatureMessage(result.getContent().getSender(), result.getContent().getSenderDevice(), result.getContent().getPniSignatureMessage().get());
} else if (result.getContent().getPniSignatureMessage().isPresent()) {
Log.w(TAG, "Ignoring PNI signature because the feature flag is disabled!");
}
jobs.add(new PushProcessMessageJob(result.getContent(), smsMessageId, envelope.getTimestamp()));

View File

@@ -537,13 +537,6 @@ public final class FeatureFlags {
return giftBadgeReceiveSupport() && getBoolean(GIFT_BADGE_SEND_SUPPORT, Environment.IS_STAGING);
}
/**
* Whether or not we should use the new recipient merging strategy.
*/
public static boolean recipientMergeV2() {
return getBoolean(RECIPIENT_MERGE_V2, false);
}
/**
* Whether or not we should enable the SMS exporter
*