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
|
@ -94,8 +94,10 @@ public class AttachmentHelper {
|
|||
return;
|
||||
}
|
||||
|
||||
final var pointer = attachment.asPointer();
|
||||
logger.debug("Retrieving attachment {} with size {}", pointer.getRemoteId(), pointer.getSize());
|
||||
var tmpFile = IOUtils.createTempFile();
|
||||
try (var input = retrieveAttachmentAsStream(attachment.asPointer(), tmpFile)) {
|
||||
try (var input = retrieveAttachmentAsStream(pointer, tmpFile)) {
|
||||
consumer.handle(input);
|
||||
} finally {
|
||||
try {
|
||||
|
|
|
@ -83,6 +83,7 @@ public class StorageHelper {
|
|||
readContactRecord(record);
|
||||
}
|
||||
}
|
||||
logger.debug("Done reading data from remote storage");
|
||||
}
|
||||
|
||||
private void readContactRecord(final SignalStorageRecord record) {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.asamk.signal.manager.storage.recipients;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Contact {
|
||||
|
||||
private final String name;
|
||||
|
@ -68,6 +70,23 @@ public class Contact {
|
|||
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 {
|
||||
|
||||
private String name;
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.asamk.signal.manager.storage.recipients;
|
|||
import org.whispersystems.signalservice.internal.util.Util;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
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 {
|
||||
|
||||
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.ProfileKeyCredential;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Recipient {
|
||||
|
||||
private final RecipientId recipientId;
|
||||
|
@ -81,6 +83,24 @@ public class Recipient {
|
|||
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 {
|
||||
|
||||
private RecipientId recipientId;
|
||||
|
|
|
@ -130,10 +130,7 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
|
|||
|
||||
public Recipient getRecipient(RecipientId recipientId) {
|
||||
synchronized (recipients) {
|
||||
while (recipientsMerged.containsKey(recipientId)) {
|
||||
recipientId = recipientsMerged.get(recipientId);
|
||||
}
|
||||
return recipients.get(recipientId);
|
||||
return getRecipientLocked(recipientId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -378,11 +375,21 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
|
|||
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(
|
||||
final RecipientId recipientId, final Recipient recipient
|
||||
) {
|
||||
recipients.put(recipientId, recipient);
|
||||
saveLocked();
|
||||
final var existingRecipient = getRecipientLocked(recipientId);
|
||||
if (existingRecipient == null || !existingRecipient.equals(recipient)) {
|
||||
recipients.put(recipientId, recipient);
|
||||
saveLocked();
|
||||
}
|
||||
}
|
||||
|
||||
private void mergeRecipientsLocked(RecipientId recipientId, RecipientId toBeMergedRecipientId) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue