Allow PNI-only contact inserts.

This commit is contained in:
Greyson Parrelli 2023-08-17 09:14:58 -04:00
parent 15204a2c84
commit 74d5faf3fa
3 changed files with 28 additions and 26 deletions

View file

@ -60,25 +60,6 @@ class RecipientTableTest_getAndPossiblyMerge {
FeatureFlagsAccessor.forceValue(FeatureFlags.PHONE_NUMBER_PRIVACY, true)
}
@Test
fun single() {
test("local user, local e164+aci provided, changeSelf=false, leave pni alone") {
given(E164_SELF, PNI_SELF, ACI_SELF)
process(E164_SELF, PNI_A, ACI_A)
expect(E164_SELF, PNI_SELF, ACI_SELF)
}
test("local user, local e164+aci provided, changeSelf=false, leave pni alone") {
given(E164_SELF, PNI_A, ACI_SELF)
process(E164_SELF, PNI_SELF, ACI_A)
expect(E164_SELF, PNI_A, ACI_SELF)
}
}
@Test
fun allNonMergeTests() {
test("e164-only insert") {
@ -89,7 +70,7 @@ class RecipientTableTest_getAndPossiblyMerge {
assertEquals(RecipientTable.RegisteredState.UNKNOWN, record.registered)
}
test("pni-only insert", exception = IllegalArgumentException::class.java) {
test("pni-only insert") {
val id = process(null, PNI_A, null)
expect(null, PNI_A, null)
@ -137,9 +118,9 @@ class RecipientTableTest_getAndPossiblyMerge {
expect(E164_A, null, null)
}
test("no match, e164 and pni") {
process(E164_A, PNI_A, null)
expect(E164_A, PNI_A, null)
test("no match, pni-only") {
process(null, PNI_A, null)
expect(null, PNI_A, null)
}
test("no match, aci-only") {
@ -147,6 +128,11 @@ class RecipientTableTest_getAndPossiblyMerge {
expect(null, null, ACI_A)
}
test("no match, e164 and pni") {
process(E164_A, PNI_A, null)
expect(E164_A, PNI_A, null)
}
test("no match, e164 and aci") {
process(E164_A, null, ACI_A)
expect(E164_A, null, ACI_A)
@ -713,6 +699,22 @@ class RecipientTableTest_getAndPossiblyMerge {
process(E164_A, null, ACI_SELF, changeSelf = true)
expect(E164_A, null, ACI_SELF)
}
test("local user, local e164+aci provided, changeSelf=false, leave pni alone") {
given(E164_SELF, PNI_SELF, ACI_SELF)
process(E164_SELF, PNI_A, ACI_A)
expect(E164_SELF, PNI_SELF, ACI_SELF)
}
test("local user, local e164+aci provided, changeSelf=false, leave pni alone") {
given(E164_SELF, PNI_A, ACI_SELF)
process(E164_SELF, PNI_SELF, ACI_A)
expect(E164_SELF, PNI_A, ACI_SELF)
}
}
/**

View file

@ -445,7 +445,7 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
@VisibleForTesting
fun getAndPossiblyMerge(aci: ACI?, pni: PNI?, e164: String?, pniVerified: Boolean = false, changeSelf: Boolean = false): RecipientId {
require(aci != null || e164 != null) { "Must provide an ACI or E164!" }
require(aci != null || pni != null || e164 != null) { "Must provide an ACI, PNI, or E164!" }
val db = writableDatabase
var transactionSuccessful = false

View file

@ -42,8 +42,8 @@ public final class SignalContactRecord implements SignalRecord {
this.id = id;
this.proto = proto;
this.hasUnknownFields = ProtoUtil.hasUnknownFields(proto);
this.aci = OptionalUtil.absentIfEmpty(proto.getAci()).map(ACI::parseOrNull);
this.pni = OptionalUtil.absentIfEmpty(proto.getPni()).map(PNI::parseOrNull);
this.aci = OptionalUtil.absentIfEmpty(proto.getAci()).map(ACI::parseOrNull).map(it -> it.isUnknown() ? null : it);
this.pni = OptionalUtil.absentIfEmpty(proto.getPni()).map(PNI::parseOrNull).map(it -> it.isUnknown() ? null : it);
this.e164 = OptionalUtil.absentIfEmpty(proto.getE164());
this.profileGivenName = OptionalUtil.absentIfEmpty(proto.getGivenName());
this.profileFamilyName = OptionalUtil.absentIfEmpty(proto.getFamilyName());