Extend logging in RecipientStore

This commit is contained in:
AsamK 2021-12-06 19:18:18 +01:00
parent 8867a7b9ee
commit 9c811ecc02

View file

@ -230,6 +230,7 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
public void deleteRecipientData(final RecipientId recipientId) { public void deleteRecipientData(final RecipientId recipientId) {
synchronized (recipients) { synchronized (recipients) {
logger.debug("Deleting recipient data for {}", recipientId);
final var recipient = recipients.get(recipientId); final var recipient = recipients.get(recipientId);
storeRecipientLocked(recipientId, storeRecipientLocked(recipientId,
Recipient.newBuilder() Recipient.newBuilder()
@ -342,45 +343,57 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
} }
if (byNumber.isEmpty()) { if (byNumber.isEmpty()) {
logger.debug("Got recipient existing with uuid, updating with high trust number"); logger.debug("Got recipient {} existing with uuid, updating with high trust number",
byUuid.get().getRecipientId());
updateRecipientAddressLocked(byUuid.get().getRecipientId(), address); updateRecipientAddressLocked(byUuid.get().getRecipientId(), address);
return new Pair<>(byUuid.get().getRecipientId(), Optional.empty()); return new Pair<>(byUuid.get().getRecipientId(), Optional.empty());
} }
if (byUuid.isEmpty()) { final var byNumberRecipient = byNumber.get();
if (byNumber.get().getAddress().uuid().isPresent()) {
logger.debug(
"Got recipient existing with number, but different uuid, so stripping its number and adding new recipient");
updateRecipientAddressLocked(byNumber.get().getRecipientId(), if (byUuid.isEmpty()) {
new RecipientAddress(byNumber.get().getAddress().uuid().get())); if (byNumberRecipient.getAddress().uuid().isPresent()) {
logger.debug(
"Got recipient {} existing with number, but different uuid, so stripping its number and adding new recipient",
byNumberRecipient.getRecipientId());
updateRecipientAddressLocked(byNumberRecipient.getRecipientId(),
new RecipientAddress(byNumberRecipient.getAddress().uuid().get()));
return new Pair<>(addNewRecipientLocked(address), Optional.empty()); return new Pair<>(addNewRecipientLocked(address), Optional.empty());
} }
logger.debug("Got recipient existing with number and no uuid, updating with high trust uuid"); logger.debug("Got recipient {} existing with number and no uuid, updating with high trust uuid",
updateRecipientAddressLocked(byNumber.get().getRecipientId(), address); byNumberRecipient.getRecipientId());
return new Pair<>(byNumber.get().getRecipientId(), Optional.empty()); updateRecipientAddressLocked(byNumberRecipient.getRecipientId(), address);
return new Pair<>(byNumberRecipient.getRecipientId(), Optional.empty());
} }
if (byNumber.get().getAddress().uuid().isPresent()) { final var byUuidRecipient = byUuid.get();
if (byNumberRecipient.getAddress().uuid().isPresent()) {
logger.debug( logger.debug(
"Got separate recipients for high trust number and uuid, recipient for number has different uuid, so stripping its number"); "Got separate recipients for high trust number {} and uuid {}, recipient for number has different uuid, so stripping its number",
byNumberRecipient.getRecipientId(),
byUuidRecipient.getRecipientId());
updateRecipientAddressLocked(byNumber.get().getRecipientId(), updateRecipientAddressLocked(byNumberRecipient.getRecipientId(),
new RecipientAddress(byNumber.get().getAddress().uuid().get())); new RecipientAddress(byNumberRecipient.getAddress().uuid().get()));
updateRecipientAddressLocked(byUuid.get().getRecipientId(), address); updateRecipientAddressLocked(byUuidRecipient.getRecipientId(), address);
return new Pair<>(byUuid.get().getRecipientId(), Optional.empty()); return new Pair<>(byUuidRecipient.getRecipientId(), Optional.empty());
} }
logger.debug("Got separate recipients for high trust number and uuid, need to merge them"); logger.debug("Got separate recipients for high trust number {} and uuid {}, need to merge them",
updateRecipientAddressLocked(byUuid.get().getRecipientId(), address); byNumberRecipient.getRecipientId(),
mergeRecipientsLocked(byUuid.get().getRecipientId(), byNumber.get().getRecipientId()); byUuidRecipient.getRecipientId());
recipientsMerged.put(byNumber.get().getRecipientId(), byUuid.get().getRecipientId()); updateRecipientAddressLocked(byUuidRecipient.getRecipientId(), address);
return new Pair<>(byUuid.get().getRecipientId(), byNumber.map(Recipient::getRecipientId)); mergeRecipientsLocked(byUuidRecipient.getRecipientId(), byNumberRecipient.getRecipientId());
recipientsMerged.put(byNumberRecipient.getRecipientId(), byUuidRecipient.getRecipientId());
return new Pair<>(byUuidRecipient.getRecipientId(), byNumber.map(Recipient::getRecipientId));
} }
private RecipientId addNewRecipientLocked(final RecipientAddress address) { private RecipientId addNewRecipientLocked(final RecipientAddress address) {
final var nextRecipientId = nextIdLocked(); final var nextRecipientId = nextIdLocked();
logger.debug("Adding new recipient {} with address {}", nextRecipientId, address);
storeRecipientLocked(nextRecipientId, new Recipient(nextRecipientId, address, null, null, null, null)); storeRecipientLocked(nextRecipientId, new Recipient(nextRecipientId, address, null, null, null, null));
return nextRecipientId; return nextRecipientId;
} }
@ -394,7 +407,9 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
private Recipient getRecipientLocked(RecipientId recipientId) { private Recipient getRecipientLocked(RecipientId recipientId) {
while (recipientsMerged.containsKey(recipientId)) { while (recipientsMerged.containsKey(recipientId)) {
recipientId = recipientsMerged.get(recipientId); final var newRecipientId = recipientsMerged.get(recipientId);
logger.debug("Using {} instead of {}, because recipients have been merged", newRecipientId, recipientId);
recipientId = newRecipientId;
} }
return recipients.get(recipientId); return recipients.get(recipientId);
} }