Use Java 17

This commit is contained in:
AsamK 2021-10-24 21:06:13 +02:00
parent 9cb1409918
commit ce70a623c2
51 changed files with 142 additions and 236 deletions

View file

@ -47,8 +47,7 @@ public class GetUserStatusCommand implements JsonRpcLocalCommand {
}
// Output
if (outputWriter instanceof JsonWriter) {
final var jsonWriter = (JsonWriter) outputWriter;
if (outputWriter instanceof JsonWriter jsonWriter) {
var jsonUserStatuses = registered.entrySet().stream().map(entry -> {
final var number = entry.getValue().first();

View file

@ -55,8 +55,7 @@ public class JoinGroupCommand implements JsonRpcLocalCommand {
try {
final var results = m.joinGroup(linkUrl);
var newGroupId = results.first();
if (outputWriter instanceof JsonWriter) {
final var writer = (JsonWriter) outputWriter;
if (outputWriter instanceof JsonWriter writer) {
if (!m.getGroup(newGroupId).isMember()) {
writer.write(Map.of("groupId", newGroupId.toBase64(), "onlyRequested", true));
} else {

View file

@ -27,8 +27,7 @@ public class ListContactsCommand implements JsonRpcLocalCommand {
public void handleCommand(final Namespace ns, final Manager m, final OutputWriter outputWriter) {
var contacts = m.getContacts();
if (outputWriter instanceof PlainTextWriter) {
final var writer = (PlainTextWriter) outputWriter;
if (outputWriter instanceof PlainTextWriter writer) {
for (var c : contacts) {
final var contact = c.second();
writer.println("Number: {} Name: {} Blocked: {} Message expiration: {}",

View file

@ -43,8 +43,7 @@ public class ListDevicesCommand implements JsonRpcLocalCommand {
throw new IOErrorException("Failed to get linked devices: " + e.getMessage(), e);
}
if (outputWriter instanceof PlainTextWriter) {
final var writer = (PlainTextWriter) outputWriter;
if (outputWriter instanceof PlainTextWriter writer) {
for (var d : devices) {
writer.println("- Device {}{}:", d.getId(), (d.isThisDevice() ? " (this device)" : ""));
writer.indent(w -> {

View file

@ -80,8 +80,7 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
) throws CommandException {
final var groups = m.getGroups();
if (outputWriter instanceof JsonWriter) {
final var jsonWriter = (JsonWriter) outputWriter;
if (outputWriter instanceof JsonWriter jsonWriter) {
var jsonGroups = groups.stream().map(group -> {
final var groupInviteLink = group.getGroupInviteLinkUrl();

View file

@ -59,8 +59,7 @@ public class ListIdentitiesCommand implements JsonRpcLocalCommand {
identities = m.getIdentities(CommandUtil.getSingleRecipientIdentifier(number, m.getSelfNumber()));
}
if (outputWriter instanceof PlainTextWriter) {
final var writer = (PlainTextWriter) outputWriter;
if (outputWriter instanceof PlainTextWriter writer) {
for (var id : identities) {
printIdentityFingerprint(writer, m, id);
}

View file

@ -79,8 +79,7 @@ public class QuitGroupCommand implements JsonRpcLocalCommand {
}
private void outputResult(final OutputWriter outputWriter, final long timestamp) {
if (outputWriter instanceof PlainTextWriter) {
final var writer = (PlainTextWriter) outputWriter;
if (outputWriter instanceof PlainTextWriter writer) {
writer.println("{}", timestamp);
} else {
final var writer = (JsonWriter) outputWriter;

View file

@ -58,8 +58,7 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
final Namespace ns, final Signal signal, DBusConnection dbusconnection, final OutputWriter outputWriter
) throws CommandException {
try {
if (outputWriter instanceof JsonWriter) {
final var jsonWriter = (JsonWriter) outputWriter;
if (outputWriter instanceof JsonWriter jsonWriter) {
dbusconnection.addSigHandler(Signal.MessageReceived.class, signal, messageReceived -> {
var envelope = new JsonMessageEnvelope(messageReceived);

View file

@ -40,10 +40,11 @@ public class RegisterCommand implements RegistrationCommand {
} catch (CaptchaRequiredException e) {
String message;
if (captcha == null) {
message = "Captcha required for verification, use --captcha CAPTCHA\n"
+ "To get the token, go to https://signalcaptchas.org/registration/generate.html\n"
+ "Check the developer tools (F12) console for a failed redirect to signalcaptcha://\n"
+ "Everything after signalcaptcha:// is the captcha token.";
message = """
Captcha required for verification, use --captcha CAPTCHA
To get the token, go to https://signalcaptchas.org/registration/generate.html
Check the developer tools (F12) console for a failed redirect to signalcaptcha://
Everything after signalcaptcha:// is the captcha token.""";
} else {
message = "Invalid captcha given.";
}

View file

@ -67,8 +67,7 @@ public class RemoteDeleteCommand implements JsonRpcLocalCommand {
}
private void outputResult(final OutputWriter outputWriter, final long timestamp) {
if (outputWriter instanceof PlainTextWriter) {
final var writer = (PlainTextWriter) outputWriter;
if (outputWriter instanceof PlainTextWriter writer) {
writer.println("{}", timestamp);
} else {
final var writer = (JsonWriter) outputWriter;

View file

@ -113,8 +113,7 @@ public class SendCommand implements JsonRpcLocalCommand {
}
private void outputResult(final OutputWriter outputWriter, final long timestamp) {
if (outputWriter instanceof PlainTextWriter) {
final var writer = (PlainTextWriter) outputWriter;
if (outputWriter instanceof PlainTextWriter writer) {
writer.println("{}", timestamp);
} else {
final var writer = (JsonWriter) outputWriter;

View file

@ -83,8 +83,7 @@ public class SendReactionCommand implements JsonRpcLocalCommand {
}
private void outputResult(final OutputWriter outputWriter, final long timestamp) {
if (outputWriter instanceof PlainTextWriter) {
final var writer = (PlainTextWriter) outputWriter;
if (outputWriter instanceof PlainTextWriter writer) {
writer.println("{}", timestamp);
} else {
final var writer = (JsonWriter) outputWriter;

View file

@ -77,33 +77,23 @@ public class UpdateGroupCommand implements JsonRpcLocalCommand {
if (value == null) {
return null;
}
switch (value) {
case "enabled":
return GroupLinkState.ENABLED;
case "enabled-with-approval":
case "enabledWithApproval":
return GroupLinkState.ENABLED_WITH_APPROVAL;
case "disabled":
return GroupLinkState.DISABLED;
default:
throw new UserErrorException("Invalid group link state: " + value);
}
return switch (value) {
case "enabled" -> GroupLinkState.ENABLED;
case "enabled-with-approval", "enabledWithApproval" -> GroupLinkState.ENABLED_WITH_APPROVAL;
case "disabled" -> GroupLinkState.DISABLED;
default -> throw new UserErrorException("Invalid group link state: " + value);
};
}
GroupPermission getGroupPermission(String value) throws UserErrorException {
if (value == null) {
return null;
}
switch (value) {
case "every-member":
case "everyMember":
return GroupPermission.EVERY_MEMBER;
case "only-admins":
case "onlyAdmins":
return GroupPermission.ONLY_ADMINS;
default:
throw new UserErrorException("Invalid group permission: " + value);
}
return switch (value) {
case "every-member", "everyMember" -> GroupPermission.EVERY_MEMBER;
case "only-admins", "onlyAdmins" -> GroupPermission.ONLY_ADMINS;
default -> throw new UserErrorException("Invalid group permission: " + value);
};
}
@Override
@ -179,8 +169,7 @@ public class UpdateGroupCommand implements JsonRpcLocalCommand {
}
private void outputResult(final OutputWriter outputWriter, final Long timestamp, final GroupId groupId) {
if (outputWriter instanceof PlainTextWriter) {
final var writer = (PlainTextWriter) outputWriter;
if (outputWriter instanceof PlainTextWriter writer) {
if (groupId != null) {
writer.println("Created new group: \"{}\"", groupId.toBase64());
}

View file

@ -42,8 +42,7 @@ public class UploadStickerPackCommand implements JsonRpcLocalCommand {
try {
var url = m.uploadStickerPack(path);
if (outputWriter instanceof PlainTextWriter) {
final var writer = (PlainTextWriter) outputWriter;
if (outputWriter instanceof PlainTextWriter writer) {
writer.println("{}", url);
} else {
final var writer = (JsonWriter) outputWriter;