]> nmode's Git Repositories - signal-cli/commitdiff
Add mobile-coin-address to updateProfile command
authorAsamK <asamk@gmx.de>
Sat, 21 May 2022 08:42:56 +0000 (10:42 +0200)
committerAsamK <asamk@gmx.de>
Sat, 21 May 2022 08:44:28 +0000 (10:44 +0200)
lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java
lib/src/main/java/org/asamk/signal/manager/api/UpdateProfile.java
lib/src/main/java/org/asamk/signal/manager/helper/ProfileHelper.java
lib/src/main/java/org/asamk/signal/manager/helper/StorageHelper.java
man/signal-cli.1.adoc
src/main/java/org/asamk/signal/commands/UpdateProfileCommand.java

index 3ca3c109a0be58e1fdf7db525c9db38fbb92f944..96196f8ff8e6f3fc89039f4ab6bb424fd2cc8173 100644 (file)
@@ -270,7 +270,8 @@ class ManagerImpl implements Manager {
                         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();
     }
 
index 2b47f7d58f7289b39773895c89aa083daf052969..d5de308e4bb37929701ad2f7475768d278229b06 100644 (file)
@@ -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;
@@ -18,6 +19,7 @@ public class UpdateProfile {
         aboutEmoji = builder.aboutEmoji;
         avatar = builder.avatar;
         deleteAvatar = builder.deleteAvatar;
+        mobileCoinAddress = builder.mobileCoinAddress;
     }
 
     public static Builder newBuilder() {
@@ -32,6 +34,7 @@ public class UpdateProfile {
         builder.aboutEmoji = copy.getAboutEmoji();
         builder.avatar = copy.getAvatar();
         builder.deleteAvatar = copy.isDeleteAvatar();
+        builder.mobileCoinAddress = copy.getMobileCoinAddress();
         return builder;
     }
 
@@ -59,6 +62,10 @@ public class UpdateProfile {
         return deleteAvatar;
     }
 
+    public byte[] getMobileCoinAddress() {
+        return mobileCoinAddress;
+    }
+
     public static final class Builder {
 
         private String givenName;
@@ -67,6 +74,7 @@ public class UpdateProfile {
         private String aboutEmoji;
         private File avatar;
         private boolean deleteAvatar;
+        private byte[] mobileCoinAddress;
 
         private Builder() {
         }
@@ -101,6 +109,11 @@ public class UpdateProfile {
             return this;
         }
 
+        public Builder withMobileCoinAddress(final byte[] val) {
+            mobileCoinAddress = val;
+            return this;
+        }
+
         public UpdateProfile build() {
             return new UpdateProfile(this);
         }
index 1a876d7ec4d1826b52bc0ff760f94d2fc5615483..cc01dc73bb822e2903ddc5d4a6c0a5f7798a0a05 100644 (file)
@@ -64,7 +64,7 @@ public final class ProfileHelper {
         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();
@@ -144,9 +144,14 @@ public final class ProfileHelper {
      * @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(
@@ -156,7 +161,8 @@ public final class ProfileHelper {
             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);
@@ -172,6 +178,9 @@ public final class ProfileHelper {
         if (aboutEmoji != null) {
             builder.withAboutEmoji(aboutEmoji);
         }
+        if (mobileCoinAddress != null) {
+            builder.withMobileCoinAddress(mobileCoinAddress);
+        }
         var newProfile = builder.build();
 
         if (uploadProfile) {
index 469ca02e57954afdc4b6bad252229140125cfdc8..88fe84b90c72b654f5e0aadcf9d3f7dd02b13262 100644 (file)
@@ -234,6 +234,7 @@ public class StorageHelper {
                         accountRecord.getFamilyName().orElse(null),
                         null,
                         null,
+                        null,
                         null);
     }
 
index 1cebd044fb0addd3eecf02a8be0508a605868d9c..456c6f1a772442cc12a13e3f683d6fc0bf47d6c2 100644 (file)
@@ -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.
index 1edb6df985ced69758327e8f19042d5b3ac0da65..d8e874302de747bd2f06a85c3f6a688a8a442627 100644 (file)
@@ -12,6 +12,7 @@ import org.asamk.signal.output.OutputWriter;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Base64;
 
 public class UpdateProfileCommand implements JsonRpcLocalCommand {
 
@@ -27,6 +28,7 @@ public class UpdateProfileCommand implements JsonRpcLocalCommand {
         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");
@@ -41,9 +43,13 @@ public class UpdateProfileCommand implements JsonRpcLocalCommand {
         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 {
@@ -52,6 +58,7 @@ public class UpdateProfileCommand implements JsonRpcLocalCommand {
                     .withFamilyName(familyName)
                     .withAbout(about)
                     .withAboutEmoji(aboutEmoji)
+                    .withMobileCoinAddress(mobileCoinAddress)
                     .withAvatar(avatarFile)
                     .withDeleteAvatar(removeAvatar)
                     .build());