mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Merge profile commands to a single UpdateProfileCommand
This commit is contained in:
parent
abb6ebc910
commit
958d10fcd1
6 changed files with 89 additions and 89 deletions
|
@ -208,20 +208,21 @@ number::
|
||||||
Specify the safety number or fingerprint of the key, only use this option if you have verified
|
Specify the safety number or fingerprint of the key, only use this option if you have verified
|
||||||
the fingerprint.
|
the fingerprint.
|
||||||
|
|
||||||
setProfileName
|
updateProfile
|
||||||
--------------
|
--------------
|
||||||
Update the name visible by message recipients for the current users.
|
Update the name and/or avatar image visible by message recipients for the current users.
|
||||||
|
The profile is stored encrypted on the Signal servers. The decryption key is sent
|
||||||
|
with every outgoing messages (excluding group messages).
|
||||||
|
|
||||||
name::
|
*--name*::
|
||||||
New name visible by message recipients.
|
New name visible by message recipients.
|
||||||
|
|
||||||
setProfileAvatar
|
*--avatar*::
|
||||||
----------------
|
|
||||||
Update the avatar visible by message recipients for the current users.
|
|
||||||
|
|
||||||
avatar::
|
|
||||||
Path to the new avatar visible by message recipients.
|
Path to the new avatar visible by message recipients.
|
||||||
|
|
||||||
|
*--remove-avatar*::
|
||||||
|
Remove the avatar visible by message recipients.
|
||||||
|
|
||||||
daemon
|
daemon
|
||||||
~~~~~~
|
~~~~~~
|
||||||
signal-cli can run in daemon mode and provides an experimental dbus interface. For
|
signal-cli can run in daemon mode and provides an experimental dbus interface. For
|
||||||
|
|
|
@ -20,13 +20,12 @@ public class Commands {
|
||||||
addCommand("removeDevice", new RemoveDeviceCommand());
|
addCommand("removeDevice", new RemoveDeviceCommand());
|
||||||
addCommand("removePin", new RemovePinCommand());
|
addCommand("removePin", new RemovePinCommand());
|
||||||
addCommand("send", new SendCommand());
|
addCommand("send", new SendCommand());
|
||||||
addCommand("setProfileAvatar", new SetProfileAvatarCommand());
|
|
||||||
addCommand("setProfileName", new SetProfileNameCommand());
|
|
||||||
addCommand("setPin", new SetPinCommand());
|
addCommand("setPin", new SetPinCommand());
|
||||||
addCommand("trust", new TrustCommand());
|
addCommand("trust", new TrustCommand());
|
||||||
addCommand("unregister", new UnregisterCommand());
|
addCommand("unregister", new UnregisterCommand());
|
||||||
addCommand("updateAccount", new UpdateAccountCommand());
|
addCommand("updateAccount", new UpdateAccountCommand());
|
||||||
addCommand("updateGroup", new UpdateGroupCommand());
|
addCommand("updateGroup", new UpdateGroupCommand());
|
||||||
|
addCommand("updateProfile", new UpdateProfileCommand());
|
||||||
addCommand("verify", new VerifyCommand());
|
addCommand("verify", new VerifyCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
package org.asamk.signal.commands;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import net.sourceforge.argparse4j.impl.Arguments;
|
||||||
|
import net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup;
|
||||||
|
import net.sourceforge.argparse4j.inf.Namespace;
|
||||||
|
import net.sourceforge.argparse4j.inf.Subparser;
|
||||||
|
import org.asamk.signal.manager.Manager;
|
||||||
|
|
||||||
|
public class UpdateProfileCommand implements LocalCommand {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void attachToSubparser(final Subparser subparser) {
|
||||||
|
final MutuallyExclusiveGroup avatarOptions = subparser.addMutuallyExclusiveGroup();
|
||||||
|
avatarOptions.addArgument("--avatar")
|
||||||
|
.help("Path to new profile avatar");
|
||||||
|
avatarOptions.addArgument("--remove-avatar")
|
||||||
|
.action(Arguments.storeTrue());
|
||||||
|
|
||||||
|
subparser.addArgument("--name")
|
||||||
|
.help("New profile name");
|
||||||
|
|
||||||
|
subparser.help("Set a name and/or avatar image for the user 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");
|
||||||
|
|
||||||
|
if (name != null) {
|
||||||
|
try {
|
||||||
|
m.setProfileName(name);
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("UpdateAccount error: " + e.getMessage());
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String avatarPath = ns.getString("avatar");
|
||||||
|
|
||||||
|
if (avatarPath != null) {
|
||||||
|
File avatarFile = new File(avatarPath);
|
||||||
|
|
||||||
|
try {
|
||||||
|
m.setProfileAvatar(avatarFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("UpdateAccount error: " + e.getMessage());
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean removeAvatar = ns.getBoolean("remove_avatar");
|
||||||
|
|
||||||
|
if (removeAvatar) {
|
||||||
|
try {
|
||||||
|
m.removeProfileAvatar();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("UpdateAccount error: " + e.getMessage());
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -210,7 +210,13 @@ public class Manager implements Signal {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProfileAvatar(File avatar) throws IOException {
|
public void setProfileAvatar(File avatar) throws IOException {
|
||||||
accountManager.setProfileAvatar(account.getProfileKey(), Utils.createStreamDetailsFromFile(avatar));
|
final StreamDetails streamDetails = Utils.createStreamDetailsFromFile(avatar);
|
||||||
|
accountManager.setProfileAvatar(account.getProfileKey(), streamDetails);
|
||||||
|
streamDetails.getStream().close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeProfileAvatar() throws IOException {
|
||||||
|
accountManager.setProfileAvatar(account.getProfileKey(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unregister() throws IOException {
|
public void unregister() throws IOException {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue