Skip to content

Commit

Permalink
Improve final address when merging recipients
Browse files Browse the repository at this point in the history
  • Loading branch information
AsamK committed Jan 14, 2025
1 parent 7a25ae5 commit 9426974
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static Pair<RecipientId, List<RecipientId>> resolveRecipientTrustedLocked(
)
) || 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());
}

Expand Down Expand Up @@ -93,14 +93,14 @@ static Pair<RecipientId, List<RecipientId>> resolveRecipientTrustedLocked(
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ public RecipientAddress(ServiceId serviceId) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9426974

Please sign in to comment.