Add commands to update profile name and avatar

Two new commands are added `setProfileName` and `setProfileAvatar` which
allow to update the name and avatar visible by other users for the
current profiles.

Closes #227
This commit is contained in:
Jérémy Bobbio 2019-09-24 19:22:14 +02:00 committed by AsamK
parent c53bb132eb
commit abb6ebc910
6 changed files with 113 additions and 0 deletions

View file

@ -20,6 +20,8 @@ public class Commands {
addCommand("removeDevice", new RemoveDeviceCommand());
addCommand("removePin", new RemovePinCommand());
addCommand("send", new SendCommand());
addCommand("setProfileAvatar", new SetProfileAvatarCommand());
addCommand("setProfileName", new SetProfileNameCommand());
addCommand("setPin", new SetPinCommand());
addCommand("trust", new TrustCommand());
addCommand("unregister", new UnregisterCommand());

View file

@ -0,0 +1,40 @@
package org.asamk.signal.commands;
import java.io.IOException;
import java.io.File;
import net.sourceforge.argparse4j.impl.Arguments;
import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.manager.Manager;
public class SetProfileAvatarCommand implements LocalCommand {
@Override
public void attachToSubparser(final Subparser subparser) {
subparser.addArgument("avatar")
.help("Path to new profile avatar");
subparser.help("Set the avatar for this profile");
}
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.isRegistered()) {
System.err.println("User is not registered.");
return 1;
}
String avatarPath = ns.getString("avatar");
File avatarFile = new File(avatarPath);
try {
m.setProfileAvatar(avatarFile);
} catch (IOException e) {
System.err.println("UpdateAccount error: " + e.getMessage());
return 3;
}
return 0;
}
}

View file

@ -0,0 +1,38 @@
package org.asamk.signal.commands;
import java.io.IOException;
import net.sourceforge.argparse4j.impl.Arguments;
import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.manager.Manager;
public class SetProfileNameCommand implements LocalCommand {
@Override
public void attachToSubparser(final Subparser subparser) {
subparser.addArgument("name")
.help("New profile name");
subparser.help("Set a new name for this profile");
}
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (!m.isRegistered()) {
System.err.println("User is not registered.");
return 1;
}
String name = ns.getString("name");
try {
m.setProfileName(name);
} catch (IOException e) {
System.err.println("UpdateAccount error: " + e.getMessage());
return 3;
}
return 0;
}
}