Use var instead of explicit types

This commit is contained in:
AsamK 2021-02-21 15:01:41 +01:00
parent 03c30519b1
commit de273586b4
77 changed files with 850 additions and 1017 deletions

View file

@ -4,7 +4,6 @@ import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.groups.GroupId;
import org.asamk.signal.manager.groups.GroupIdFormatException;
import org.asamk.signal.manager.groups.GroupNotFoundException;
import org.asamk.signal.util.Util;
@ -21,7 +20,7 @@ public class BlockCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
for (String contact_number : ns.<String>getList("contact")) {
for (var contact_number : ns.<String>getList("contact")) {
try {
m.setContactBlocked(contact_number, true);
} catch (InvalidNumberException e) {
@ -30,9 +29,9 @@ public class BlockCommand implements LocalCommand {
}
if (ns.<String>getList("group") != null) {
for (String groupIdString : ns.<String>getList("group")) {
for (var groupIdString : ns.<String>getList("group")) {
try {
GroupId groupId = Util.decodeGroupId(groupIdString);
var groupId = Util.decodeGroupId(groupIdString);
m.setGroupBlocked(groupId, true);
} catch (GroupIdFormatException | GroupNotFoundException e) {
System.err.println(e.getMessage());

View file

@ -45,7 +45,7 @@ public class DaemonCommand implements MultiLocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
boolean inJson = ns.get("output") == OutputType.JSON || ns.getBoolean("json");
var inJson = ns.get("output") == OutputType.JSON || ns.getBoolean("json");
// TODO delete later when "json" variable is removed
if (ns.getBoolean("json")) {
@ -61,9 +61,9 @@ public class DaemonCommand implements MultiLocalCommand {
busType = DBusConnection.DBusBusType.SESSION;
}
try (DBusConnection conn = DBusConnection.getConnection(busType)) {
String objectPath = DbusConfig.getObjectPath();
Thread t = run(conn, objectPath, m, ignoreAttachments, inJson);
try (var conn = DBusConnection.getConnection(busType)) {
var objectPath = DbusConfig.getObjectPath();
var t = run(conn, objectPath, m, ignoreAttachments, inJson);
conn.requestBusName(DbusConfig.getBusname());
@ -80,7 +80,7 @@ public class DaemonCommand implements MultiLocalCommand {
@Override
public int handleCommand(final Namespace ns, final List<Manager> managers) {
boolean inJson = ns.get("output") == OutputType.JSON || ns.getBoolean("json");
var inJson = ns.get("output") == OutputType.JSON || ns.getBoolean("json");
// TODO delete later when "json" variable is removed
if (ns.getBoolean("json")) {
@ -96,17 +96,17 @@ public class DaemonCommand implements MultiLocalCommand {
busType = DBusConnection.DBusBusType.SESSION;
}
try (DBusConnection conn = DBusConnection.getConnection(busType)) {
List<Thread> receiveThreads = new ArrayList<>();
for (Manager m : managers) {
String objectPath = DbusConfig.getObjectPath(m.getUsername());
Thread thread = run(conn, objectPath, m, ignoreAttachments, inJson);
try (var conn = DBusConnection.getConnection(busType)) {
var receiveThreads = new ArrayList<Thread>();
for (var m : managers) {
var objectPath = DbusConfig.getObjectPath(m.getUsername());
var thread = run(conn, objectPath, m, ignoreAttachments, inJson);
receiveThreads.add(thread);
}
conn.requestBusName(DbusConfig.getBusname());
for (Thread t : receiveThreads) {
for (var t : receiveThreads) {
try {
t.join();
} catch (InterruptedException ignored) {
@ -124,7 +124,7 @@ public class DaemonCommand implements MultiLocalCommand {
) throws DBusException {
conn.exportObject(objectPath, new DbusSignalImpl(m));
final Thread thread = new Thread(() -> {
final var thread = new Thread(() -> {
while (true) {
try {
m.receiveMessages(1,

View file

@ -12,7 +12,6 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
@ -38,7 +37,7 @@ public class GetUserStatusCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
// Setup the json object mapper
boolean inJson = ns.get("output") == OutputType.JSON || ns.getBoolean("json");
var inJson = ns.get("output") == OutputType.JSON || ns.getBoolean("json");
// TODO delete later when "json" variable is removed
if (ns.getBoolean("json")) {
@ -56,9 +55,9 @@ public class GetUserStatusCommand implements LocalCommand {
// Output
if (inJson) {
final JsonWriter jsonWriter = new JsonWriter(System.out);
final var jsonWriter = new JsonWriter(System.out);
List<JsonUserStatus> jsonUserStatuses = registered.entrySet()
var jsonUserStatuses = registered.entrySet()
.stream()
.map(entry -> new JsonUserStatus(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());
@ -70,7 +69,7 @@ public class GetUserStatusCommand implements LocalCommand {
return 3;
}
} else {
for (Map.Entry<String, Boolean> entry : registered.entrySet()) {
for (var entry : registered.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue());
}
}

View file

@ -4,16 +4,12 @@ import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.groups.GroupId;
import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
import org.freedesktop.dbus.exceptions.DBusExecutionException;
import org.whispersystems.libsignal.util.Pair;
import org.whispersystems.signalservice.api.groupsv2.GroupLinkNotActiveException;
import org.whispersystems.signalservice.api.messages.SendMessageResult;
import org.whispersystems.signalservice.internal.push.exceptions.GroupPatchNotAcceptedException;
import java.io.IOException;
import java.util.List;
import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
import static org.asamk.signal.util.ErrorUtils.handleIOException;
@ -29,7 +25,7 @@ public class JoinGroupCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
final GroupInviteLinkUrl linkUrl;
String uri = ns.getString("uri");
var uri = ns.getString("uri");
try {
linkUrl = GroupInviteLinkUrl.fromUri(uri);
} catch (GroupInviteLinkUrl.InvalidGroupLinkException e) {
@ -46,8 +42,8 @@ public class JoinGroupCommand implements LocalCommand {
}
try {
final Pair<GroupId, List<SendMessageResult>> results = m.joinGroup(linkUrl);
GroupId newGroupId = results.first();
final var results = m.joinGroup(linkUrl);
var newGroupId = results.first();
if (!m.getGroup(newGroupId).isMember(m.getSelfAddress())) {
System.out.println("Requested to join group \"" + newGroupId.toBase64() + "\"");
} else {

View file

@ -21,13 +21,13 @@ public class LinkCommand implements ProvisioningCommand {
@Override
public int handleCommand(final Namespace ns, final ProvisioningManager m) {
String deviceName = ns.getString("name");
var deviceName = ns.getString("name");
if (deviceName == null) {
deviceName = "cli";
}
try {
System.out.println(m.getDeviceLinkUri());
String username = m.finishDeviceLink(deviceName);
var username = m.finishDeviceLink(deviceName);
System.out.println("Associated with: " + username);
} catch (TimeoutException e) {
System.err.println("Link request timed out, please try again.");

View file

@ -4,9 +4,6 @@ import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.storage.contacts.ContactInfo;
import java.util.List;
public class ListContactsCommand implements LocalCommand {
@ -16,8 +13,8 @@ public class ListContactsCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
List<ContactInfo> contacts = m.getContacts();
for (ContactInfo c : contacts) {
var contacts = m.getContacts();
for (var c : contacts) {
System.out.println(String.format("Number: %s Name: %s Blocked: %b", c.number, c.name, c.blocked));
}
return 0;

View file

@ -5,10 +5,8 @@ import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.util.DateUtils;
import org.whispersystems.signalservice.api.messages.multidevice.DeviceInfo;
import java.io.IOException;
import java.util.List;
public class ListDevicesCommand implements LocalCommand {
@ -19,8 +17,8 @@ public class ListDevicesCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
try {
List<DeviceInfo> devices = m.getLinkedDevices();
for (DeviceInfo d : devices) {
var devices = m.getLinkedDevices();
for (var d : devices) {
System.out.println("Device "
+ d.getId()
+ (d.getId() == m.getDeviceId() ? " (this device)" : "")

View file

@ -7,7 +7,6 @@ import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.JsonWriter;
import org.asamk.signal.OutputType;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
import org.asamk.signal.manager.storage.groups.GroupInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -15,7 +14,6 @@ import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@ -32,7 +30,7 @@ public class ListGroupsCommand implements LocalCommand {
private static void printGroupPlainText(Manager m, GroupInfo group, boolean detailed) {
if (detailed) {
final GroupInviteLinkUrl groupInviteLink = group.getGroupInviteLink();
final var groupInviteLink = group.getGroupInviteLink();
System.out.println(String.format(
"Id: %s Name: %s Active: %s Blocked: %b Members: %s Pending members: %s Requesting members: %s Link: %s",
@ -70,11 +68,11 @@ public class ListGroupsCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (ns.get("output") == OutputType.JSON) {
final JsonWriter jsonWriter = new JsonWriter(System.out);
final var jsonWriter = new JsonWriter(System.out);
List<JsonGroup> jsonGroups = new ArrayList<>();
for (GroupInfo group : m.getGroups()) {
final GroupInviteLinkUrl groupInviteLink = group.getGroupInviteLink();
var jsonGroups = new ArrayList<JsonGroup>();
for (var group : m.getGroups()) {
final var groupInviteLink = group.getGroupInviteLink();
jsonGroups.add(new JsonGroup(group.getGroupId().toBase64(),
group.getTitle(),
@ -96,7 +94,7 @@ public class ListGroupsCommand implements LocalCommand {
return 0;
} else {
boolean detailed = ns.getBoolean("detailed");
for (GroupInfo group : m.getGroups()) {
for (var group : m.getGroups()) {
printGroupPlainText(m, group, detailed);
}
}

View file

@ -9,12 +9,10 @@ import org.asamk.signal.util.Hex;
import org.asamk.signal.util.Util;
import org.whispersystems.signalservice.api.util.InvalidNumberException;
import java.util.List;
public class ListIdentitiesCommand implements LocalCommand {
private static void printIdentityFingerprint(Manager m, IdentityInfo theirId) {
String digits = Util.formatSafetyNumber(m.computeSafetyNumber(theirId.getAddress(), theirId.getIdentityKey()));
var digits = Util.formatSafetyNumber(m.computeSafetyNumber(theirId.getAddress(), theirId.getIdentityKey()));
System.out.println(String.format("%s: %s Added: %s Fingerprint: %s Safety Number: %s",
theirId.getAddress().getNumber().orNull(),
theirId.getTrustLevel(),
@ -31,14 +29,14 @@ public class ListIdentitiesCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
if (ns.get("number") == null) {
for (IdentityInfo identity : m.getIdentities()) {
for (var identity : m.getIdentities()) {
printIdentityFingerprint(m, identity);
}
} else {
String number = ns.getString("number");
var number = ns.getString("number");
try {
List<IdentityInfo> identities = m.getIdentities(number);
for (IdentityInfo id : identities) {
var identities = m.getIdentities(number);
for (var id : identities) {
printIdentityFingerprint(m, id);
}
} catch (InvalidNumberException e) {

View file

@ -4,16 +4,12 @@ import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.groups.GroupId;
import org.asamk.signal.manager.groups.GroupIdFormatException;
import org.asamk.signal.manager.groups.GroupNotFoundException;
import org.asamk.signal.manager.groups.NotAGroupMemberException;
import org.asamk.signal.util.Util;
import org.whispersystems.libsignal.util.Pair;
import org.whispersystems.signalservice.api.messages.SendMessageResult;
import java.io.IOException;
import java.util.List;
import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
import static org.asamk.signal.util.ErrorUtils.handleGroupIdFormatException;
@ -32,8 +28,8 @@ public class QuitGroupCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
try {
final GroupId groupId = Util.decodeGroupId(ns.getString("group"));
final Pair<Long, List<SendMessageResult>> results = m.sendQuitGroupMessage(groupId);
final var groupId = Util.decodeGroupId(ns.getString("group"));
final var results = m.sendQuitGroupMessage(groupId);
return handleTimestampAndSendMessageResults(results.first(), results.second());
} catch (IOException e) {
handleIOException(e);

View file

@ -48,19 +48,19 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
}
public int handleCommand(final Namespace ns, final Signal signal, DBusConnection dbusconnection) {
boolean inJson = ns.get("output") == OutputType.JSON || ns.getBoolean("json");
var inJson = ns.get("output") == OutputType.JSON || ns.getBoolean("json");
// TODO delete later when "json" variable is removed
if (ns.getBoolean("json")) {
logger.warn("\"--json\" option has been deprecated, please use the global \"--output=json\" instead.");
}
final JsonWriter jsonWriter = inJson ? new JsonWriter(System.out) : null;
final var jsonWriter = inJson ? new JsonWriter(System.out) : null;
try {
dbusconnection.addSigHandler(Signal.MessageReceived.class, messageReceived -> {
if (jsonWriter != null) {
JsonMessageEnvelope envelope = new JsonMessageEnvelope(messageReceived);
final Map<String, JsonMessageEnvelope> object = Map.of("envelope", envelope);
var envelope = new JsonMessageEnvelope(messageReceived);
final var object = Map.of("envelope", envelope);
try {
jsonWriter.write(object);
} catch (IOException e) {
@ -77,7 +77,7 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
}
if (messageReceived.getAttachments().size() > 0) {
System.out.println("Attachments: ");
for (String attachment : messageReceived.getAttachments()) {
for (var attachment : messageReceived.getAttachments()) {
System.out.println("- Stored plaintext in: " + attachment);
}
}
@ -87,8 +87,8 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
dbusconnection.addSigHandler(Signal.ReceiptReceived.class, receiptReceived -> {
if (jsonWriter != null) {
JsonMessageEnvelope envelope = new JsonMessageEnvelope(receiptReceived);
final Map<String, JsonMessageEnvelope> object = Map.of("envelope", envelope);
var envelope = new JsonMessageEnvelope(receiptReceived);
final var object = Map.of("envelope", envelope);
try {
jsonWriter.write(object);
} catch (IOException e) {
@ -103,8 +103,8 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
dbusconnection.addSigHandler(Signal.SyncMessageReceived.class, syncReceived -> {
if (jsonWriter != null) {
JsonMessageEnvelope envelope = new JsonMessageEnvelope(syncReceived);
final Map<String, JsonMessageEnvelope> object = Map.of("envelope", envelope);
var envelope = new JsonMessageEnvelope(syncReceived);
final var object = Map.of("envelope", envelope);
try {
jsonWriter.write(object);
} catch (IOException e) {
@ -122,7 +122,7 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
}
if (syncReceived.getAttachments().size() > 0) {
System.out.println("Attachments: ");
for (String attachment : syncReceived.getAttachments()) {
for (var attachment : syncReceived.getAttachments()) {
System.out.println("- Stored plaintext in: " + attachment);
}
}
@ -144,7 +144,7 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
boolean inJson = ns.get("output") == OutputType.JSON || ns.getBoolean("json");
var inJson = ns.get("output") == OutputType.JSON || ns.getBoolean("json");
// TODO delete later when "json" variable is removed
if (ns.getBoolean("json")) {
@ -155,16 +155,14 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
if (ns.getDouble("timeout") != null) {
timeout = ns.getDouble("timeout");
}
boolean returnOnTimeout = true;
var returnOnTimeout = true;
if (timeout < 0) {
returnOnTimeout = false;
timeout = 3600;
}
boolean ignoreAttachments = ns.getBoolean("ignore_attachments");
try {
final Manager.ReceiveMessageHandler handler = inJson
? new JsonReceiveMessageHandler(m)
: new ReceiveMessageHandler(m);
final var handler = inJson ? new JsonReceiveMessageHandler(m) : new ReceiveMessageHandler(m);
m.receiveMessages((long) (timeout * 1000),
TimeUnit.MILLISECONDS,
returnOnTimeout,

View file

@ -23,7 +23,7 @@ public class RegisterCommand implements RegistrationCommand {
@Override
public int handleCommand(final Namespace ns, final RegistrationManager m) {
final boolean voiceVerification = ns.getBoolean("voice");
final String captcha = ns.getString("captcha");
final var captcha = ns.getString("captcha");
try {
m.register(voiceVerification, captcha);

View file

@ -1,7 +1,6 @@
package org.asamk.signal.commands;
import net.sourceforge.argparse4j.impl.Arguments;
import net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup;
import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser;
@ -24,7 +23,7 @@ public class SendCommand implements DbusCommand {
@Override
public void attachToSubparser(final Subparser subparser) {
subparser.addArgument("recipient").help("Specify the recipients' phone number.").nargs("*");
final MutuallyExclusiveGroup mutuallyExclusiveGroup = subparser.addMutuallyExclusiveGroup();
final var mutuallyExclusiveGroup = subparser.addMutuallyExclusiveGroup();
mutuallyExclusiveGroup.addArgument("-g", "--group").help("Specify the recipient group ID.");
mutuallyExclusiveGroup.addArgument("--note-to-self")
.help("Send the message to self without notification.")
@ -40,11 +39,11 @@ public class SendCommand implements DbusCommand {
@Override
public int handleCommand(final Namespace ns, final Signal signal) {
final List<String> recipients = ns.getList("recipient");
final Boolean isEndSession = ns.getBoolean("endsession");
final String groupIdString = ns.getString("group");
final Boolean isNoteToSelf = ns.getBoolean("note_to_self");
final var isEndSession = ns.getBoolean("endsession");
final var groupIdString = ns.getString("group");
final var isNoteToSelf = ns.getBoolean("note_to_self");
final boolean noRecipients = recipients == null || recipients.isEmpty();
final var noRecipients = recipients == null || recipients.isEmpty();
if ((noRecipients && isEndSession) || (noRecipients && groupIdString == null && !isNoteToSelf)) {
System.err.println("No recipients given");
System.err.println("Aborting sending.");
@ -75,7 +74,7 @@ public class SendCommand implements DbusCommand {
}
}
String messageText = ns.getString("message");
var messageText = ns.getString("message");
if (messageText == null) {
try {
messageText = IOUtils.readAll(System.in, Charset.defaultCharset());
@ -101,7 +100,7 @@ public class SendCommand implements DbusCommand {
return 1;
}
long timestamp = signal.sendGroupMessage(messageText, attachments, groupId);
var timestamp = signal.sendGroupMessage(messageText, attachments, groupId);
System.out.println(timestamp);
return 0;
} catch (AssertionError e) {
@ -115,7 +114,7 @@ public class SendCommand implements DbusCommand {
if (isNoteToSelf) {
try {
long timestamp = signal.sendNoteToSelfMessage(messageText, attachments);
var timestamp = signal.sendNoteToSelfMessage(messageText, attachments);
System.out.println(timestamp);
return 0;
} catch (AssertionError e) {
@ -131,7 +130,7 @@ public class SendCommand implements DbusCommand {
}
try {
long timestamp = signal.sendMessage(messageText, attachments, recipients);
var timestamp = signal.sendMessage(messageText, attachments, recipients);
System.out.println(timestamp);
return 0;
} catch (AssertionError e) {

View file

@ -5,7 +5,6 @@ import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.groups.GroupId;
import org.asamk.signal.manager.groups.GroupIdFormatException;
import org.asamk.signal.manager.groups.GroupNotFoundException;
import org.asamk.signal.manager.groups.NotAGroupMemberException;
@ -48,9 +47,9 @@ public class SendReactionCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
final List<String> recipients = ns.getList("recipient");
final String groupIdString = ns.getString("group");
final var groupIdString = ns.getString("group");
final boolean noRecipients = recipients == null || recipients.isEmpty();
final var noRecipients = recipients == null || recipients.isEmpty();
if (noRecipients && groupIdString == null) {
System.err.println("No recipients given");
System.err.println("Aborting sending.");
@ -61,15 +60,15 @@ public class SendReactionCommand implements LocalCommand {
return 1;
}
final String emoji = ns.getString("emoji");
final var emoji = ns.getString("emoji");
final boolean isRemove = ns.getBoolean("remove");
final String targetAuthor = ns.getString("target_author");
final var targetAuthor = ns.getString("target_author");
final long targetTimestamp = ns.getLong("target_timestamp");
try {
final Pair<Long, List<SendMessageResult>> results;
if (groupIdString != null) {
GroupId groupId = Util.decodeGroupId(groupIdString);
var groupId = Util.decodeGroupId(groupIdString);
results = m.sendGroupMessageReaction(emoji, isRemove, targetAuthor, targetTimestamp, groupId);
} else {
results = m.sendMessageReaction(emoji, isRemove, targetAuthor, targetTimestamp, recipients);

View file

@ -20,7 +20,7 @@ public class SetPinCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
try {
String registrationLockPin = ns.getString("registrationLockPin");
var registrationLockPin = ns.getString("registrationLockPin");
m.setRegistrationLockPin(Optional.of(registrationLockPin));
return 0;
} catch (UnauthenticatedResponseException e) {

View file

@ -1,7 +1,6 @@
package org.asamk.signal.commands;
import net.sourceforge.argparse4j.impl.Arguments;
import net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup;
import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser;
@ -17,7 +16,7 @@ public class TrustCommand implements LocalCommand {
@Override
public void attachToSubparser(final Subparser subparser) {
subparser.addArgument("number").help("Specify the phone number, for which to set the trust.").required(true);
MutuallyExclusiveGroup mutTrust = subparser.addMutuallyExclusiveGroup();
var mutTrust = subparser.addMutuallyExclusiveGroup();
mutTrust.addArgument("-a", "--trust-all-known-keys")
.help("Trust all known keys of this user, only use this for testing.")
.action(Arguments.storeTrue());
@ -27,15 +26,15 @@ public class TrustCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
String number = ns.getString("number");
var number = ns.getString("number");
if (ns.getBoolean("trust_all_known_keys")) {
boolean res = m.trustIdentityAllKeys(number);
var res = m.trustIdentityAllKeys(number);
if (!res) {
System.err.println("Failed to set the trust for this number, make sure the number is correct.");
return 1;
}
} else {
String safetyNumber = ns.getString("verified_safety_number");
var safetyNumber = ns.getString("verified_safety_number");
if (safetyNumber != null) {
safetyNumber = safetyNumber.replaceAll(" ", "");
if (safetyNumber.length() == 66) {

View file

@ -4,7 +4,6 @@ import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.groups.GroupId;
import org.asamk.signal.manager.groups.GroupIdFormatException;
import org.asamk.signal.manager.groups.GroupNotFoundException;
import org.asamk.signal.util.Util;
@ -21,7 +20,7 @@ public class UnblockCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
for (String contact_number : ns.<String>getList("contact")) {
for (var contact_number : ns.<String>getList("contact")) {
try {
m.setContactBlocked(contact_number, false);
} catch (InvalidNumberException e) {
@ -30,9 +29,9 @@ public class UnblockCommand implements LocalCommand {
}
if (ns.<String>getList("group") != null) {
for (String groupIdString : ns.<String>getList("group")) {
for (var groupIdString : ns.<String>getList("group")) {
try {
GroupId groupId = Util.decodeGroupId(groupIdString);
var groupId = Util.decodeGroupId(groupIdString);
m.setGroupBlocked(groupId, false);
} catch (GroupIdFormatException | GroupNotFoundException e) {
System.err.println(e.getMessage());

View file

@ -23,13 +23,13 @@ public class UpdateContactCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
String number = ns.getString("number");
String name = ns.getString("name");
var number = ns.getString("number");
var name = ns.getString("name");
try {
m.setContactName(number, name);
Integer expiration = ns.getInt("expiration");
var expiration = ns.getInt("expiration");
if (expiration != null) {
m.setExpirationTimer(number, expiration);
}

View file

@ -40,7 +40,7 @@ public class UpdateGroupCommand implements DbusCommand {
groupId = new byte[0];
}
String groupName = ns.getString("name");
var groupName = ns.getString("name");
if (groupName == null) {
groupName = "";
}
@ -50,13 +50,13 @@ public class UpdateGroupCommand implements DbusCommand {
groupMembers = new ArrayList<>();
}
String groupAvatar = ns.getString("avatar");
var groupAvatar = ns.getString("avatar");
if (groupAvatar == null) {
groupAvatar = "";
}
try {
byte[] newGroupId = signal.updateGroup(groupId, groupName, groupMembers, groupAvatar);
var newGroupId = signal.updateGroup(groupId, groupName, groupMembers, groupAvatar);
if (groupId.length != newGroupId.length) {
System.out.println("Creating new group \"" + Base64.getEncoder().encodeToString(newGroupId) + "\"");
}

View file

@ -1,7 +1,6 @@
package org.asamk.signal.commands;
import net.sourceforge.argparse4j.impl.Arguments;
import net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup;
import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser;
@ -19,7 +18,7 @@ public class UpdateProfileCommand implements LocalCommand {
subparser.addArgument("--about").help("New profile about text");
subparser.addArgument("--about-emoji").help("New profile about emoji");
final MutuallyExclusiveGroup avatarOptions = subparser.addMutuallyExclusiveGroup();
final var avatarOptions = subparser.addMutuallyExclusiveGroup();
avatarOptions.addArgument("--avatar").help("Path to new profile avatar");
avatarOptions.addArgument("--remove-avatar").action(Arguments.storeTrue());
@ -28,10 +27,10 @@ public class UpdateProfileCommand implements LocalCommand {
@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");
var name = ns.getString("name");
var about = ns.getString("about");
var aboutEmoji = ns.getString("about_emoji");
var avatarPath = ns.getString("avatar");
boolean removeAvatar = ns.getBoolean("remove_avatar");
try {

View file

@ -20,8 +20,8 @@ public class UploadStickerPackCommand implements LocalCommand {
@Override
public int handleCommand(final Namespace ns, final Manager m) {
try {
File path = new File(ns.getString("path"));
String url = m.uploadStickerPack(path);
var path = new File(ns.getString("path"));
var url = m.uploadStickerPack(path);
System.out.println(url);
return 0;
} catch (IOException e) {

View file

@ -21,8 +21,8 @@ public class VerifyCommand implements RegistrationCommand {
@Override
public int handleCommand(final Namespace ns, final RegistrationManager m) {
try {
String verificationCode = ns.getString("verificationCode");
String pin = ns.getString("pin");
var verificationCode = ns.getString("verificationCode");
var pin = ns.getString("pin");
m.verifyAccount(verificationCode, pin);
return 0;
} catch (LockedException e) {