mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Use Java 17
This commit is contained in:
parent
9cb1409918
commit
ce70a623c2
51 changed files with 142 additions and 236 deletions
|
@ -26,7 +26,7 @@ public interface SignalControl extends DBusInterface {
|
|||
|
||||
String link(String newDeviceName) throws Error.Failure;
|
||||
|
||||
public String version();
|
||||
String version();
|
||||
|
||||
List<DBusPath> listAccounts();
|
||||
|
||||
|
|
|
@ -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 user’s key is untrusted, either the user has reinstalled Signal or a third party sent this message.");
|
||||
final var recipientName = getLegacyIdentifier(m.resolveSignalServiceAddress(e.getSender()));
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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: {}",
|
||||
|
|
|
@ -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 -> {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.";
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
||||
}
|
||||
|
|
|
@ -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".
|
||||
|
|
|
@ -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".
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue