mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-30 11:00:38 +00:00
Use Java 17
This commit is contained in:
parent
9cb1409918
commit
ce70a623c2
51 changed files with 142 additions and 236 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue