mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Only store recipient if there were changes
This commit is contained in:
parent
c9dffe47f6
commit
415b65d208
8 changed files with 107 additions and 8 deletions
|
@ -37,6 +37,9 @@
|
||||||
{
|
{
|
||||||
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BM\\E"
|
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BM\\E"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BR\\E"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BS\\E"
|
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BS\\E"
|
||||||
},
|
},
|
||||||
|
@ -46,6 +49,9 @@
|
||||||
{
|
{
|
||||||
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CH\\E"
|
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CH\\E"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CN\\E"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CZ\\E"
|
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CZ\\E"
|
||||||
},
|
},
|
||||||
|
@ -70,6 +76,15 @@
|
||||||
{
|
{
|
||||||
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GR\\E"
|
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GR\\E"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HK\\E"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HU\\E"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ID\\E"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IL\\E"
|
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IL\\E"
|
||||||
},
|
},
|
||||||
|
@ -85,6 +100,9 @@
|
||||||
{
|
{
|
||||||
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MO\\E"
|
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MO\\E"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MY\\E"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NL\\E"
|
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NL\\E"
|
||||||
},
|
},
|
||||||
|
@ -106,6 +124,9 @@
|
||||||
{
|
{
|
||||||
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_UA\\E"
|
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_UA\\E"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_UG\\E"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_US\\E"
|
"pattern":"\\Qcom/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_US\\E"
|
||||||
},
|
},
|
||||||
|
|
|
@ -94,8 +94,10 @@ public class AttachmentHelper {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final var pointer = attachment.asPointer();
|
||||||
|
logger.debug("Retrieving attachment {} with size {}", pointer.getRemoteId(), pointer.getSize());
|
||||||
var tmpFile = IOUtils.createTempFile();
|
var tmpFile = IOUtils.createTempFile();
|
||||||
try (var input = retrieveAttachmentAsStream(attachment.asPointer(), tmpFile)) {
|
try (var input = retrieveAttachmentAsStream(pointer, tmpFile)) {
|
||||||
consumer.handle(input);
|
consumer.handle(input);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -83,6 +83,7 @@ public class StorageHelper {
|
||||||
readContactRecord(record);
|
readContactRecord(record);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
logger.debug("Done reading data from remote storage");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readContactRecord(final SignalStorageRecord record) {
|
private void readContactRecord(final SignalStorageRecord record) {
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.asamk.signal.manager.storage.recipients;
|
package org.asamk.signal.manager.storage.recipients;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class Contact {
|
public class Contact {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
@ -68,6 +70,23 @@ public class Contact {
|
||||||
return archived;
|
return archived;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(final Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
final Contact contact = (Contact) o;
|
||||||
|
return messageExpirationTime == contact.messageExpirationTime
|
||||||
|
&& blocked == contact.blocked
|
||||||
|
&& archived == contact.archived
|
||||||
|
&& Objects.equals(name, contact.name)
|
||||||
|
&& Objects.equals(color, contact.color);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(name, color, messageExpirationTime, blocked, archived);
|
||||||
|
}
|
||||||
|
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.asamk.signal.manager.storage.recipients;
|
||||||
import org.whispersystems.signalservice.internal.util.Util;
|
import org.whispersystems.signalservice.internal.util.Util;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class Profile {
|
public class Profile {
|
||||||
|
@ -156,6 +157,33 @@ public class Profile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(final Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
final Profile profile = (Profile) o;
|
||||||
|
return lastUpdateTimestamp == profile.lastUpdateTimestamp
|
||||||
|
&& Objects.equals(givenName, profile.givenName)
|
||||||
|
&& Objects.equals(familyName, profile.familyName)
|
||||||
|
&& Objects.equals(about, profile.about)
|
||||||
|
&& Objects.equals(aboutEmoji, profile.aboutEmoji)
|
||||||
|
&& Objects.equals(avatarUrlPath, profile.avatarUrlPath)
|
||||||
|
&& unidentifiedAccessMode == profile.unidentifiedAccessMode
|
||||||
|
&& Objects.equals(capabilities, profile.capabilities);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(lastUpdateTimestamp,
|
||||||
|
givenName,
|
||||||
|
familyName,
|
||||||
|
about,
|
||||||
|
aboutEmoji,
|
||||||
|
avatarUrlPath,
|
||||||
|
unidentifiedAccessMode,
|
||||||
|
capabilities);
|
||||||
|
}
|
||||||
|
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
|
|
||||||
private String givenName;
|
private String givenName;
|
||||||
|
|
|
@ -3,6 +3,8 @@ package org.asamk.signal.manager.storage.recipients;
|
||||||
import org.signal.zkgroup.profiles.ProfileKey;
|
import org.signal.zkgroup.profiles.ProfileKey;
|
||||||
import org.signal.zkgroup.profiles.ProfileKeyCredential;
|
import org.signal.zkgroup.profiles.ProfileKeyCredential;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class Recipient {
|
public class Recipient {
|
||||||
|
|
||||||
private final RecipientId recipientId;
|
private final RecipientId recipientId;
|
||||||
|
@ -81,6 +83,24 @@ public class Recipient {
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(final Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
final Recipient recipient = (Recipient) o;
|
||||||
|
return Objects.equals(recipientId, recipient.recipientId)
|
||||||
|
&& Objects.equals(address, recipient.address)
|
||||||
|
&& Objects.equals(contact, recipient.contact)
|
||||||
|
&& Objects.equals(profileKey, recipient.profileKey)
|
||||||
|
&& Objects.equals(profileKeyCredential, recipient.profileKeyCredential)
|
||||||
|
&& Objects.equals(profile, recipient.profile);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(recipientId, address, contact, profileKey, profileKeyCredential, profile);
|
||||||
|
}
|
||||||
|
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
|
|
||||||
private RecipientId recipientId;
|
private RecipientId recipientId;
|
||||||
|
|
|
@ -130,10 +130,7 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
|
||||||
|
|
||||||
public Recipient getRecipient(RecipientId recipientId) {
|
public Recipient getRecipient(RecipientId recipientId) {
|
||||||
synchronized (recipients) {
|
synchronized (recipients) {
|
||||||
while (recipientsMerged.containsKey(recipientId)) {
|
return getRecipientLocked(recipientId);
|
||||||
recipientId = recipientsMerged.get(recipientId);
|
|
||||||
}
|
|
||||||
return recipients.get(recipientId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,11 +375,21 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
|
||||||
storeRecipientLocked(recipientId, Recipient.newBuilder(recipient).withAddress(address).build());
|
storeRecipientLocked(recipientId, Recipient.newBuilder(recipient).withAddress(address).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Recipient getRecipientLocked(RecipientId recipientId) {
|
||||||
|
while (recipientsMerged.containsKey(recipientId)) {
|
||||||
|
recipientId = recipientsMerged.get(recipientId);
|
||||||
|
}
|
||||||
|
return recipients.get(recipientId);
|
||||||
|
}
|
||||||
|
|
||||||
private void storeRecipientLocked(
|
private void storeRecipientLocked(
|
||||||
final RecipientId recipientId, final Recipient recipient
|
final RecipientId recipientId, final Recipient recipient
|
||||||
) {
|
) {
|
||||||
recipients.put(recipientId, recipient);
|
final var existingRecipient = getRecipientLocked(recipientId);
|
||||||
saveLocked();
|
if (existingRecipient == null || !existingRecipient.equals(recipient)) {
|
||||||
|
recipients.put(recipientId, recipient);
|
||||||
|
saveLocked();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mergeRecipientsLocked(RecipientId recipientId, RecipientId toBeMergedRecipientId) {
|
private void mergeRecipientsLocked(RecipientId recipientId, RecipientId toBeMergedRecipientId) {
|
||||||
|
|
|
@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ListIdentitiesCommand implements JsonRpcLocalCommand {
|
public class ListIdentitiesCommand implements JsonRpcLocalCommand {
|
||||||
|
@ -67,7 +68,7 @@ public class ListIdentitiesCommand implements JsonRpcLocalCommand {
|
||||||
var safetyNumber = Util.formatSafetyNumber(id.safetyNumber());
|
var safetyNumber = Util.formatSafetyNumber(id.safetyNumber());
|
||||||
var scannableSafetyNumber = id.scannableSafetyNumber();
|
var scannableSafetyNumber = id.scannableSafetyNumber();
|
||||||
return new JsonIdentity(address.getNumber().orElse(null),
|
return new JsonIdentity(address.getNumber().orElse(null),
|
||||||
address.getUuid().toString(),
|
address.getUuid().map(UUID::toString).orElse(null),
|
||||||
Hex.toString(id.getFingerprint()),
|
Hex.toString(id.getFingerprint()),
|
||||||
safetyNumber,
|
safetyNumber,
|
||||||
scannableSafetyNumber == null
|
scannableSafetyNumber == null
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue