}
/**
- * @param avatar if avatar is null the image from the local avatar store is used (if present),
- * if it's Optional.absent(), the avatar will be removed
+ * @param name if null, the previous name will be kept
+ * @param about if null, the previous about text will be kept
+ * @param aboutEmoji if null, the previous about emoji will be kept
+ * @param avatar if avatar is null the image from the local avatar store is used (if present),
+ * if it's Optional.absent(), the avatar will be removed
*/
- public void setProfile(String name, Optional<File> avatar) throws IOException {
- // TODO
- String about = null;
- String aboutEmoji = null;
+ public void setProfile(String name, String about, String aboutEmoji, Optional<File> avatar) throws IOException {
+ SignalProfileEntry profileEntry = account.getProfileStore().getProfileEntry(getSelfAddress());
+ SignalProfile profile = profileEntry == null ? null : profileEntry.getProfile();
+ SignalProfile newProfile = new SignalProfile(profile == null ? null : profile.getIdentityKey(),
+ name != null ? name : profile == null || profile.getName() == null ? "" : profile.getName(),
+ about != null ? about : profile == null || profile.getAbout() == null ? "" : profile.getAbout(),
+ aboutEmoji != null
+ ? aboutEmoji
+ : profile == null || profile.getAboutEmoji() == null ? "" : profile.getAboutEmoji(),
+ profile == null ? null : profile.getUnidentifiedAccess(),
+ account.isUnrestrictedUnidentifiedAccess(),
+ profile == null ? null : profile.getCapabilities());
try (final StreamDetails streamDetails = avatar == null
? avatarStore.retrieveProfileAvatar(getSelfAddress())
: avatar.isPresent() ? Utils.createStreamDetailsFromFile(avatar.get()) : null) {
accountManager.setVersionedProfile(account.getUuid(),
account.getProfileKey(),
- name,
- about,
- aboutEmoji,
+ newProfile.getName(),
+ newProfile.getAbout(),
+ newProfile.getAboutEmoji(),
streamDetails);
}
avatarStore.deleteProfileAvatar(getSelfAddress());
}
}
+ account.getProfileStore()
+ .updateProfile(getSelfAddress(),
+ account.getProfileKey(),
+ System.currentTimeMillis(),
+ newProfile,
+ profileEntry == null ? null : profileEntry.getProfileKeyCredential());
try {
sendSyncMessage(SignalServiceSyncMessage.forFetchLatest(SignalServiceSyncMessage.FetchType.LOCAL_PROFILE));
@JsonProperty
private final String name;
+ @JsonProperty
+ private final String about;
+
+ @JsonProperty
+ private final String aboutEmoji;
+
@JsonProperty
private final String unidentifiedAccess;
public SignalProfile(
final String identityKey,
final String name,
+ final String about,
+ final String aboutEmoji,
final String unidentifiedAccess,
final boolean unrestrictedUnidentifiedAccess,
final SignalServiceProfile.Capabilities capabilities
) {
this.identityKey = identityKey;
this.name = name;
+ this.about = about;
+ this.aboutEmoji = aboutEmoji;
this.unidentifiedAccess = unidentifiedAccess;
this.unrestrictedUnidentifiedAccess = unrestrictedUnidentifiedAccess;
this.capabilities = new Capabilities();
public SignalProfile(
@JsonProperty("identityKey") final String identityKey,
@JsonProperty("name") final String name,
+ @JsonProperty("about") final String about,
+ @JsonProperty("aboutEmoji") final String aboutEmoji,
@JsonProperty("unidentifiedAccess") final String unidentifiedAccess,
@JsonProperty("unrestrictedUnidentifiedAccess") final boolean unrestrictedUnidentifiedAccess,
@JsonProperty("capabilities") final Capabilities capabilities
) {
this.identityKey = identityKey;
this.name = name;
+ this.about = about;
+ this.aboutEmoji = aboutEmoji;
this.unidentifiedAccess = unidentifiedAccess;
this.unrestrictedUnidentifiedAccess = unrestrictedUnidentifiedAccess;
this.capabilities = capabilities;
return name;
}
+ public String getAbout() {
+ return about;
+ }
+
+ public String getAboutEmoji() {
+ return aboutEmoji;
+ }
+
public String getUnidentifiedAccess() {
return unidentifiedAccess;
}
+ ", name='"
+ name
+ '\''
- + ", avatarFile="
+ + ", about='"
+ + about
+ + '\''
+ + ", aboutEmoji='"
+ + aboutEmoji
+ + '\''
+ ", unidentifiedAccess='"
+ unidentifiedAccess
+ '\''
) {
ProfileCipher profileCipher = new ProfileCipher(profileKey);
try {
- String name;
- try {
- name = encryptedProfile.getName() == null
- ? null
- : new String(profileCipher.decryptName(Base64.getDecoder().decode(encryptedProfile.getName())));
- } catch (IllegalArgumentException e) {
- name = null;
- }
+ String name = decryptName(encryptedProfile.getName(), profileCipher);
+ String about = decryptName(encryptedProfile.getAbout(), profileCipher);
+ String aboutEmoji = decryptName(encryptedProfile.getAboutEmoji(), profileCipher);
String unidentifiedAccess;
try {
unidentifiedAccess = encryptedProfile.getUnidentifiedAccess() == null
}
return new SignalProfile(encryptedProfile.getIdentityKey(),
name,
+ about,
+ aboutEmoji,
unidentifiedAccess,
encryptedProfile.isUnrestrictedUnidentifiedAccess(),
encryptedProfile.getCapabilities());
return null;
}
}
+
+ private static String decryptName(
+ final String encryptedName, final ProfileCipher profileCipher
+ ) throws InvalidCiphertextException {
+ try {
+ return encryptedName == null
+ ? null
+ : new String(profileCipher.decryptName(Base64.getDecoder().decode(encryptedName)));
+ } catch (IllegalArgumentException e) {
+ return null;
+ }
+ }
}
@Override
public void attachToSubparser(final Subparser subparser) {
+ subparser.addArgument("--name").help("New profile name");
+ subparser.addArgument("--about").help("New profile about text");
+ subparser.addArgument("--about-emoji").help("New profile about emoji");
+
final MutuallyExclusiveGroup avatarOptions = subparser.addMutuallyExclusiveGroup();
avatarOptions.addArgument("--avatar").help("Path to new profile avatar");
avatarOptions.addArgument("--remove-avatar").action(Arguments.storeTrue());
- subparser.addArgument("--name").required(true).help("New profile name");
-
- subparser.help("Set a name and avatar image for the user profile");
+ subparser.help("Set a name, about and avatar image for the user profile");
}
@Override
public int handleCommand(final Namespace ns, final Manager m) {
String name = ns.getString("name");
+ String about = ns.getString("about");
+ String aboutEmoji = ns.getString("about_emoji");
String avatarPath = ns.getString("avatar");
boolean removeAvatar = ns.getBoolean("remove_avatar");
Optional<File> avatarFile = removeAvatar
? Optional.absent()
: avatarPath == null ? null : Optional.of(new File(avatarPath));
- m.setProfile(name, avatarFile);
+ m.setProfile(name, about, aboutEmoji, avatarFile);
} catch (IOException e) {
System.err.println("UpdateAccount error: " + e.getMessage());
return 3;