mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Always use correct recipientId after recipients were merged
This commit is contained in:
parent
9c811ecc02
commit
bbe74ef020
1 changed files with 22 additions and 20 deletions
|
@ -130,7 +130,8 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
|
||||||
|
|
||||||
public Recipient getRecipient(RecipientId recipientId) {
|
public Recipient getRecipient(RecipientId recipientId) {
|
||||||
synchronized (recipients) {
|
synchronized (recipients) {
|
||||||
return getRecipientLocked(recipientId);
|
recipientId = getActualRecipientId(recipientId);
|
||||||
|
return recipients.get(recipientId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,15 +199,16 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void storeContact(final RecipientId recipientId, final Contact contact) {
|
public void storeContact(RecipientId recipientId, final Contact contact) {
|
||||||
synchronized (recipients) {
|
synchronized (recipients) {
|
||||||
|
recipientId = getActualRecipientId(recipientId);
|
||||||
final var recipient = recipients.get(recipientId);
|
final var recipient = recipients.get(recipientId);
|
||||||
storeRecipientLocked(recipientId, Recipient.newBuilder(recipient).withContact(contact).build());
|
storeRecipientLocked(recipientId, Recipient.newBuilder(recipient).withContact(contact).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Contact getContact(final RecipientId recipientId) {
|
public Contact getContact(RecipientId recipientId) {
|
||||||
final var recipient = getRecipient(recipientId);
|
final var recipient = getRecipient(recipientId);
|
||||||
return recipient == null ? null : recipient.getContact();
|
return recipient == null ? null : recipient.getContact();
|
||||||
}
|
}
|
||||||
|
@ -221,15 +223,17 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteContact(final RecipientId recipientId) {
|
public void deleteContact(RecipientId recipientId) {
|
||||||
synchronized (recipients) {
|
synchronized (recipients) {
|
||||||
|
recipientId = getActualRecipientId(recipientId);
|
||||||
final var recipient = recipients.get(recipientId);
|
final var recipient = recipients.get(recipientId);
|
||||||
storeRecipientLocked(recipientId, Recipient.newBuilder(recipient).withContact(null).build());
|
storeRecipientLocked(recipientId, Recipient.newBuilder(recipient).withContact(null).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteRecipientData(final RecipientId recipientId) {
|
public void deleteRecipientData(RecipientId recipientId) {
|
||||||
synchronized (recipients) {
|
synchronized (recipients) {
|
||||||
|
recipientId = getActualRecipientId(recipientId);
|
||||||
logger.debug("Deleting recipient data for {}", recipientId);
|
logger.debug("Deleting recipient data for {}", recipientId);
|
||||||
final var recipient = recipients.get(recipientId);
|
final var recipient = recipients.get(recipientId);
|
||||||
storeRecipientLocked(recipientId,
|
storeRecipientLocked(recipientId,
|
||||||
|
@ -259,16 +263,18 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void storeProfile(final RecipientId recipientId, final Profile profile) {
|
public void storeProfile(RecipientId recipientId, final Profile profile) {
|
||||||
synchronized (recipients) {
|
synchronized (recipients) {
|
||||||
|
recipientId = getActualRecipientId(recipientId);
|
||||||
final var recipient = recipients.get(recipientId);
|
final var recipient = recipients.get(recipientId);
|
||||||
storeRecipientLocked(recipientId, Recipient.newBuilder(recipient).withProfile(profile).build());
|
storeRecipientLocked(recipientId, Recipient.newBuilder(recipient).withProfile(profile).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void storeProfileKey(final RecipientId recipientId, final ProfileKey profileKey) {
|
public void storeProfileKey(RecipientId recipientId, final ProfileKey profileKey) {
|
||||||
synchronized (recipients) {
|
synchronized (recipients) {
|
||||||
|
recipientId = getActualRecipientId(recipientId);
|
||||||
final var recipient = recipients.get(recipientId);
|
final var recipient = recipients.get(recipientId);
|
||||||
if (profileKey != null && profileKey.equals(recipient.getProfileKey())) {
|
if (profileKey != null && profileKey.equals(recipient.getProfileKey())) {
|
||||||
return;
|
return;
|
||||||
|
@ -286,10 +292,9 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void storeProfileKeyCredential(
|
public void storeProfileKeyCredential(RecipientId recipientId, final ProfileKeyCredential profileKeyCredential) {
|
||||||
final RecipientId recipientId, final ProfileKeyCredential profileKeyCredential
|
|
||||||
) {
|
|
||||||
synchronized (recipients) {
|
synchronized (recipients) {
|
||||||
|
recipientId = getActualRecipientId(recipientId);
|
||||||
final var recipient = recipients.get(recipientId);
|
final var recipient = recipients.get(recipientId);
|
||||||
storeRecipientLocked(recipientId,
|
storeRecipientLocked(recipientId,
|
||||||
Recipient.newBuilder(recipient).withProfileKeyCredential(profileKeyCredential).build());
|
Recipient.newBuilder(recipient).withProfileKeyCredential(profileKeyCredential).build());
|
||||||
|
@ -387,7 +392,6 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
|
||||||
byUuidRecipient.getRecipientId());
|
byUuidRecipient.getRecipientId());
|
||||||
updateRecipientAddressLocked(byUuidRecipient.getRecipientId(), address);
|
updateRecipientAddressLocked(byUuidRecipient.getRecipientId(), address);
|
||||||
mergeRecipientsLocked(byUuidRecipient.getRecipientId(), byNumberRecipient.getRecipientId());
|
mergeRecipientsLocked(byUuidRecipient.getRecipientId(), byNumberRecipient.getRecipientId());
|
||||||
recipientsMerged.put(byNumberRecipient.getRecipientId(), byUuidRecipient.getRecipientId());
|
|
||||||
return new Pair<>(byUuidRecipient.getRecipientId(), byNumber.map(Recipient::getRecipientId));
|
return new Pair<>(byUuidRecipient.getRecipientId(), byNumber.map(Recipient::getRecipientId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,26 +402,23 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
|
||||||
return nextRecipientId;
|
return nextRecipientId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateRecipientAddressLocked(
|
private void updateRecipientAddressLocked(RecipientId recipientId, final RecipientAddress address) {
|
||||||
final RecipientId recipientId, final RecipientAddress address
|
recipientId = getActualRecipientId(recipientId);
|
||||||
) {
|
|
||||||
final var recipient = recipients.get(recipientId);
|
final var recipient = recipients.get(recipientId);
|
||||||
storeRecipientLocked(recipientId, Recipient.newBuilder(recipient).withAddress(address).build());
|
storeRecipientLocked(recipientId, Recipient.newBuilder(recipient).withAddress(address).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Recipient getRecipientLocked(RecipientId recipientId) {
|
private RecipientId getActualRecipientId(RecipientId recipientId) {
|
||||||
while (recipientsMerged.containsKey(recipientId)) {
|
while (recipientsMerged.containsKey(recipientId)) {
|
||||||
final var newRecipientId = recipientsMerged.get(recipientId);
|
final var newRecipientId = recipientsMerged.get(recipientId);
|
||||||
logger.debug("Using {} instead of {}, because recipients have been merged", newRecipientId, recipientId);
|
logger.debug("Using {} instead of {}, because recipients have been merged", newRecipientId, recipientId);
|
||||||
recipientId = newRecipientId;
|
recipientId = newRecipientId;
|
||||||
}
|
}
|
||||||
return recipients.get(recipientId);
|
return recipientId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void storeRecipientLocked(
|
private void storeRecipientLocked(final RecipientId recipientId, final Recipient recipient) {
|
||||||
final RecipientId recipientId, final Recipient recipient
|
final var existingRecipient = recipients.get(recipientId);
|
||||||
) {
|
|
||||||
final var existingRecipient = getRecipientLocked(recipientId);
|
|
||||||
if (existingRecipient == null || !existingRecipient.equals(recipient)) {
|
if (existingRecipient == null || !existingRecipient.equals(recipient)) {
|
||||||
recipients.put(recipientId, recipient);
|
recipients.put(recipientId, recipient);
|
||||||
saveLocked();
|
saveLocked();
|
||||||
|
@ -439,6 +440,7 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
|
||||||
: toBeMergedRecipient.getProfileKeyCredential(),
|
: toBeMergedRecipient.getProfileKeyCredential(),
|
||||||
recipient.getProfile() != null ? recipient.getProfile() : toBeMergedRecipient.getProfile()));
|
recipient.getProfile() != null ? recipient.getProfile() : toBeMergedRecipient.getProfile()));
|
||||||
recipients.remove(toBeMergedRecipientId);
|
recipients.remove(toBeMergedRecipientId);
|
||||||
|
recipientsMerged.put(toBeMergedRecipientId, recipientId);
|
||||||
saveLocked();
|
saveLocked();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue