mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Store payment address of profiles
This commit is contained in:
parent
c3425979dd
commit
e844abcad1
5 changed files with 53 additions and 20 deletions
|
@ -1,5 +1,7 @@
|
|||
package org.asamk.signal.manager.helper;
|
||||
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
import org.asamk.signal.manager.SignalDependencies;
|
||||
import org.asamk.signal.manager.config.ServiceConfig;
|
||||
import org.asamk.signal.manager.storage.SignalAccount;
|
||||
|
@ -23,6 +25,7 @@ import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
|||
import org.whispersystems.signalservice.api.push.exceptions.NotFoundException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException;
|
||||
import org.whispersystems.signalservice.api.services.ProfileService;
|
||||
import org.whispersystems.signalservice.internal.push.SignalServiceProtos;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -138,13 +141,20 @@ public final class ProfileHelper {
|
|||
: avatar.isPresent()
|
||||
? AvatarUploadParams.forAvatar(streamDetails)
|
||||
: AvatarUploadParams.unchanged(false);
|
||||
final var paymentsAddress = Optional.ofNullable(newProfile.getPaymentAddress()).map(data -> {
|
||||
try {
|
||||
return SignalServiceProtos.PaymentAddress.parseFrom(data);
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
final var avatarPath = dependencies.getAccountManager()
|
||||
.setVersionedProfile(account.getAci(),
|
||||
account.getProfileKey(),
|
||||
newProfile.getInternalServiceName(),
|
||||
newProfile.getAbout() == null ? "" : newProfile.getAbout(),
|
||||
newProfile.getAboutEmoji() == null ? "" : newProfile.getAboutEmoji(),
|
||||
Optional.empty(),
|
||||
paymentsAddress,
|
||||
avatarUploadParams,
|
||||
List.of(/* TODO */));
|
||||
builder.withAvatarUrlPath(avatarPath.orElse(null));
|
||||
|
|
|
@ -757,6 +757,7 @@ public class SignalAccount implements Closeable {
|
|||
profile.getAbout(),
|
||||
profile.getAboutEmoji(),
|
||||
null,
|
||||
null,
|
||||
profile.isUnrestrictedUnidentifiedAccess()
|
||||
? Profile.UnidentifiedAccessMode.UNRESTRICTED
|
||||
: profile.getUnidentifiedAccess() != null
|
||||
|
|
|
@ -20,6 +20,8 @@ public class Profile {
|
|||
|
||||
private final String avatarUrlPath;
|
||||
|
||||
private final byte[] paymentAddress;
|
||||
|
||||
private final UnidentifiedAccessMode unidentifiedAccessMode;
|
||||
|
||||
private final Set<Capability> capabilities;
|
||||
|
@ -31,6 +33,7 @@ public class Profile {
|
|||
final String about,
|
||||
final String aboutEmoji,
|
||||
final String avatarUrlPath,
|
||||
final byte[] paymentAddress,
|
||||
final UnidentifiedAccessMode unidentifiedAccessMode,
|
||||
final Set<Capability> capabilities
|
||||
) {
|
||||
|
@ -40,6 +43,7 @@ public class Profile {
|
|||
this.about = about;
|
||||
this.aboutEmoji = aboutEmoji;
|
||||
this.avatarUrlPath = avatarUrlPath;
|
||||
this.paymentAddress = paymentAddress;
|
||||
this.unidentifiedAccessMode = unidentifiedAccessMode;
|
||||
this.capabilities = capabilities;
|
||||
}
|
||||
|
@ -51,6 +55,7 @@ public class Profile {
|
|||
about = builder.about;
|
||||
aboutEmoji = builder.aboutEmoji;
|
||||
avatarUrlPath = builder.avatarUrlPath;
|
||||
paymentAddress = builder.paymentAddress;
|
||||
unidentifiedAccessMode = builder.unidentifiedAccessMode;
|
||||
capabilities = builder.capabilities;
|
||||
}
|
||||
|
@ -67,6 +72,7 @@ public class Profile {
|
|||
builder.about = copy.getAbout();
|
||||
builder.aboutEmoji = copy.getAboutEmoji();
|
||||
builder.avatarUrlPath = copy.getAvatarUrlPath();
|
||||
builder.paymentAddress = copy.getPaymentAddress();
|
||||
builder.unidentifiedAccessMode = copy.getUnidentifiedAccessMode();
|
||||
builder.capabilities = copy.getCapabilities();
|
||||
return builder;
|
||||
|
@ -118,6 +124,10 @@ public class Profile {
|
|||
return avatarUrlPath;
|
||||
}
|
||||
|
||||
public byte[] getPaymentAddress() {
|
||||
return paymentAddress;
|
||||
}
|
||||
|
||||
public UnidentifiedAccessMode getUnidentifiedAccessMode() {
|
||||
return unidentifiedAccessMode;
|
||||
}
|
||||
|
@ -190,6 +200,7 @@ public class Profile {
|
|||
private String about;
|
||||
private String aboutEmoji;
|
||||
private String avatarUrlPath;
|
||||
private byte[] paymentAddress;
|
||||
private UnidentifiedAccessMode unidentifiedAccessMode = UnidentifiedAccessMode.UNKNOWN;
|
||||
private Set<Capability> capabilities = Collections.emptySet();
|
||||
private long lastUpdateTimestamp = 0;
|
||||
|
@ -240,5 +251,10 @@ public class Profile {
|
|||
lastUpdateTimestamp = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withPaymentAddress(final byte[] val) {
|
||||
paymentAddress = val;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,6 +103,9 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
|
|||
r.profile.about,
|
||||
r.profile.aboutEmoji,
|
||||
r.profile.avatarUrlPath,
|
||||
r.profile.paymentAddress == null
|
||||
? null
|
||||
: Base64.getDecoder().decode(r.profile.paymentAddress),
|
||||
Profile.UnidentifiedAccessMode.valueOfOrUnknown(r.profile.unidentifiedAccessMode),
|
||||
r.profile.capabilities.stream()
|
||||
.map(Profile.Capability::valueOfOrNull)
|
||||
|
@ -535,27 +538,28 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
|
|||
final var base64 = Base64.getEncoder();
|
||||
var storage = new Storage(recipients.entrySet().stream().map(pair -> {
|
||||
final var recipient = pair.getValue();
|
||||
final var contact = recipient.getContact() == null
|
||||
final var recipientContact = recipient.getContact();
|
||||
final var contact = recipientContact == null
|
||||
? null
|
||||
: new Storage.Recipient.Contact(recipient.getContact().getName(),
|
||||
recipient.getContact().getColor(),
|
||||
recipient.getContact().getMessageExpirationTime(),
|
||||
recipient.getContact().isBlocked(),
|
||||
recipient.getContact().isArchived());
|
||||
final var profile = recipient.getProfile() == null
|
||||
: new Storage.Recipient.Contact(recipientContact.getName(),
|
||||
recipientContact.getColor(),
|
||||
recipientContact.getMessageExpirationTime(),
|
||||
recipientContact.isBlocked(),
|
||||
recipientContact.isArchived());
|
||||
final var recipientProfile = recipient.getProfile();
|
||||
final var profile = recipientProfile == null
|
||||
? null
|
||||
: new Storage.Recipient.Profile(recipient.getProfile().getLastUpdateTimestamp(),
|
||||
recipient.getProfile().getGivenName(),
|
||||
recipient.getProfile().getFamilyName(),
|
||||
recipient.getProfile().getAbout(),
|
||||
recipient.getProfile().getAboutEmoji(),
|
||||
recipient.getProfile().getAvatarUrlPath(),
|
||||
recipient.getProfile().getUnidentifiedAccessMode().name(),
|
||||
recipient.getProfile()
|
||||
.getCapabilities()
|
||||
.stream()
|
||||
.map(Enum::name)
|
||||
.collect(Collectors.toSet()));
|
||||
: new Storage.Recipient.Profile(recipientProfile.getLastUpdateTimestamp(),
|
||||
recipientProfile.getGivenName(),
|
||||
recipientProfile.getFamilyName(),
|
||||
recipientProfile.getAbout(),
|
||||
recipientProfile.getAboutEmoji(),
|
||||
recipientProfile.getAvatarUrlPath(),
|
||||
recipientProfile.getPaymentAddress() == null
|
||||
? null
|
||||
: base64.encodeToString(recipientProfile.getPaymentAddress()),
|
||||
recipientProfile.getUnidentifiedAccessMode().name(),
|
||||
recipientProfile.getCapabilities().stream().map(Enum::name).collect(Collectors.toSet()));
|
||||
return new Storage.Recipient(pair.getKey().id(),
|
||||
recipient.getAddress().number().orElse(null),
|
||||
recipient.getAddress().uuid().map(UUID::toString).orElse(null),
|
||||
|
@ -605,6 +609,7 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
|
|||
String about,
|
||||
String aboutEmoji,
|
||||
String avatarUrlPath,
|
||||
String paymentAddress,
|
||||
String unidentifiedAccessMode,
|
||||
Set<String> capabilities
|
||||
) {}
|
||||
|
|
|
@ -32,6 +32,7 @@ public class ProfileUtils {
|
|||
about,
|
||||
aboutEmoji,
|
||||
encryptedProfile.getAvatar(),
|
||||
encryptedProfile.getPaymentAddress(),
|
||||
getUnidentifiedAccessMode(encryptedProfile, profileCipher),
|
||||
getCapabilities(encryptedProfile));
|
||||
} catch (InvalidCiphertextException e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue