Extend updateProfile command to set family name

This commit is contained in:
AsamK 2021-05-05 19:32:52 +02:00
parent 3d361d54bb
commit b7f05a1c80
5 changed files with 34 additions and 18 deletions

View file

@ -354,18 +354,22 @@ public class Manager implements Closeable {
}
/**
* @param name if null, the previous name will be kept
* @param givenName if null, the previous givenName will be kept
* @param familyName if null, the previous familyName 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, String about, String aboutEmoji, Optional<File> avatar) throws IOException {
public void setProfile(
String givenName, final String familyName, String about, String aboutEmoji, Optional<File> avatar
) throws IOException {
var profile = getRecipientProfile(account.getSelfRecipientId());
var builder = profile == null ? Profile.newBuilder() : Profile.newBuilder(profile);
if (name != null) {
builder.withGivenName(name);
builder.withFamilyName(null);
if (givenName != null) {
builder.withGivenName(givenName);
}
if (familyName != null) {
builder.withFamilyName(familyName);
}
if (about != null) {
builder.withAbout(about);

View file

@ -162,7 +162,7 @@ public class RegistrationManager implements Closeable {
m.refreshPreKeys();
// Set an initial empty profile so user can be added to groups
m.setProfile(null, null, null, null);
m.setProfile(null, null, null, null, null);
final var result = m;
m = null;

View file

@ -289,18 +289,28 @@ Specify the safety number of the key, only use this option if you have verified
=== updateProfile
Update the name and avatar image visible by message recipients for the current users.
Update the profile information shown to message recipients.
The profile is stored encrypted on the Signal servers.
The decryption key is sent with every outgoing messages to contacts.
The decryption key is sent with every outgoing messages to contacts and included
in every group.
*--name*::
New name visible by message recipients.
*--given-name* NAME, *--name* NAME::
New (given) name.
*--avatar*::
Path to the new avatar visible by message recipients.
*--family-name* FAMILY_NAME::
New family name.
*--about* ABOUT_TEXT::
New profile status text.
*--about-emoji* EMOJI::
New profile status emoji.
*--avatar* AVATAR_FILE::
Path to the new avatar image file.
*--remove-avatar*::
Remove the avatar visible by message recipients.
Remove the avatar
=== updateContact

View file

@ -16,7 +16,8 @@ public class UpdateProfileCommand implements LocalCommand {
@Override
public void attachToSubparser(final Subparser subparser) {
subparser.addArgument("--name").help("New profile name");
subparser.addArgument("--given-name", "--name").help("New profile (given) name");
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");
@ -29,7 +30,8 @@ public class UpdateProfileCommand implements LocalCommand {
@Override
public void handleCommand(final Namespace ns, final Manager m) throws CommandException {
var name = ns.getString("name");
var givenName = ns.getString("given_name");
var familyName = ns.getString("family_name");
var about = ns.getString("about");
var aboutEmoji = ns.getString("about_emoji");
var avatarPath = ns.getString("avatar");
@ -40,7 +42,7 @@ public class UpdateProfileCommand implements LocalCommand {
: avatarPath == null ? null : Optional.of(new File(avatarPath));
try {
m.setProfile(name, about, aboutEmoji, avatarFile);
m.setProfile(givenName, familyName, about, aboutEmoji, avatarFile);
} catch (IOException e) {
throw new IOErrorException("Update profile error: " + e.getMessage());
}

View file

@ -372,7 +372,7 @@ public class DbusSignalImpl implements Signal {
Optional<File> avatarFile = removeAvatar
? Optional.absent()
: avatarPath == null ? null : Optional.of(new File(avatarPath));
m.setProfile(name, about, aboutEmoji, avatarFile);
m.setProfile(name, null, about, aboutEmoji, avatarFile);
} catch (IOException e) {
throw new Error.Failure(e.getMessage());
}