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

@ -26,7 +26,7 @@ public interface SignalControl extends DBusInterface {
String link(String newDeviceName) throws Error.Failure;
public String version();
String version();
List<DBusPath> listAccounts();

View file

@ -53,8 +53,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
writer.println("Got receipt.");
} else if (envelope.isSignalMessage() || envelope.isPreKeySignalMessage() || envelope.isUnidentifiedSender()) {
if (exception != null) {
if (exception instanceof UntrustedIdentityException) {
var e = (UntrustedIdentityException) exception;
if (exception instanceof UntrustedIdentityException e) {
writer.println(
"The users key is untrusted, either the user has reinstalled Signal or a third party sent this message.");
final var recipientName = getLegacyIdentifier(m.resolveSignalServiceAddress(e.getSender()));

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;

View file

@ -274,15 +274,9 @@ public class DbusManagerImpl implements Manager {
}
if (updateGroup.getGroupLinkState() != null) {
switch (updateGroup.getGroupLinkState()) {
case DISABLED:
group.disableLink();
break;
case ENABLED:
group.enableLink(false);
break;
case ENABLED_WITH_APPROVAL:
group.enableLink(true);
break;
case DISABLED -> group.disableLink();
case ENABLED -> group.enableLink(false);
case ENABLED_WITH_APPROVAL -> group.enableLink(true);
}
}
return new SendGroupMessageResults(0, List.of());

View file

@ -71,8 +71,7 @@ public class JsonMessageEnvelope {
this.sourceNumber = source.getNumber().orNull();
this.sourceUuid = source.getUuid().toString();
this.sourceDevice = content.getSenderDevice();
} else if (exception instanceof UntrustedIdentityException) {
var e = (UntrustedIdentityException) exception;
} else if (exception instanceof UntrustedIdentityException e) {
final var source = m.resolveSignalServiceAddress(e.getSender());
this.source = getLegacyIdentifier(source);
this.sourceNumber = source.getNumber().orNull();

View file

@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import java.util.List;
public class JsonRpcBulkMessage extends JsonRpcMessage {
public final class JsonRpcBulkMessage extends JsonRpcMessage {
List<JsonNode> messages;

View file

@ -4,6 +4,6 @@ package org.asamk.signal.jsonrpc;
* Represents a JSON-RPC (bulk) request or (bulk) response.
* https://www.jsonrpc.org/specification
*/
public abstract class JsonRpcMessage {
public sealed abstract class JsonRpcMessage permits JsonRpcBulkMessage, JsonRpcRequest, JsonRpcResponse {
}

View file

@ -8,7 +8,7 @@ import com.fasterxml.jackson.databind.node.ValueNode;
* Represents a JSON-RPC request.
* https://www.jsonrpc.org/specification#request_object
*/
public class JsonRpcRequest extends JsonRpcMessage {
public final class JsonRpcRequest extends JsonRpcMessage {
/**
* A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0".

View file

@ -8,7 +8,7 @@ import com.fasterxml.jackson.databind.node.ValueNode;
* Represents a JSON-RPC response.
* https://www.jsonrpc.org/specification#response_object
*/
public class JsonRpcResponse extends JsonRpcMessage {
public final class JsonRpcResponse extends JsonRpcMessage {
/**
* A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0".

View file

@ -64,12 +64,12 @@ public class ErrorUtils {
"CAPTCHA proof required for sending to \"%s\", available options \"%s\" with challenge token \"%s\", or wait \"%d\" seconds.\n"
+ (
failure.getOptions().contains(ProofRequiredException.Option.RECAPTCHA)
?
"To get the captcha token, go to https://signalcaptchas.org/challenge/generate.html\n"
+ "Check the developer tools (F12) console for a failed redirect to signalcaptcha://\n"
+ "Everything after signalcaptcha:// is the captcha token.\n"
+ "Use the following command to submit the captcha token:\n"
+ "signal-cli submitRateLimitChallenge --challenge CHALLENGE_TOKEN --captcha CAPTCHA_TOKEN"
? """
To get the captcha token, go to https://signalcaptchas.org/challenge/generate.html
Check the developer tools (F12) console for a failed redirect to signalcaptcha://
Everything after signalcaptcha:// is the captcha token.
Use the following command to submit the captcha token:
signal-cli submitRateLimitChallenge --challenge CHALLENGE_TOKEN --captcha CAPTCHA_TOKEN"""
: ""
),
identifier,