Skip to content

Commit

Permalink
Add mobile-coin-address to updateProfile command
Browse files Browse the repository at this point in the history
  • Loading branch information
AsamK committed May 21, 2022
1 parent bf75d9b commit 34c0968
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ public void updateProfile(UpdateProfile updateProfile) throws IOException {
updateProfile.getAboutEmoji(),
updateProfile.isDeleteAvatar()
? Optional.empty()
: updateProfile.getAvatar() == null ? null : Optional.of(updateProfile.getAvatar()));
: updateProfile.getAvatar() == null ? null : Optional.of(updateProfile.getAvatar()),
updateProfile.getMobileCoinAddress());
context.getSyncHelper().sendSyncFetchProfileMessage();
}

Expand Down
13 changes: 13 additions & 0 deletions lib/src/main/java/org/asamk/signal/manager/api/UpdateProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class UpdateProfile {
private final String aboutEmoji;
private final File avatar;
private final boolean deleteAvatar;
private final byte[] mobileCoinAddress;

private UpdateProfile(final Builder builder) {
givenName = builder.givenName;
Expand All @@ -18,6 +19,7 @@ private UpdateProfile(final Builder builder) {
aboutEmoji = builder.aboutEmoji;
avatar = builder.avatar;
deleteAvatar = builder.deleteAvatar;
mobileCoinAddress = builder.mobileCoinAddress;
}

public static Builder newBuilder() {
Expand All @@ -32,6 +34,7 @@ public static Builder newBuilder(final UpdateProfile copy) {
builder.aboutEmoji = copy.getAboutEmoji();
builder.avatar = copy.getAvatar();
builder.deleteAvatar = copy.isDeleteAvatar();
builder.mobileCoinAddress = copy.getMobileCoinAddress();
return builder;
}

Expand Down Expand Up @@ -59,6 +62,10 @@ public boolean isDeleteAvatar() {
return deleteAvatar;
}

public byte[] getMobileCoinAddress() {
return mobileCoinAddress;
}

public static final class Builder {

private String givenName;
Expand All @@ -67,6 +74,7 @@ public static final class Builder {
private String aboutEmoji;
private File avatar;
private boolean deleteAvatar;
private byte[] mobileCoinAddress;

private Builder() {
}
Expand Down Expand Up @@ -101,6 +109,11 @@ public Builder withDeleteAvatar(final boolean val) {
return this;
}

public Builder withMobileCoinAddress(final byte[] val) {
mobileCoinAddress = val;
return this;
}

public UpdateProfile build() {
return new UpdateProfile(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void rotateProfileKey() throws IOException {
var profileKey = KeyUtils.createProfileKey();
account.setProfileKey(profileKey);
context.getAccountHelper().updateAccountAttributes();
setProfile(true, true, null, null, null, null, null);
setProfile(true, true, null, null, null, null, null, null);
// TODO update profile key in storage

final var recipientIds = account.getRecipientStore().getRecipientIdsWithEnabledProfileSharing();
Expand Down Expand Up @@ -144,9 +144,14 @@ public ProfileKeyCredential getRecipientProfileKeyCredential(RecipientId recipie
* @param avatar if avatar is null the image from the local avatar store is used (if present),
*/
public void setProfile(
String givenName, final String familyName, String about, String aboutEmoji, Optional<File> avatar
String givenName,
final String familyName,
String about,
String aboutEmoji,
Optional<File> avatar,
byte[] mobileCoinAddress
) throws IOException {
setProfile(true, false, givenName, familyName, about, aboutEmoji, avatar);
setProfile(true, false, givenName, familyName, about, aboutEmoji, avatar, mobileCoinAddress);
}

public void setProfile(
Expand All @@ -156,7 +161,8 @@ public void setProfile(
final String familyName,
String about,
String aboutEmoji,
Optional<File> avatar
Optional<File> avatar,
byte[] mobileCoinAddress
) throws IOException {
var profile = getSelfProfile();
var builder = profile == null ? Profile.newBuilder() : Profile.newBuilder(profile);
Expand All @@ -172,6 +178,9 @@ public void setProfile(
if (aboutEmoji != null) {
builder.withAboutEmoji(aboutEmoji);
}
if (mobileCoinAddress != null) {
builder.withMobileCoinAddress(mobileCoinAddress);
}
var newProfile = builder.build();

if (uploadProfile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ private void readAccountRecord(final SignalStorageManifest manifest) throws IOEx
accountRecord.getFamilyName().orElse(null),
null,
null,
null,
null);
}

Expand Down
3 changes: 3 additions & 0 deletions man/signal-cli.1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,9 @@ Path to the new avatar image file.
*--remove-avatar*::
Remove the avatar

*--mobile-coin-address*::
New MobileCoin address (Base64 encoded public address)

=== updateContact

Update the info associated to a number on our contact list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.io.File;
import java.io.IOException;
import java.util.Base64;

public class UpdateProfileCommand implements JsonRpcLocalCommand {

Expand All @@ -27,6 +28,7 @@ public void attachToSubparser(final Subparser subparser) {
subparser.addArgument("--family-name").help("New profile family name (optional)");
subparser.addArgument("--about").help("New profile about text");
subparser.addArgument("--about-emoji").help("New profile about emoji");
subparser.addArgument("--mobile-coin-address").help("New MobileCoin address (Base64 encoded public address)");

final var avatarOptions = subparser.addMutuallyExclusiveGroup();
avatarOptions.addArgument("--avatar").help("Path to new profile avatar");
Expand All @@ -41,9 +43,13 @@ public void handleCommand(
var familyName = ns.getString("family-name");
var about = ns.getString("about");
var aboutEmoji = ns.getString("about-emoji");
var mobileCoinAddressString = ns.getString("mobile-coin-address");
var mobileCoinAddress = mobileCoinAddressString == null
? null
: Base64.getDecoder().decode(mobileCoinAddressString);

var avatarPath = ns.getString("avatar");
boolean removeAvatar = Boolean.TRUE.equals(ns.getBoolean("remove-avatar"));

File avatarFile = removeAvatar || avatarPath == null ? null : new File(avatarPath);

try {
Expand All @@ -52,6 +58,7 @@ public void handleCommand(
.withFamilyName(familyName)
.withAbout(about)
.withAboutEmoji(aboutEmoji)
.withMobileCoinAddress(mobileCoinAddress)
.withAvatar(avatarFile)
.withDeleteAvatar(removeAvatar)
.build());
Expand Down

0 comments on commit 34c0968

Please sign in to comment.