mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Use RecipientAddress in AvatarStore
This commit is contained in:
parent
285bfafdc1
commit
b9f66248ac
5 changed files with 31 additions and 26 deletions
|
@ -1,9 +1,9 @@
|
|||
package org.asamk.signal.manager;
|
||||
|
||||
import org.asamk.signal.manager.groups.GroupId;
|
||||
import org.asamk.signal.manager.storage.recipients.RecipientAddress;
|
||||
import org.asamk.signal.manager.util.IOUtils;
|
||||
import org.asamk.signal.manager.util.Utils;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
import org.whispersystems.signalservice.api.util.StreamDetails;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -20,11 +20,11 @@ public class AvatarStore {
|
|||
this.avatarsPath = avatarsPath;
|
||||
}
|
||||
|
||||
public StreamDetails retrieveContactAvatar(SignalServiceAddress address) throws IOException {
|
||||
public StreamDetails retrieveContactAvatar(RecipientAddress address) throws IOException {
|
||||
return retrieveAvatar(getContactAvatarFile(address));
|
||||
}
|
||||
|
||||
public StreamDetails retrieveProfileAvatar(SignalServiceAddress address) throws IOException {
|
||||
public StreamDetails retrieveProfileAvatar(RecipientAddress address) throws IOException {
|
||||
return retrieveAvatar(getProfileAvatarFile(address));
|
||||
}
|
||||
|
||||
|
@ -33,11 +33,11 @@ public class AvatarStore {
|
|||
return retrieveAvatar(groupAvatarFile);
|
||||
}
|
||||
|
||||
public void storeContactAvatar(SignalServiceAddress address, AvatarStorer storer) throws IOException {
|
||||
public void storeContactAvatar(RecipientAddress address, AvatarStorer storer) throws IOException {
|
||||
storeAvatar(getContactAvatarFile(address), storer);
|
||||
}
|
||||
|
||||
public void storeProfileAvatar(SignalServiceAddress address, AvatarStorer storer) throws IOException {
|
||||
public void storeProfileAvatar(RecipientAddress address, AvatarStorer storer) throws IOException {
|
||||
storeAvatar(getProfileAvatarFile(address), storer);
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ public class AvatarStore {
|
|||
storeAvatar(getGroupAvatarFile(groupId), storer);
|
||||
}
|
||||
|
||||
public void deleteProfileAvatar(SignalServiceAddress address) throws IOException {
|
||||
public void deleteProfileAvatar(RecipientAddress address) throws IOException {
|
||||
deleteAvatar(getProfileAvatarFile(address));
|
||||
}
|
||||
|
||||
|
@ -77,16 +77,12 @@ public class AvatarStore {
|
|||
return new File(avatarsPath, "group-" + groupId.toBase64().replace("/", "_"));
|
||||
}
|
||||
|
||||
private File getContactAvatarFile(SignalServiceAddress address) {
|
||||
return new File(avatarsPath, "contact-" + getLegacyIdentifier(address));
|
||||
private File getContactAvatarFile(RecipientAddress address) {
|
||||
return new File(avatarsPath, "contact-" + address.getLegacyIdentifier());
|
||||
}
|
||||
|
||||
private String getLegacyIdentifier(final SignalServiceAddress address) {
|
||||
return address.getNumber().or(() -> address.getAci().toString());
|
||||
}
|
||||
|
||||
private File getProfileAvatarFile(SignalServiceAddress address) {
|
||||
return new File(avatarsPath, "profile-" + getLegacyIdentifier(address));
|
||||
private File getProfileAvatarFile(RecipientAddress address) {
|
||||
return new File(avatarsPath, "profile-" + address.getLegacyIdentifier());
|
||||
}
|
||||
|
||||
private void createAvatarsDir() throws IOException {
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.asamk.signal.manager.SignalDependencies;
|
|||
import org.asamk.signal.manager.config.ServiceConfig;
|
||||
import org.asamk.signal.manager.storage.SignalAccount;
|
||||
import org.asamk.signal.manager.storage.recipients.Profile;
|
||||
import org.asamk.signal.manager.storage.recipients.RecipientAddress;
|
||||
import org.asamk.signal.manager.storage.recipients.RecipientId;
|
||||
import org.asamk.signal.manager.util.IOUtils;
|
||||
import org.asamk.signal.manager.util.ProfileUtils;
|
||||
|
@ -131,7 +132,7 @@ public final class ProfileHelper {
|
|||
if (uploadProfile) {
|
||||
try (final var streamDetails = avatar == null
|
||||
? context.getAvatarStore()
|
||||
.retrieveProfileAvatar(account.getSelfAddress())
|
||||
.retrieveProfileAvatar(account.getSelfRecipientAddress())
|
||||
: avatar.isPresent() ? Utils.createStreamDetailsFromFile(avatar.get()) : null) {
|
||||
final var avatarPath = dependencies.getAccountManager()
|
||||
.setVersionedProfile(account.getAci(),
|
||||
|
@ -150,10 +151,10 @@ public final class ProfileHelper {
|
|||
if (avatar != null) {
|
||||
if (avatar.isPresent()) {
|
||||
context.getAvatarStore()
|
||||
.storeProfileAvatar(account.getSelfAddress(),
|
||||
.storeProfileAvatar(account.getSelfRecipientAddress(),
|
||||
outputStream -> IOUtils.copyFileToStream(avatar.get(), outputStream));
|
||||
} else {
|
||||
context.getAvatarStore().deleteProfileAvatar(account.getSelfAddress());
|
||||
context.getAvatarStore().deleteProfileAvatar(account.getSelfRecipientAddress());
|
||||
}
|
||||
}
|
||||
account.getProfileStore().storeProfile(account.getSelfRecipientId(), newProfile);
|
||||
|
@ -219,7 +220,7 @@ public final class ProfileHelper {
|
|||
var profile = account.getProfileStore().getProfile(recipientId);
|
||||
if (profile == null || !Objects.equals(avatarPath, profile.getAvatarUrlPath())) {
|
||||
logger.trace("Downloading profile avatar for {}", recipientId);
|
||||
downloadProfileAvatar(context.getRecipientHelper().resolveSignalServiceAddress(recipientId),
|
||||
downloadProfileAvatar(account.getRecipientStore().resolveRecipientAddress(recipientId),
|
||||
avatarPath,
|
||||
profileKey);
|
||||
var builder = profile == null ? Profile.newBuilder() : Profile.newBuilder(profile);
|
||||
|
@ -330,7 +331,7 @@ public final class ProfileHelper {
|
|||
}
|
||||
|
||||
private void downloadProfileAvatar(
|
||||
SignalServiceAddress address, String avatarPath, ProfileKey profileKey
|
||||
RecipientAddress address, String avatarPath, ProfileKey profileKey
|
||||
) {
|
||||
if (avatarPath == null) {
|
||||
try {
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.asamk.signal.manager.TrustLevel;
|
|||
import org.asamk.signal.manager.storage.SignalAccount;
|
||||
import org.asamk.signal.manager.storage.groups.GroupInfoV1;
|
||||
import org.asamk.signal.manager.storage.recipients.Contact;
|
||||
import org.asamk.signal.manager.storage.recipients.RecipientAddress;
|
||||
import org.asamk.signal.manager.util.AttachmentUtils;
|
||||
import org.asamk.signal.manager.util.IOUtils;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -128,7 +129,7 @@ public class SyncHelper {
|
|||
var profileKey = account.getProfileStore().getProfileKey(recipientId);
|
||||
out.write(new DeviceContact(address,
|
||||
Optional.fromNullable(contact.getName()),
|
||||
createContactAvatarAttachment(address),
|
||||
createContactAvatarAttachment(new RecipientAddress(address)),
|
||||
Optional.fromNullable(contact.getColor()),
|
||||
Optional.fromNullable(verifiedMessage),
|
||||
Optional.fromNullable(profileKey),
|
||||
|
@ -264,7 +265,7 @@ public class SyncHelper {
|
|||
account.getContactStore().storeContact(recipientId, builder.build());
|
||||
|
||||
if (c.getAvatar().isPresent()) {
|
||||
downloadContactAvatar(c.getAvatar().get(), c.getAddress());
|
||||
downloadContactAvatar(c.getAvatar().get(), new RecipientAddress(c.getAddress()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -309,7 +310,7 @@ public class SyncHelper {
|
|||
context.getSendHelper().sendSyncMessage(message);
|
||||
}
|
||||
|
||||
private Optional<SignalServiceAttachmentStream> createContactAvatarAttachment(SignalServiceAddress address) throws IOException {
|
||||
private Optional<SignalServiceAttachmentStream> createContactAvatarAttachment(RecipientAddress address) throws IOException {
|
||||
final var streamDetails = context.getAvatarStore().retrieveContactAvatar(address);
|
||||
if (streamDetails == null) {
|
||||
return Optional.absent();
|
||||
|
@ -318,7 +319,7 @@ public class SyncHelper {
|
|||
return Optional.of(AttachmentUtils.createAttachment(streamDetails, Optional.absent()));
|
||||
}
|
||||
|
||||
private void downloadContactAvatar(SignalServiceAttachment avatar, SignalServiceAddress address) {
|
||||
private void downloadContactAvatar(SignalServiceAttachment avatar, RecipientAddress address) {
|
||||
try {
|
||||
context.getAvatarStore()
|
||||
.storeContactAvatar(address,
|
||||
|
|
|
@ -554,7 +554,7 @@ public class SignalAccount implements Closeable {
|
|||
if (legacyRecipientStore != null) {
|
||||
getRecipientStore().resolveRecipientsTrusted(legacyRecipientStore.getAddresses());
|
||||
}
|
||||
getSelfRecipientId();
|
||||
getRecipientStore().resolveRecipientTrusted(getSelfRecipientAddress());
|
||||
migrated = true;
|
||||
}
|
||||
|
||||
|
@ -914,9 +914,12 @@ public class SignalAccount implements Closeable {
|
|||
return new SignalServiceAddress(aci, account);
|
||||
}
|
||||
|
||||
public RecipientAddress getSelfRecipientAddress() {
|
||||
return new RecipientAddress(aci == null ? null : aci.uuid(), account);
|
||||
}
|
||||
|
||||
public RecipientId getSelfRecipientId() {
|
||||
return getRecipientStore().resolveRecipientTrusted(new RecipientAddress(aci == null ? null : aci.uuid(),
|
||||
account));
|
||||
return getRecipientStore().resolveRecipient(getSelfRecipientAddress());
|
||||
}
|
||||
|
||||
public String getEncryptedDeviceName() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue