mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Improve final address when merging recipients
This commit is contained in:
parent
7a25ae5b9c
commit
94269744ad
3 changed files with 20 additions and 18 deletions
|
@ -39,7 +39,7 @@ public class MergeRecipientHelper {
|
|||
)
|
||||
) || recipient.address().aci().equals(address.aci())) {
|
||||
logger.debug("Got existing recipient {}, updating with high trust address", recipient.id());
|
||||
store.updateRecipientAddress(recipient.id(), recipient.address().withIdentifiersFrom(address));
|
||||
store.updateRecipientAddress(recipient.id(), address.withOtherIdentifiersFrom(recipient.address()));
|
||||
return new Pair<>(recipient.id(), List.of());
|
||||
}
|
||||
|
||||
|
@ -93,14 +93,14 @@ public class MergeRecipientHelper {
|
|||
if (finalAddress == null) {
|
||||
finalAddress = recipient.address();
|
||||
} else {
|
||||
finalAddress = finalAddress.withIdentifiersFrom(recipient.address());
|
||||
finalAddress = finalAddress.withOtherIdentifiersFrom(recipient.address());
|
||||
}
|
||||
store.removeRecipientAddress(recipient.id());
|
||||
}
|
||||
if (finalAddress == null) {
|
||||
finalAddress = address;
|
||||
} else {
|
||||
finalAddress = finalAddress.withIdentifiersFrom(address);
|
||||
finalAddress = address.withOtherIdentifiersFrom(finalAddress);
|
||||
}
|
||||
|
||||
for (final var recipient : recipientsToBeStripped) {
|
||||
|
|
|
@ -79,11 +79,11 @@ public record RecipientAddress(
|
|||
this(Optional.of(serviceId), Optional.empty());
|
||||
}
|
||||
|
||||
public RecipientAddress withIdentifiersFrom(RecipientAddress address) {
|
||||
return new RecipientAddress(address.aci.or(this::aci),
|
||||
address.pni.or(this::pni),
|
||||
address.number.or(this::number),
|
||||
address.username.or(this::username));
|
||||
public RecipientAddress withOtherIdentifiersFrom(RecipientAddress address) {
|
||||
return new RecipientAddress(this.aci.or(address::aci),
|
||||
this.pni.or(address::pni),
|
||||
this.number.or(address::number),
|
||||
this.username.or(address::username));
|
||||
}
|
||||
|
||||
public RecipientAddress removeIdentifiersFrom(RecipientAddress address) {
|
||||
|
|
|
@ -111,18 +111,20 @@ class MergeRecipientHelperTest {
|
|||
new T(Set.of(rec(1, ADDR_A.ACI), rec(2, ADDR_A.PNI), rec(3, ADDR_A.NUM)),
|
||||
ADDR_A.FULL,
|
||||
Set.of(rec(1, ADDR_A.FULL))),
|
||||
new T(Set.of(rec(1, ADDR_A.ACI.withIdentifiersFrom(ADDR_B.PNI)), rec(2, ADDR_A.PNI), rec(3, ADDR_A.NUM)),
|
||||
ADDR_A.FULL,
|
||||
Set.of(rec(1, ADDR_A.FULL))),
|
||||
new T(Set.of(rec(1, ADDR_A.ACI.withIdentifiersFrom(ADDR_B.NUM)), rec(2, ADDR_A.PNI), rec(3, ADDR_A.NUM)),
|
||||
ADDR_A.FULL,
|
||||
Set.of(rec(1, ADDR_A.FULL))),
|
||||
new T(Set.of(rec(1, ADDR_A.ACI), rec(2, ADDR_A.PNI), rec(3, ADDR_A.NUM.withIdentifiersFrom(ADDR_B.ACI))),
|
||||
new T(Set.of(rec(1, ADDR_B.PNI.withOtherIdentifiersFrom(ADDR_A.ACI)),
|
||||
rec(2, ADDR_A.PNI),
|
||||
rec(3, ADDR_A.NUM)), ADDR_A.FULL, Set.of(rec(1, ADDR_A.FULL))),
|
||||
new T(Set.of(rec(1, ADDR_B.NUM.withOtherIdentifiersFrom(ADDR_A.ACI)),
|
||||
rec(2, ADDR_A.PNI),
|
||||
rec(3, ADDR_A.NUM)), ADDR_A.FULL, Set.of(rec(1, ADDR_A.FULL))),
|
||||
new T(Set.of(rec(1, ADDR_A.ACI),
|
||||
rec(2, ADDR_A.PNI),
|
||||
rec(3, ADDR_B.ACI.withOtherIdentifiersFrom(ADDR_A.NUM))),
|
||||
ADDR_A.FULL,
|
||||
Set.of(rec(1, ADDR_A.FULL), rec(3, ADDR_B.ACI))),
|
||||
new T(Set.of(rec(1, ADDR_A.ACI), rec(2, ADDR_A.PNI.withIdentifiersFrom(ADDR_B.ACI)), rec(3, ADDR_A.NUM)),
|
||||
ADDR_A.FULL,
|
||||
Set.of(rec(1, ADDR_A.FULL), rec(2, ADDR_B.ACI))),
|
||||
new T(Set.of(rec(1, ADDR_A.ACI),
|
||||
rec(2, ADDR_B.ACI.withOtherIdentifiersFrom(ADDR_A.PNI)),
|
||||
rec(3, ADDR_A.NUM)), ADDR_A.FULL, Set.of(rec(1, ADDR_A.FULL), rec(2, ADDR_B.ACI))),
|
||||
};
|
||||
|
||||
@ParameterizedTest
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue