mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Improve import of contact from storage
This commit is contained in:
parent
dcde9fbe8e
commit
457b093dce
1 changed files with 19 additions and 8 deletions
|
@ -6,6 +6,7 @@ import org.asamk.signal.manager.api.TrustLevel;
|
||||||
import org.asamk.signal.manager.groups.GroupId;
|
import org.asamk.signal.manager.groups.GroupId;
|
||||||
import org.asamk.signal.manager.storage.SignalAccount;
|
import org.asamk.signal.manager.storage.SignalAccount;
|
||||||
import org.asamk.signal.manager.storage.recipients.Contact;
|
import org.asamk.signal.manager.storage.recipients.Contact;
|
||||||
|
import org.asamk.signal.manager.storage.recipients.Profile;
|
||||||
import org.signal.libsignal.protocol.IdentityKey;
|
import org.signal.libsignal.protocol.IdentityKey;
|
||||||
import org.signal.libsignal.protocol.InvalidKeyException;
|
import org.signal.libsignal.protocol.InvalidKeyException;
|
||||||
import org.signal.libsignal.zkgroup.InvalidInputException;
|
import org.signal.libsignal.zkgroup.InvalidInputException;
|
||||||
|
@ -100,26 +101,36 @@ public class StorageHelper {
|
||||||
|
|
||||||
final var contactRecord = record.getContact().get();
|
final var contactRecord = record.getContact().get();
|
||||||
final var address = contactRecord.getAddress();
|
final var address = contactRecord.getAddress();
|
||||||
|
|
||||||
final var recipientId = account.getRecipientResolver().resolveRecipient(address);
|
final var recipientId = account.getRecipientResolver().resolveRecipient(address);
|
||||||
|
|
||||||
final var contact = account.getContactStore().getContact(recipientId);
|
final var contact = account.getContactStore().getContact(recipientId);
|
||||||
final var blocked = contact != null && contact.isBlocked();
|
final var blocked = contact != null && contact.isBlocked();
|
||||||
final var profileShared = contact != null && contact.isProfileSharingEnabled();
|
final var profileShared = contact != null && contact.isProfileSharingEnabled();
|
||||||
final var givenName = contact == null ? null : contact.getGivenName();
|
final var archived = contact != null && contact.isArchived();
|
||||||
final var familyName = contact == null ? null : contact.getFamilyName();
|
if (blocked != contactRecord.isBlocked()
|
||||||
if ((contactRecord.getGivenName().isPresent() && !contactRecord.getGivenName().get().equals(givenName)) || (
|
|| profileShared != contactRecord.isProfileSharingEnabled()
|
||||||
contactRecord.getFamilyName().isPresent() && !contactRecord.getFamilyName().get().equals(familyName)
|
|| archived != contactRecord.isArchived()) {
|
||||||
) || blocked != contactRecord.isBlocked() || profileShared != contactRecord.isProfileSharingEnabled()) {
|
|
||||||
logger.debug("Storing new or updated contact {}", recipientId);
|
logger.debug("Storing new or updated contact {}", recipientId);
|
||||||
final var contactBuilder = contact == null ? Contact.newBuilder() : Contact.newBuilder(contact);
|
final var contactBuilder = contact == null ? Contact.newBuilder() : Contact.newBuilder(contact);
|
||||||
final var newContact = contactBuilder.withBlocked(contactRecord.isBlocked())
|
final var newContact = contactBuilder.withBlocked(contactRecord.isBlocked())
|
||||||
.withGivenName(contactRecord.getGivenName().orElse(null))
|
|
||||||
.withFamilyName(contactRecord.getFamilyName().orElse(null))
|
|
||||||
.withProfileSharingEnabled(contactRecord.isProfileSharingEnabled())
|
.withProfileSharingEnabled(contactRecord.isProfileSharingEnabled())
|
||||||
|
.withArchived(contactRecord.isArchived())
|
||||||
.build();
|
.build();
|
||||||
account.getContactStore().storeContact(recipientId, newContact);
|
account.getContactStore().storeContact(recipientId, newContact);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final var profile = account.getProfileStore().getProfile(recipientId);
|
||||||
|
final var givenName = profile == null ? null : profile.getGivenName();
|
||||||
|
final var familyName = profile == null ? null : profile.getFamilyName();
|
||||||
|
if ((contactRecord.getGivenName().isPresent() && !contactRecord.getGivenName().get().equals(givenName)) || (
|
||||||
|
contactRecord.getFamilyName().isPresent() && !contactRecord.getFamilyName().get().equals(familyName)
|
||||||
|
)) {
|
||||||
|
final var profileBuilder = profile == null ? Profile.newBuilder() : Profile.newBuilder(profile);
|
||||||
|
final var newProfile = profileBuilder.withGivenName(contactRecord.getGivenName().orElse(null))
|
||||||
|
.withFamilyName(contactRecord.getFamilyName().orElse(null))
|
||||||
|
.build();
|
||||||
|
account.getProfileStore().storeProfile(recipientId, newProfile);
|
||||||
|
}
|
||||||
if (contactRecord.getProfileKey().isPresent()) {
|
if (contactRecord.getProfileKey().isPresent()) {
|
||||||
try {
|
try {
|
||||||
logger.trace("Storing profile key {}", recipientId);
|
logger.trace("Storing profile key {}", recipientId);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue