Remove workaround for getBoolean from JsonRpcLocalCommand

This commit is contained in:
AsamK 2021-09-30 19:33:57 +02:00
parent f44b148946
commit c9f5550d18
17 changed files with 22 additions and 31 deletions

View file

@ -117,8 +117,8 @@ public class App {
var username = ns.getString("username"); var username = ns.getString("username");
final var useDbus = ns.getBoolean("dbus"); final var useDbus = Boolean.TRUE.equals(ns.getBoolean("dbus"));
final var useDbusSystem = ns.getBoolean("dbus-system"); final var useDbusSystem = Boolean.TRUE.equals(ns.getBoolean("dbus-system"));
if (useDbus || useDbusSystem) { if (useDbus || useDbusSystem) {
// If username is null, it will connect to the default object path // If username is null, it will connect to the default object path
initDbusClient(command, username, useDbusSystem, outputWriter); initDbusClient(command, username, useDbusSystem, outputWriter);

View file

@ -80,7 +80,7 @@ public class Main {
return false; return false;
} }
return ns.getBoolean("verbose"); return Boolean.TRUE.equals(ns.getBoolean("verbose"));
} }
private static void configureLogging(final boolean verbose) { private static void configureLogging(final boolean verbose) {

View file

@ -54,10 +54,10 @@ public class DaemonCommand implements MultiLocalCommand {
public void handleCommand( public void handleCommand(
final Namespace ns, final Manager m, final OutputWriter outputWriter final Namespace ns, final Manager m, final OutputWriter outputWriter
) throws CommandException { ) throws CommandException {
boolean ignoreAttachments = ns.getBoolean("ignore-attachments"); boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
DBusConnection.DBusBusType busType; DBusConnection.DBusBusType busType;
if (ns.getBoolean("system")) { if (Boolean.TRUE.equals(ns.getBoolean("system"))) {
busType = DBusConnection.DBusBusType.SYSTEM; busType = DBusConnection.DBusBusType.SYSTEM;
} else { } else {
busType = DBusConnection.DBusBusType.SESSION; busType = DBusConnection.DBusBusType.SESSION;
@ -83,10 +83,10 @@ public class DaemonCommand implements MultiLocalCommand {
public void handleCommand( public void handleCommand(
final Namespace ns, final List<Manager> managers, final SignalCreator c, final OutputWriter outputWriter final Namespace ns, final List<Manager> managers, final SignalCreator c, final OutputWriter outputWriter
) throws CommandException { ) throws CommandException {
boolean ignoreAttachments = ns.getBoolean("ignore-attachments"); boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
DBusConnection.DBusBusType busType; DBusConnection.DBusBusType busType;
if (ns.getBoolean("system")) { if (Boolean.TRUE.equals(ns.getBoolean("system"))) {
busType = DBusConnection.DBusBusType.SYSTEM; busType = DBusConnection.DBusBusType.SYSTEM;
} else { } else {
busType = DBusConnection.DBusBusType.SESSION; busType = DBusConnection.DBusBusType.SESSION;

View file

@ -65,7 +65,7 @@ public class JsonRpcDispatcherCommand implements LocalCommand {
public void handleCommand( public void handleCommand(
final Namespace ns, final Manager m, final OutputWriter outputWriter final Namespace ns, final Manager m, final OutputWriter outputWriter
) throws CommandException { ) throws CommandException {
final boolean ignoreAttachments = ns.getBoolean("ignore-attachments"); final boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
final var objectMapper = Util.createJsonObjectMapper(); final var objectMapper = Util.createJsonObjectMapper();
final var jsonRpcSender = new JsonRpcSender((JsonWriter) outputWriter); final var jsonRpcSender = new JsonRpcSender((JsonWriter) outputWriter);

View file

@ -64,14 +64,5 @@ public interface JsonRpcLocalCommand extends JsonRpcCommand<Map<String, Object>>
return super.getList(dest + "s"); return super.getList(dest + "s");
} }
@Override
public Boolean getBoolean(String dest) {
Boolean maybeGotten = this.get(dest);
if (maybeGotten == null) {
maybeGotten = false;
}
return maybeGotten;
}
} }
} }

View file

@ -102,7 +102,7 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
jsonWriter.write(jsonGroups); jsonWriter.write(jsonGroups);
} else { } else {
final var writer = (PlainTextWriter) outputWriter; final var writer = (PlainTextWriter) outputWriter;
boolean detailed = ns.getBoolean("detailed"); boolean detailed = Boolean.TRUE.equals(ns.getBoolean("detailed"));
for (var group : groups) { for (var group : groups) {
printGroupPlainText(writer, group, detailed); printGroupPlainText(writer, group, detailed);
} }

View file

@ -61,7 +61,7 @@ public class QuitGroupCommand implements JsonRpcLocalCommand {
} catch (NotAGroupMemberException e) { } catch (NotAGroupMemberException e) {
logger.info("User is not a group member"); logger.info("User is not a group member");
} }
if (ns.getBoolean("delete")) { if (Boolean.TRUE.equals(ns.getBoolean("delete"))) {
logger.debug("Deleting group {}", groupId); logger.debug("Deleting group {}", groupId);
m.deleteGroup(groupId); m.deleteGroup(groupId);
} }

View file

@ -147,7 +147,7 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
returnOnTimeout = false; returnOnTimeout = false;
timeout = 3600; timeout = 3600;
} }
boolean ignoreAttachments = ns.getBoolean("ignore-attachments"); boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
try { try {
final var handler = outputWriter instanceof JsonWriter ? new JsonReceiveMessageHandler(m, final var handler = outputWriter instanceof JsonWriter ? new JsonReceiveMessageHandler(m,
(JsonWriter) outputWriter) : new ReceiveMessageHandler(m, (PlainTextWriter) outputWriter); (JsonWriter) outputWriter) : new ReceiveMessageHandler(m, (PlainTextWriter) outputWriter);

View file

@ -31,7 +31,7 @@ public class RegisterCommand implements RegistrationCommand {
@Override @Override
public void handleCommand(final Namespace ns, final RegistrationManager m) throws CommandException { public void handleCommand(final Namespace ns, final RegistrationManager m) throws CommandException {
final boolean voiceVerification = ns.getBoolean("voice"); final boolean voiceVerification = Boolean.TRUE.equals(ns.getBoolean("voice"));
final var captchaString = ns.getString("captcha"); final var captchaString = ns.getString("captcha");
final var captcha = captchaString == null ? null : captchaString.replace("signalcaptcha://", ""); final var captcha = captchaString == null ? null : captchaString.replace("signalcaptcha://", "");

View file

@ -43,7 +43,7 @@ public class RemoteDeleteCommand implements JsonRpcLocalCommand {
public void handleCommand( public void handleCommand(
final Namespace ns, final Manager m, final OutputWriter outputWriter final Namespace ns, final Manager m, final OutputWriter outputWriter
) throws CommandException { ) throws CommandException {
final var isNoteToSelf = ns.getBoolean("note-to-self"); final var isNoteToSelf = Boolean.TRUE.equals(ns.getBoolean("note-to-self"));
final var recipientStrings = ns.<String>getList("recipient"); final var recipientStrings = ns.<String>getList("recipient");
final var groupIdStrings = ns.<String>getList("group-id"); final var groupIdStrings = ns.<String>getList("group-id");

View file

@ -58,7 +58,7 @@ public class SendCommand implements JsonRpcLocalCommand {
public void handleCommand( public void handleCommand(
final Namespace ns, final Manager m, final OutputWriter outputWriter final Namespace ns, final Manager m, final OutputWriter outputWriter
) throws CommandException { ) throws CommandException {
final var isNoteToSelf = ns.getBoolean("note-to-self"); final var isNoteToSelf = Boolean.TRUE.equals(ns.getBoolean("note-to-self"));
final var recipientStrings = ns.<String>getList("recipient"); final var recipientStrings = ns.<String>getList("recipient");
final var groupIdStrings = ns.<String>getList("group-id"); final var groupIdStrings = ns.<String>getList("group-id");
@ -67,7 +67,7 @@ public class SendCommand implements JsonRpcLocalCommand {
recipientStrings, recipientStrings,
groupIdStrings); groupIdStrings);
final var isEndSession = ns.getBoolean("end-session"); final var isEndSession = Boolean.TRUE.equals(ns.getBoolean("end-session"));
if (isEndSession) { if (isEndSession) {
final var singleRecipients = recipientIdentifiers.stream() final var singleRecipients = recipientIdentifiers.stream()
.filter(r -> r instanceof RecipientIdentifier.Single) .filter(r -> r instanceof RecipientIdentifier.Single)

View file

@ -52,7 +52,7 @@ public class SendReactionCommand implements JsonRpcLocalCommand {
public void handleCommand( public void handleCommand(
final Namespace ns, final Manager m, final OutputWriter outputWriter final Namespace ns, final Manager m, final OutputWriter outputWriter
) throws CommandException { ) throws CommandException {
final var isNoteToSelf = ns.getBoolean("note-to-self"); final var isNoteToSelf = Boolean.TRUE.equals(ns.getBoolean("note-to-self"));
final var recipientStrings = ns.<String>getList("recipient"); final var recipientStrings = ns.<String>getList("recipient");
final var groupIdStrings = ns.<String>getList("group-id"); final var groupIdStrings = ns.<String>getList("group-id");
@ -62,7 +62,7 @@ public class SendReactionCommand implements JsonRpcLocalCommand {
groupIdStrings); groupIdStrings);
final var emoji = ns.getString("emoji"); final var emoji = ns.getString("emoji");
final var isRemove = ns.getBoolean("remove"); final var isRemove = Boolean.TRUE.equals(ns.getBoolean("remove"));
final var targetAuthor = ns.getString("target-author"); final var targetAuthor = ns.getString("target-author");
final var targetTimestamp = ns.getLong("target-timestamp"); final var targetTimestamp = ns.getLong("target-timestamp");

View file

@ -41,7 +41,7 @@ public class SendTypingCommand implements JsonRpcLocalCommand {
) throws CommandException { ) throws CommandException {
final var recipientStrings = ns.<String>getList("recipient"); final var recipientStrings = ns.<String>getList("recipient");
final var groupIdStrings = ns.<String>getList("group-id"); final var groupIdStrings = ns.<String>getList("group-id");
final var action = ns.getBoolean("stop") ? TypingAction.STOP : TypingAction.START; final var action = Boolean.TRUE.equals(ns.getBoolean("stop")) ? TypingAction.STOP : TypingAction.START;
final var recipientIdentifiers = new HashSet<RecipientIdentifier>(); final var recipientIdentifiers = new HashSet<RecipientIdentifier>();
if (recipientStrings != null) { if (recipientStrings != null) {

View file

@ -39,7 +39,7 @@ public class TrustCommand implements JsonRpcLocalCommand {
) throws CommandException { ) throws CommandException {
var recipentString = ns.getString("recipient"); var recipentString = ns.getString("recipient");
var recipient = CommandUtil.getSingleRecipientIdentifier(recipentString, m.getSelfNumber()); var recipient = CommandUtil.getSingleRecipientIdentifier(recipentString, m.getSelfNumber());
if (ns.getBoolean("trust-all-known-keys")) { if (Boolean.TRUE.equals(ns.getBoolean("trust-all-known-keys"))) {
boolean res = m.trustIdentityAllKeys(recipient); boolean res = m.trustIdentityAllKeys(recipient);
if (!res) { if (!res) {
throw new UserErrorException("Failed to set the trust for this number, make sure the number is correct."); throw new UserErrorException("Failed to set the trust for this number, make sure the number is correct.");

View file

@ -31,7 +31,7 @@ public class UnregisterCommand implements LocalCommand {
final Namespace ns, final Manager m, final OutputWriter outputWriter final Namespace ns, final Manager m, final OutputWriter outputWriter
) throws CommandException { ) throws CommandException {
try { try {
if (ns.getBoolean("delete-account")) { if (Boolean.TRUE.equals(ns.getBoolean("delete-account"))) {
m.deleteAccount(); m.deleteAccount();
} else { } else {
m.unregister(); m.unregister();

View file

@ -121,7 +121,7 @@ public class UpdateGroupCommand implements JsonRpcLocalCommand {
var groupAdmins = CommandUtil.getSingleRecipientIdentifiers(ns.getList("admin"), localNumber); var groupAdmins = CommandUtil.getSingleRecipientIdentifiers(ns.getList("admin"), localNumber);
var groupRemoveAdmins = CommandUtil.getSingleRecipientIdentifiers(ns.getList("remove-admin"), localNumber); var groupRemoveAdmins = CommandUtil.getSingleRecipientIdentifiers(ns.getList("remove-admin"), localNumber);
var groupAvatar = ns.getString("avatar"); var groupAvatar = ns.getString("avatar");
var groupResetLink = ns.getBoolean("reset-link"); var groupResetLink = Boolean.TRUE.equals(ns.getBoolean("reset-link"));
var groupLinkState = getGroupLinkState(ns.getString("link")); var groupLinkState = getGroupLinkState(ns.getString("link"));
var groupExpiration = ns.getInt("expiration"); var groupExpiration = ns.getInt("expiration");
var groupAddMemberPermission = getGroupPermission(ns.getString("set-permission-add-member")); var groupAddMemberPermission = getGroupPermission(ns.getString("set-permission-add-member"));

View file

@ -42,7 +42,7 @@ public class UpdateProfileCommand implements JsonRpcLocalCommand {
var about = ns.getString("about"); var about = ns.getString("about");
var aboutEmoji = ns.getString("about-emoji"); var aboutEmoji = ns.getString("about-emoji");
var avatarPath = ns.getString("avatar"); var avatarPath = ns.getString("avatar");
boolean removeAvatar = ns.getBoolean("remove-avatar"); boolean removeAvatar = Boolean.TRUE.equals(ns.getBoolean("remove-avatar"));
Optional<File> avatarFile = removeAvatar Optional<File> avatarFile = removeAvatar
? Optional.absent() ? Optional.absent()