kopia lustrzana https://github.com/ryukoposting/Signal-Android
Add support for the changeSelf param in getAndPossiblyMergePnp.
rodzic
0e7cffedc9
commit
d0420ba51d
|
@ -350,7 +350,6 @@ class RecipientDatabaseTest_getAndPossiblyMergePnp {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This is a case where normally we'd update the E164 of a user, but here the changeSelf flag is disabled, so we shouldn't. */
|
/** This is a case where normally we'd update the E164 of a user, but here the changeSelf flag is disabled, so we shouldn't. */
|
||||||
@Ignore("Change self isn't implemented yet!")
|
|
||||||
@Test
|
@Test
|
||||||
fun getAndPossiblyMerge_aciMapsToExistingUserButE164DoesNot_aciBelongsToLocalUser_changeSelfFalse() {
|
fun getAndPossiblyMerge_aciMapsToExistingUserButE164DoesNot_aciBelongsToLocalUser_changeSelfFalse() {
|
||||||
val dataSet = KeyValueDataSet().apply {
|
val dataSet = KeyValueDataSet().apply {
|
||||||
|
|
|
@ -527,11 +527,11 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||||
|
|
||||||
return writableDatabase.withinTransaction {
|
return writableDatabase.withinTransaction {
|
||||||
when {
|
when {
|
||||||
serviceId is PNI -> processPnpTuple(e164, serviceId, null, pniVerified = false)
|
serviceId is PNI -> processPnpTuple(e164, serviceId, null, pniVerified = false, changeSelf = changeSelf)
|
||||||
serviceId is ACI -> processPnpTuple(e164, null, serviceId, pniVerified = false)
|
serviceId is ACI -> processPnpTuple(e164, null, serviceId, pniVerified = false, changeSelf = changeSelf)
|
||||||
serviceId == null -> processPnpTuple(e164, null, null, pniVerified = false)
|
serviceId == null -> processPnpTuple(e164, null, null, pniVerified = false, changeSelf = changeSelf)
|
||||||
getByPni(PNI.from(serviceId.uuid())).isPresent -> processPnpTuple(e164, PNI.from(serviceId.uuid()), null, pniVerified = false)
|
getByPni(PNI.from(serviceId.uuid())).isPresent -> processPnpTuple(e164, PNI.from(serviceId.uuid()), null, pniVerified = false, changeSelf = changeSelf)
|
||||||
else -> processPnpTuple(e164, null, ACI.fromNullable(serviceId), pniVerified = false)
|
else -> processPnpTuple(e164, null, ACI.fromNullable(serviceId), pniVerified = false, changeSelf = changeSelf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2201,8 +2201,8 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||||
* @return The [RecipientId] of the resulting recipient.
|
* @return The [RecipientId] of the resulting recipient.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
fun processPnpTuple(e164: String?, pni: PNI?, aci: ACI?, pniVerified: Boolean): RecipientId {
|
fun processPnpTuple(e164: String?, pni: PNI?, aci: ACI?, pniVerified: Boolean, changeSelf: Boolean = false): RecipientId {
|
||||||
val changeSet = processPnpTupleToChangeSet(e164, pni, aci, pniVerified)
|
val changeSet = processPnpTupleToChangeSet(e164, pni, aci, pniVerified, changeSelf)
|
||||||
return writePnpChangeSetToDisk(changeSet)
|
return writePnpChangeSetToDisk(changeSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2326,7 +2326,7 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||||
* It is assumed that we are in a transaction.
|
* It is assumed that we are in a transaction.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
fun processPnpTupleToChangeSet(e164: String?, pni: PNI?, aci: ACI?, pniVerified: Boolean): PnpChangeSet {
|
fun processPnpTupleToChangeSet(e164: String?, pni: PNI?, aci: ACI?, pniVerified: Boolean, changeSelf: Boolean = false): PnpChangeSet {
|
||||||
Preconditions.checkArgument(e164 != null || pni != null || aci != null, "Must provide at least one field!")
|
Preconditions.checkArgument(e164 != null || pni != null || aci != null, "Must provide at least one field!")
|
||||||
Preconditions.checkArgument(pni == null || e164 != null, "If a PNI is provided, you must also provide an E164!")
|
Preconditions.checkArgument(pni == null || e164 != null, "If a PNI is provided, you must also provide an E164!")
|
||||||
|
|
||||||
|
@ -2374,11 +2374,13 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e164 != null && record.e164 != e164) {
|
var updatedNumber = false
|
||||||
|
if (e164 != null && record.e164 != e164 && (changeSelf || aci != SignalStore.account().aci)) {
|
||||||
operations += PnpOperation.SetE164(
|
operations += PnpOperation.SetE164(
|
||||||
recipientId = partialData.commonId,
|
recipientId = partialData.commonId,
|
||||||
e164 = e164
|
e164 = e164
|
||||||
)
|
)
|
||||||
|
updatedNumber = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pni != null && record.pni != pni) {
|
if (pni != null && record.pni != pni) {
|
||||||
|
@ -2395,11 +2397,11 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e164 != null && record.e164 != null && record.e164 != e164) {
|
if (record.e164 != null && updatedNumber) {
|
||||||
operations += PnpOperation.ChangeNumberInsert(
|
operations += PnpOperation.ChangeNumberInsert(
|
||||||
recipientId = partialData.commonId,
|
recipientId = partialData.commonId,
|
||||||
oldE164 = record.e164,
|
oldE164 = record.e164,
|
||||||
newE164 = e164
|
newE164 = e164!!
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2460,7 +2462,7 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (finalData.byE164 == null && e164 != null) {
|
if (finalData.byE164 == null && e164 != null && (changeSelf || aci != SignalStore.account().aci)) {
|
||||||
operations += PnpOperation.SetE164(
|
operations += PnpOperation.SetE164(
|
||||||
recipientId = primaryId,
|
recipientId = primaryId,
|
||||||
e164 = e164
|
e164 = e164
|
||||||
|
|
Ładowanie…
Reference in New Issue