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
|
@ -3226,6 +3226,10 @@
|
||||||
"name":"sun.security.x509.CRLDistributionPointsExtension",
|
"name":"sun.security.x509.CRLDistributionPointsExtension",
|
||||||
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
|
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name":"sun.security.x509.ExtendedKeyUsageExtension",
|
||||||
|
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name":"sun.security.x509.KeyUsageExtension",
|
"name":"sun.security.x509.KeyUsageExtension",
|
||||||
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
|
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package org.asamk.signal.manager;
|
package org.asamk.signal.manager;
|
||||||
|
|
||||||
import org.asamk.signal.manager.groups.GroupId;
|
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.IOUtils;
|
||||||
import org.asamk.signal.manager.util.Utils;
|
import org.asamk.signal.manager.util.Utils;
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
|
||||||
import org.whispersystems.signalservice.api.util.StreamDetails;
|
import org.whispersystems.signalservice.api.util.StreamDetails;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -20,11 +20,11 @@ public class AvatarStore {
|
||||||
this.avatarsPath = avatarsPath;
|
this.avatarsPath = avatarsPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StreamDetails retrieveContactAvatar(SignalServiceAddress address) throws IOException {
|
public StreamDetails retrieveContactAvatar(RecipientAddress address) throws IOException {
|
||||||
return retrieveAvatar(getContactAvatarFile(address));
|
return retrieveAvatar(getContactAvatarFile(address));
|
||||||
}
|
}
|
||||||
|
|
||||||
public StreamDetails retrieveProfileAvatar(SignalServiceAddress address) throws IOException {
|
public StreamDetails retrieveProfileAvatar(RecipientAddress address) throws IOException {
|
||||||
return retrieveAvatar(getProfileAvatarFile(address));
|
return retrieveAvatar(getProfileAvatarFile(address));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,11 +33,11 @@ public class AvatarStore {
|
||||||
return retrieveAvatar(groupAvatarFile);
|
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);
|
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);
|
storeAvatar(getProfileAvatarFile(address), storer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ public class AvatarStore {
|
||||||
storeAvatar(getGroupAvatarFile(groupId), storer);
|
storeAvatar(getGroupAvatarFile(groupId), storer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteProfileAvatar(SignalServiceAddress address) throws IOException {
|
public void deleteProfileAvatar(RecipientAddress address) throws IOException {
|
||||||
deleteAvatar(getProfileAvatarFile(address));
|
deleteAvatar(getProfileAvatarFile(address));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,16 +77,12 @@ public class AvatarStore {
|
||||||
return new File(avatarsPath, "group-" + groupId.toBase64().replace("/", "_"));
|
return new File(avatarsPath, "group-" + groupId.toBase64().replace("/", "_"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private File getContactAvatarFile(SignalServiceAddress address) {
|
private File getContactAvatarFile(RecipientAddress address) {
|
||||||
return new File(avatarsPath, "contact-" + getLegacyIdentifier(address));
|
return new File(avatarsPath, "contact-" + address.getLegacyIdentifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getLegacyIdentifier(final SignalServiceAddress address) {
|
private File getProfileAvatarFile(RecipientAddress address) {
|
||||||
return address.getNumber().or(() -> address.getAci().toString());
|
return new File(avatarsPath, "profile-" + address.getLegacyIdentifier());
|
||||||
}
|
|
||||||
|
|
||||||
private File getProfileAvatarFile(SignalServiceAddress address) {
|
|
||||||
return new File(avatarsPath, "profile-" + getLegacyIdentifier(address));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createAvatarsDir() throws IOException {
|
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.config.ServiceConfig;
|
||||||
import org.asamk.signal.manager.storage.SignalAccount;
|
import org.asamk.signal.manager.storage.SignalAccount;
|
||||||
import org.asamk.signal.manager.storage.recipients.Profile;
|
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.storage.recipients.RecipientId;
|
||||||
import org.asamk.signal.manager.util.IOUtils;
|
import org.asamk.signal.manager.util.IOUtils;
|
||||||
import org.asamk.signal.manager.util.ProfileUtils;
|
import org.asamk.signal.manager.util.ProfileUtils;
|
||||||
|
@ -131,7 +132,7 @@ public final class ProfileHelper {
|
||||||
if (uploadProfile) {
|
if (uploadProfile) {
|
||||||
try (final var streamDetails = avatar == null
|
try (final var streamDetails = avatar == null
|
||||||
? context.getAvatarStore()
|
? context.getAvatarStore()
|
||||||
.retrieveProfileAvatar(account.getSelfAddress())
|
.retrieveProfileAvatar(account.getSelfRecipientAddress())
|
||||||
: avatar.isPresent() ? Utils.createStreamDetailsFromFile(avatar.get()) : null) {
|
: avatar.isPresent() ? Utils.createStreamDetailsFromFile(avatar.get()) : null) {
|
||||||
final var avatarPath = dependencies.getAccountManager()
|
final var avatarPath = dependencies.getAccountManager()
|
||||||
.setVersionedProfile(account.getAci(),
|
.setVersionedProfile(account.getAci(),
|
||||||
|
@ -150,10 +151,10 @@ public final class ProfileHelper {
|
||||||
if (avatar != null) {
|
if (avatar != null) {
|
||||||
if (avatar.isPresent()) {
|
if (avatar.isPresent()) {
|
||||||
context.getAvatarStore()
|
context.getAvatarStore()
|
||||||
.storeProfileAvatar(account.getSelfAddress(),
|
.storeProfileAvatar(account.getSelfRecipientAddress(),
|
||||||
outputStream -> IOUtils.copyFileToStream(avatar.get(), outputStream));
|
outputStream -> IOUtils.copyFileToStream(avatar.get(), outputStream));
|
||||||
} else {
|
} else {
|
||||||
context.getAvatarStore().deleteProfileAvatar(account.getSelfAddress());
|
context.getAvatarStore().deleteProfileAvatar(account.getSelfRecipientAddress());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
account.getProfileStore().storeProfile(account.getSelfRecipientId(), newProfile);
|
account.getProfileStore().storeProfile(account.getSelfRecipientId(), newProfile);
|
||||||
|
@ -219,7 +220,7 @@ public final class ProfileHelper {
|
||||||
var profile = account.getProfileStore().getProfile(recipientId);
|
var profile = account.getProfileStore().getProfile(recipientId);
|
||||||
if (profile == null || !Objects.equals(avatarPath, profile.getAvatarUrlPath())) {
|
if (profile == null || !Objects.equals(avatarPath, profile.getAvatarUrlPath())) {
|
||||||
logger.trace("Downloading profile avatar for {}", recipientId);
|
logger.trace("Downloading profile avatar for {}", recipientId);
|
||||||
downloadProfileAvatar(context.getRecipientHelper().resolveSignalServiceAddress(recipientId),
|
downloadProfileAvatar(account.getRecipientStore().resolveRecipientAddress(recipientId),
|
||||||
avatarPath,
|
avatarPath,
|
||||||
profileKey);
|
profileKey);
|
||||||
var builder = profile == null ? Profile.newBuilder() : Profile.newBuilder(profile);
|
var builder = profile == null ? Profile.newBuilder() : Profile.newBuilder(profile);
|
||||||
|
@ -330,7 +331,7 @@ public final class ProfileHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void downloadProfileAvatar(
|
private void downloadProfileAvatar(
|
||||||
SignalServiceAddress address, String avatarPath, ProfileKey profileKey
|
RecipientAddress address, String avatarPath, ProfileKey profileKey
|
||||||
) {
|
) {
|
||||||
if (avatarPath == null) {
|
if (avatarPath == null) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import org.asamk.signal.manager.TrustLevel;
|
||||||
import org.asamk.signal.manager.storage.SignalAccount;
|
import org.asamk.signal.manager.storage.SignalAccount;
|
||||||
import org.asamk.signal.manager.storage.groups.GroupInfoV1;
|
import org.asamk.signal.manager.storage.groups.GroupInfoV1;
|
||||||
import org.asamk.signal.manager.storage.recipients.Contact;
|
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.AttachmentUtils;
|
||||||
import org.asamk.signal.manager.util.IOUtils;
|
import org.asamk.signal.manager.util.IOUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -128,7 +129,7 @@ public class SyncHelper {
|
||||||
var profileKey = account.getProfileStore().getProfileKey(recipientId);
|
var profileKey = account.getProfileStore().getProfileKey(recipientId);
|
||||||
out.write(new DeviceContact(address,
|
out.write(new DeviceContact(address,
|
||||||
Optional.fromNullable(contact.getName()),
|
Optional.fromNullable(contact.getName()),
|
||||||
createContactAvatarAttachment(address),
|
createContactAvatarAttachment(new RecipientAddress(address)),
|
||||||
Optional.fromNullable(contact.getColor()),
|
Optional.fromNullable(contact.getColor()),
|
||||||
Optional.fromNullable(verifiedMessage),
|
Optional.fromNullable(verifiedMessage),
|
||||||
Optional.fromNullable(profileKey),
|
Optional.fromNullable(profileKey),
|
||||||
|
@ -264,7 +265,7 @@ public class SyncHelper {
|
||||||
account.getContactStore().storeContact(recipientId, builder.build());
|
account.getContactStore().storeContact(recipientId, builder.build());
|
||||||
|
|
||||||
if (c.getAvatar().isPresent()) {
|
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);
|
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);
|
final var streamDetails = context.getAvatarStore().retrieveContactAvatar(address);
|
||||||
if (streamDetails == null) {
|
if (streamDetails == null) {
|
||||||
return Optional.absent();
|
return Optional.absent();
|
||||||
|
@ -318,7 +319,7 @@ public class SyncHelper {
|
||||||
return Optional.of(AttachmentUtils.createAttachment(streamDetails, Optional.absent()));
|
return Optional.of(AttachmentUtils.createAttachment(streamDetails, Optional.absent()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void downloadContactAvatar(SignalServiceAttachment avatar, SignalServiceAddress address) {
|
private void downloadContactAvatar(SignalServiceAttachment avatar, RecipientAddress address) {
|
||||||
try {
|
try {
|
||||||
context.getAvatarStore()
|
context.getAvatarStore()
|
||||||
.storeContactAvatar(address,
|
.storeContactAvatar(address,
|
||||||
|
|
|
@ -554,7 +554,7 @@ public class SignalAccount implements Closeable {
|
||||||
if (legacyRecipientStore != null) {
|
if (legacyRecipientStore != null) {
|
||||||
getRecipientStore().resolveRecipientsTrusted(legacyRecipientStore.getAddresses());
|
getRecipientStore().resolveRecipientsTrusted(legacyRecipientStore.getAddresses());
|
||||||
}
|
}
|
||||||
getSelfRecipientId();
|
getRecipientStore().resolveRecipientTrusted(getSelfRecipientAddress());
|
||||||
migrated = true;
|
migrated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -914,9 +914,12 @@ public class SignalAccount implements Closeable {
|
||||||
return new SignalServiceAddress(aci, account);
|
return new SignalServiceAddress(aci, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RecipientAddress getSelfRecipientAddress() {
|
||||||
|
return new RecipientAddress(aci == null ? null : aci.uuid(), account);
|
||||||
|
}
|
||||||
|
|
||||||
public RecipientId getSelfRecipientId() {
|
public RecipientId getSelfRecipientId() {
|
||||||
return getRecipientStore().resolveRecipientTrusted(new RecipientAddress(aci == null ? null : aci.uuid(),
|
return getRecipientStore().resolveRecipient(getSelfRecipientAddress());
|
||||||
account));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEncryptedDeviceName() {
|
public String getEncryptedDeviceName() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue