mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Use var instead of explicit types
This commit is contained in:
parent
03c30519b1
commit
de273586b4
77 changed files with 850 additions and 1017 deletions
|
@ -3,10 +3,7 @@ package org.asamk.signal;
|
|||
import net.sourceforge.argparse4j.ArgumentParsers;
|
||||
import net.sourceforge.argparse4j.impl.Arguments;
|
||||
import net.sourceforge.argparse4j.inf.ArgumentParser;
|
||||
import net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup;
|
||||
import net.sourceforge.argparse4j.inf.Namespace;
|
||||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
import net.sourceforge.argparse4j.inf.Subparsers;
|
||||
|
||||
import org.asamk.Signal;
|
||||
import org.asamk.signal.commands.Command;
|
||||
|
@ -33,7 +30,6 @@ import org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -44,7 +40,7 @@ public class App {
|
|||
private final Namespace ns;
|
||||
|
||||
static ArgumentParser buildArgumentParser() {
|
||||
ArgumentParser parser = ArgumentParsers.newFor("signal-cli")
|
||||
var parser = ArgumentParsers.newFor("signal-cli")
|
||||
.build()
|
||||
.defaultHelp(true)
|
||||
.description("Commandline interface for Signal.")
|
||||
|
@ -59,7 +55,7 @@ public class App {
|
|||
|
||||
parser.addArgument("-u", "--username").help("Specify your phone number, that will be used for verification.");
|
||||
|
||||
MutuallyExclusiveGroup mut = parser.addMutuallyExclusiveGroup();
|
||||
var mut = parser.addMutuallyExclusiveGroup();
|
||||
mut.addArgument("--dbus").help("Make request via user dbus.").action(Arguments.storeTrue());
|
||||
mut.addArgument("--dbus-system").help("Make request via system dbus.").action(Arguments.storeTrue());
|
||||
|
||||
|
@ -68,11 +64,11 @@ public class App {
|
|||
.type(Arguments.enumStringType(OutputType.class))
|
||||
.setDefault(OutputType.PLAIN_TEXT);
|
||||
|
||||
Subparsers subparsers = parser.addSubparsers().title("subcommands").dest("command");
|
||||
var subparsers = parser.addSubparsers().title("subcommands").dest("command");
|
||||
|
||||
final Map<String, Command> commands = Commands.getCommands();
|
||||
for (Map.Entry<String, Command> entry : commands.entrySet()) {
|
||||
Subparser subparser = subparsers.addParser(entry.getKey());
|
||||
final var commands = Commands.getCommands();
|
||||
for (var entry : commands.entrySet()) {
|
||||
var subparser = subparsers.addParser(entry.getKey());
|
||||
entry.getValue().attachToSubparser(subparser);
|
||||
}
|
||||
|
||||
|
@ -84,8 +80,8 @@ public class App {
|
|||
}
|
||||
|
||||
public int init() {
|
||||
String commandKey = ns.getString("command");
|
||||
Command command = Commands.getCommand(commandKey);
|
||||
var commandKey = ns.getString("command");
|
||||
var command = Commands.getCommand(commandKey);
|
||||
if (command == null) {
|
||||
logger.error("Command not implemented!");
|
||||
return 1;
|
||||
|
@ -97,7 +93,7 @@ public class App {
|
|||
return 1;
|
||||
}
|
||||
|
||||
String username = ns.getString("username");
|
||||
var username = ns.getString("username");
|
||||
|
||||
final boolean useDbus = ns.getBoolean("dbus");
|
||||
final boolean useDbusSystem = ns.getBoolean("dbus_system");
|
||||
|
@ -107,14 +103,14 @@ public class App {
|
|||
}
|
||||
|
||||
final File dataPath;
|
||||
String config = ns.getString("config");
|
||||
var config = ns.getString("config");
|
||||
if (config != null) {
|
||||
dataPath = new File(config);
|
||||
} else {
|
||||
dataPath = getDefaultDataPath();
|
||||
}
|
||||
|
||||
final ServiceEnvironment serviceEnvironment = ServiceEnvironment.LIVE;
|
||||
final var serviceEnvironment = ServiceEnvironment.LIVE;
|
||||
|
||||
if (!ServiceConfig.getCapabilities().isGv2()) {
|
||||
logger.warn("WARNING: Support for new group V2 is disabled,"
|
||||
|
@ -136,7 +132,7 @@ public class App {
|
|||
}
|
||||
|
||||
if (username == null) {
|
||||
List<String> usernames = Manager.getAllLocalUsernames(dataPath);
|
||||
var usernames = Manager.getAllLocalUsernames(dataPath);
|
||||
if (usernames.size() == 0) {
|
||||
System.err.println("No local users found, you first need to register or link an account");
|
||||
return 1;
|
||||
|
@ -172,7 +168,7 @@ public class App {
|
|||
private int handleProvisioningCommand(
|
||||
final ProvisioningCommand command, final File dataPath, final ServiceEnvironment serviceEnvironment
|
||||
) {
|
||||
ProvisioningManager pm = ProvisioningManager.init(dataPath, serviceEnvironment, BaseConfig.USER_AGENT);
|
||||
var pm = ProvisioningManager.init(dataPath, serviceEnvironment, BaseConfig.USER_AGENT);
|
||||
return command.handleCommand(ns, pm);
|
||||
}
|
||||
|
||||
|
@ -189,7 +185,7 @@ public class App {
|
|||
logger.error("Error loading or creating state file: {}", e.getMessage());
|
||||
return 2;
|
||||
}
|
||||
try (RegistrationManager m = manager) {
|
||||
try (var m = manager) {
|
||||
return command.handleCommand(ns, m);
|
||||
} catch (IOException e) {
|
||||
logger.error("Cleanup failed", e);
|
||||
|
@ -203,7 +199,7 @@ public class App {
|
|||
final File dataPath,
|
||||
final ServiceEnvironment serviceEnvironment
|
||||
) {
|
||||
try (Manager m = loadManager(username, dataPath, serviceEnvironment)) {
|
||||
try (var m = loadManager(username, dataPath, serviceEnvironment)) {
|
||||
if (m == null) {
|
||||
return 2;
|
||||
}
|
||||
|
@ -221,14 +217,14 @@ public class App {
|
|||
final ServiceEnvironment serviceEnvironment,
|
||||
final List<String> usernames
|
||||
) {
|
||||
final List<Manager> managers = usernames.stream()
|
||||
final var managers = usernames.stream()
|
||||
.map(u -> loadManager(u, dataPath, serviceEnvironment))
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
int result = command.handleCommand(ns, managers);
|
||||
var result = command.handleCommand(ns, managers);
|
||||
|
||||
for (Manager m : managers) {
|
||||
for (var m : managers) {
|
||||
try {
|
||||
m.close();
|
||||
} catch (IOException e) {
|
||||
|
@ -270,8 +266,8 @@ public class App {
|
|||
} else {
|
||||
busType = DBusConnection.DBusBusType.SESSION;
|
||||
}
|
||||
try (DBusConnection dBusConn = DBusConnection.getConnection(busType)) {
|
||||
Signal ts = dBusConn.getRemoteObject(DbusConfig.getBusname(),
|
||||
try (var dBusConn = DBusConnection.getConnection(busType)) {
|
||||
var ts = dBusConn.getRemoteObject(DbusConfig.getBusname(),
|
||||
DbusConfig.getObjectPath(username),
|
||||
Signal.class);
|
||||
|
||||
|
@ -302,14 +298,14 @@ public class App {
|
|||
* @return the data directory to be used by signal-cli.
|
||||
*/
|
||||
private static File getDefaultDataPath() {
|
||||
File dataPath = new File(IOUtils.getDataHomeDir(), "signal-cli");
|
||||
var dataPath = new File(IOUtils.getDataHomeDir(), "signal-cli");
|
||||
if (dataPath.exists()) {
|
||||
return dataPath;
|
||||
}
|
||||
|
||||
File configPath = new File(System.getProperty("user.home"), ".config");
|
||||
var configPath = new File(System.getProperty("user.home"), ".config");
|
||||
|
||||
File legacySettingsPath = new File(configPath, "signal");
|
||||
var legacySettingsPath = new File(configPath, "signal");
|
||||
if (legacySettingsPath.exists()) {
|
||||
return legacySettingsPath;
|
||||
}
|
||||
|
|
|
@ -5,15 +5,10 @@ import org.asamk.signal.manager.Manager;
|
|||
import org.asamk.signal.manager.groups.GroupUtils;
|
||||
import org.freedesktop.dbus.connections.impl.DBusConnection;
|
||||
import org.freedesktop.dbus.exceptions.DBusException;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceContent;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -46,11 +41,11 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
|
|||
e.printStackTrace();
|
||||
}
|
||||
} else if (content != null) {
|
||||
final SignalServiceAddress sender = !envelope.isUnidentifiedSender() && envelope.hasSource()
|
||||
final var sender = !envelope.isUnidentifiedSender() && envelope.hasSource()
|
||||
? envelope.getSourceAddress()
|
||||
: content.getSender();
|
||||
if (content.getReceiptMessage().isPresent()) {
|
||||
final SignalServiceReceiptMessage receiptMessage = content.getReceiptMessage().get();
|
||||
final var receiptMessage = content.getReceiptMessage().get();
|
||||
if (receiptMessage.isDeliveryReceipt()) {
|
||||
for (long timestamp : receiptMessage.getTimestamps()) {
|
||||
try {
|
||||
|
@ -63,9 +58,9 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
|
|||
}
|
||||
}
|
||||
} else if (content.getDataMessage().isPresent()) {
|
||||
SignalServiceDataMessage message = content.getDataMessage().get();
|
||||
var message = content.getDataMessage().get();
|
||||
|
||||
byte[] groupId = getGroupId(message);
|
||||
var groupId = getGroupId(message);
|
||||
if (!message.isEndSession() && (
|
||||
groupId == null
|
||||
|| message.getGroupContext().get().getGroupV1Type() == null
|
||||
|
@ -83,15 +78,15 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
|
|||
}
|
||||
}
|
||||
} else if (content.getSyncMessage().isPresent()) {
|
||||
SignalServiceSyncMessage sync_message = content.getSyncMessage().get();
|
||||
var sync_message = content.getSyncMessage().get();
|
||||
if (sync_message.getSent().isPresent()) {
|
||||
SentTranscriptMessage transcript = sync_message.getSent().get();
|
||||
var transcript = sync_message.getSent().get();
|
||||
|
||||
if (transcript.getDestination().isPresent() || transcript.getMessage()
|
||||
.getGroupContext()
|
||||
.isPresent()) {
|
||||
SignalServiceDataMessage message = transcript.getMessage();
|
||||
byte[] groupId = getGroupId(message);
|
||||
var message = transcript.getMessage();
|
||||
var groupId = getGroupId(message);
|
||||
|
||||
try {
|
||||
conn.sendMessage(new Signal.SyncMessageReceived(objectPath,
|
||||
|
@ -118,9 +113,9 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
|
|||
}
|
||||
|
||||
static private List<String> getAttachments(SignalServiceDataMessage message, Manager m) {
|
||||
List<String> attachments = new ArrayList<>();
|
||||
var attachments = new ArrayList<String>();
|
||||
if (message.getAttachments().isPresent()) {
|
||||
for (SignalServiceAttachment attachment : message.getAttachments().get()) {
|
||||
for (var attachment : message.getAttachments().get()) {
|
||||
if (attachment.isPointer()) {
|
||||
attachments.add(m.getAttachmentFile(attachment.asPointer().getRemoteId()).getAbsolutePath());
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class JsonReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||
|
||||
|
@ -26,7 +25,7 @@ public class JsonReceiveMessageHandler implements Manager.ReceiveMessageHandler
|
|||
|
||||
@Override
|
||||
public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) {
|
||||
final Map<String, Object> object = new HashMap<>();
|
||||
final var object = new HashMap<String, Object>();
|
||||
if (exception != null) {
|
||||
object.put("error", new JsonError(exception));
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package org.asamk.signal;
|
|||
|
||||
import net.sourceforge.argparse4j.ArgumentParsers;
|
||||
import net.sourceforge.argparse4j.impl.Arguments;
|
||||
import net.sourceforge.argparse4j.inf.ArgumentParser;
|
||||
import net.sourceforge.argparse4j.inf.ArgumentParserException;
|
||||
import net.sourceforge.argparse4j.inf.Namespace;
|
||||
|
||||
|
@ -36,11 +35,11 @@ public class Main {
|
|||
// Configuring the logger needs to happen before any logger is initialized
|
||||
configureLogging(isVerbose(args));
|
||||
|
||||
ArgumentParser parser = App.buildArgumentParser();
|
||||
var parser = App.buildArgumentParser();
|
||||
|
||||
Namespace ns = parser.parseArgsOrFail(args);
|
||||
var ns = parser.parseArgsOrFail(args);
|
||||
|
||||
int res = new App(ns).init();
|
||||
var res = new App(ns).init();
|
||||
System.exit(res);
|
||||
}
|
||||
|
||||
|
@ -51,7 +50,7 @@ public class Main {
|
|||
}
|
||||
|
||||
private static boolean isVerbose(String[] args) {
|
||||
ArgumentParser parser = ArgumentParsers.newFor("signal-cli").build().defaultHelp(false);
|
||||
var parser = ArgumentParsers.newFor("signal-cli").build().defaultHelp(false);
|
||||
parser.addArgument("--verbose").action(Arguments.storeTrue());
|
||||
|
||||
Namespace ns;
|
||||
|
|
|
@ -20,7 +20,7 @@ public final class PlainTextWriterImpl implements PlainTextWriter {
|
|||
|
||||
@Override
|
||||
public void println(String format, Object... args) throws IOException {
|
||||
final String message = MessageFormatter.arrayFormat(format, args).getMessage();
|
||||
final var message = MessageFormatter.arrayFormat(format, args).getMessage();
|
||||
|
||||
writer.write(message);
|
||||
writer.write(System.lineSeparator());
|
||||
|
|
|
@ -3,46 +3,24 @@ package org.asamk.signal;
|
|||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.groups.GroupId;
|
||||
import org.asamk.signal.manager.groups.GroupUtils;
|
||||
import org.asamk.signal.manager.storage.groups.GroupInfo;
|
||||
import org.asamk.signal.util.DateUtils;
|
||||
import org.asamk.signal.util.Util;
|
||||
import org.slf4j.helpers.MessageFormatter;
|
||||
import org.whispersystems.libsignal.UntrustedIdentityException;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceContent;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroupContext;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroupV2;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage;
|
||||
import org.whispersystems.signalservice.api.messages.calls.AnswerMessage;
|
||||
import org.whispersystems.signalservice.api.messages.calls.BusyMessage;
|
||||
import org.whispersystems.signalservice.api.messages.calls.HangupMessage;
|
||||
import org.whispersystems.signalservice.api.messages.calls.IceUpdateMessage;
|
||||
import org.whispersystems.signalservice.api.messages.calls.OfferMessage;
|
||||
import org.whispersystems.signalservice.api.messages.calls.OpaqueMessage;
|
||||
import org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.ConfigurationMessage;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.ContactsMessage;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.KeysMessage;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.MessageRequestResponseMessage;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.ReadMessage;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.StickerPackOperationMessage;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.ViewOnceOpenMessage;
|
||||
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||
|
@ -68,7 +46,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
PlainTextWriter writer = new PlainTextWriterImpl(System.out);
|
||||
|
||||
if (envelope.hasSource()) {
|
||||
SignalServiceAddress source = envelope.getSourceAddress();
|
||||
var source = envelope.getSourceAddress();
|
||||
writer.println("Envelope from: {} (device: {})", formatContact(source), envelope.getSourceDevice());
|
||||
if (source.getRelay().isPresent()) {
|
||||
writer.println("Relayed by: {}", source.getRelay().get());
|
||||
|
@ -86,7 +64,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
} else if (envelope.isSignalMessage() || envelope.isPreKeySignalMessage() || envelope.isUnidentifiedSender()) {
|
||||
if (exception != null) {
|
||||
if (exception instanceof UntrustedIdentityException) {
|
||||
UntrustedIdentityException e = (UntrustedIdentityException) exception;
|
||||
var e = (UntrustedIdentityException) exception;
|
||||
writer.println(
|
||||
"The user’s key is untrusted, either the user has reinstalled Signal or a third party sent this message.");
|
||||
writer.println(
|
||||
|
@ -112,28 +90,28 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
DateUtils.formatTimestamp(content.getServerDeliveredTimestamp()));
|
||||
|
||||
if (content.getDataMessage().isPresent()) {
|
||||
SignalServiceDataMessage message = content.getDataMessage().get();
|
||||
var message = content.getDataMessage().get();
|
||||
printDataMessage(writer, message);
|
||||
}
|
||||
if (content.getSyncMessage().isPresent()) {
|
||||
writer.println("Received a sync message");
|
||||
SignalServiceSyncMessage syncMessage = content.getSyncMessage().get();
|
||||
var syncMessage = content.getSyncMessage().get();
|
||||
printSyncMessage(writer, syncMessage);
|
||||
}
|
||||
|
||||
if (content.getCallMessage().isPresent()) {
|
||||
writer.println("Received a call message");
|
||||
SignalServiceCallMessage callMessage = content.getCallMessage().get();
|
||||
var callMessage = content.getCallMessage().get();
|
||||
printCallMessage(writer.indentedWriter(), callMessage);
|
||||
}
|
||||
if (content.getReceiptMessage().isPresent()) {
|
||||
writer.println("Received a receipt message");
|
||||
SignalServiceReceiptMessage receiptMessage = content.getReceiptMessage().get();
|
||||
var receiptMessage = content.getReceiptMessage().get();
|
||||
printReceiptMessage(writer.indentedWriter(), receiptMessage);
|
||||
}
|
||||
if (content.getTypingMessage().isPresent()) {
|
||||
writer.println("Received a typing message");
|
||||
SignalServiceTypingMessage typingMessage = content.getTypingMessage().get();
|
||||
var typingMessage = content.getTypingMessage().get();
|
||||
printTypingMessage(writer.indentedWriter(), typingMessage);
|
||||
}
|
||||
}
|
||||
|
@ -156,32 +134,32 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
}
|
||||
if (message.getGroupContext().isPresent()) {
|
||||
writer.println("Group info:");
|
||||
final SignalServiceGroupContext groupContext = message.getGroupContext().get();
|
||||
final var groupContext = message.getGroupContext().get();
|
||||
printGroupContext(writer.indentedWriter(), groupContext);
|
||||
}
|
||||
if (message.getGroupCallUpdate().isPresent()) {
|
||||
writer.println("Group call update:");
|
||||
final SignalServiceDataMessage.GroupCallUpdate groupCallUpdate = message.getGroupCallUpdate().get();
|
||||
final var groupCallUpdate = message.getGroupCallUpdate().get();
|
||||
writer.indentedWriter().println("Era id: {}", groupCallUpdate.getEraId());
|
||||
}
|
||||
if (message.getPreviews().isPresent()) {
|
||||
writer.println("Previews:");
|
||||
final List<SignalServiceDataMessage.Preview> previews = message.getPreviews().get();
|
||||
for (SignalServiceDataMessage.Preview preview : previews) {
|
||||
final var previews = message.getPreviews().get();
|
||||
for (var preview : previews) {
|
||||
writer.println("- Preview");
|
||||
printPreview(writer.indentedWriter(), preview);
|
||||
}
|
||||
}
|
||||
if (message.getSharedContacts().isPresent()) {
|
||||
final List<SharedContact> sharedContacts = message.getSharedContacts().get();
|
||||
final var sharedContacts = message.getSharedContacts().get();
|
||||
writer.println("Contacts:");
|
||||
for (SharedContact contact : sharedContacts) {
|
||||
for (var contact : sharedContacts) {
|
||||
writer.println("- Contact:");
|
||||
printSharedContact(writer.indentedWriter(), contact);
|
||||
}
|
||||
}
|
||||
if (message.getSticker().isPresent()) {
|
||||
final SignalServiceDataMessage.Sticker sticker = message.getSticker().get();
|
||||
final var sticker = message.getSticker().get();
|
||||
writer.println("Sticker:");
|
||||
printSticker(writer.indentedWriter(), sticker);
|
||||
}
|
||||
|
@ -199,27 +177,27 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
}
|
||||
if (message.getReaction().isPresent()) {
|
||||
writer.println("Reaction:");
|
||||
final SignalServiceDataMessage.Reaction reaction = message.getReaction().get();
|
||||
final var reaction = message.getReaction().get();
|
||||
printReaction(writer.indentedWriter(), reaction);
|
||||
}
|
||||
if (message.getQuote().isPresent()) {
|
||||
writer.println("Quote:");
|
||||
SignalServiceDataMessage.Quote quote = message.getQuote().get();
|
||||
var quote = message.getQuote().get();
|
||||
printQuote(writer.indentedWriter(), quote);
|
||||
}
|
||||
if (message.getRemoteDelete().isPresent()) {
|
||||
final SignalServiceDataMessage.RemoteDelete remoteDelete = message.getRemoteDelete().get();
|
||||
final var remoteDelete = message.getRemoteDelete().get();
|
||||
writer.println("Remote delete message: timestamp = {}", remoteDelete.getTargetSentTimestamp());
|
||||
}
|
||||
if (message.getMentions().isPresent()) {
|
||||
writer.println("Mentions:");
|
||||
for (SignalServiceDataMessage.Mention mention : message.getMentions().get()) {
|
||||
for (var mention : message.getMentions().get()) {
|
||||
printMention(writer, mention);
|
||||
}
|
||||
}
|
||||
if (message.getAttachments().isPresent()) {
|
||||
writer.println("Attachments:");
|
||||
for (SignalServiceAttachment attachment : message.getAttachments().get()) {
|
||||
for (var attachment : message.getAttachments().get()) {
|
||||
writer.println("- Attachment:");
|
||||
printAttachment(writer.indentedWriter(), attachment);
|
||||
}
|
||||
|
@ -233,7 +211,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
writer.println("Timestamp: {}", DateUtils.formatTimestamp(typingMessage.getTimestamp()));
|
||||
if (typingMessage.getGroupId().isPresent()) {
|
||||
writer.println("Group Info:");
|
||||
final GroupId groupId = GroupId.unknownVersion(typingMessage.getGroupId().get());
|
||||
final var groupId = GroupId.unknownVersion(typingMessage.getGroupId().get());
|
||||
printGroupInfo(writer.indentedWriter(), groupId);
|
||||
}
|
||||
}
|
||||
|
@ -261,34 +239,34 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
final PlainTextWriter writer, final SignalServiceCallMessage callMessage
|
||||
) throws IOException {
|
||||
if (callMessage.getDestinationDeviceId().isPresent()) {
|
||||
final Integer deviceId = callMessage.getDestinationDeviceId().get();
|
||||
final var deviceId = callMessage.getDestinationDeviceId().get();
|
||||
writer.println("Destination device id: {}", deviceId);
|
||||
}
|
||||
if (callMessage.getAnswerMessage().isPresent()) {
|
||||
AnswerMessage answerMessage = callMessage.getAnswerMessage().get();
|
||||
var answerMessage = callMessage.getAnswerMessage().get();
|
||||
writer.println("Answer message: {}, sdp: {})", answerMessage.getId(), answerMessage.getSdp());
|
||||
}
|
||||
if (callMessage.getBusyMessage().isPresent()) {
|
||||
BusyMessage busyMessage = callMessage.getBusyMessage().get();
|
||||
var busyMessage = callMessage.getBusyMessage().get();
|
||||
writer.println("Busy message: {}", busyMessage.getId());
|
||||
}
|
||||
if (callMessage.getHangupMessage().isPresent()) {
|
||||
HangupMessage hangupMessage = callMessage.getHangupMessage().get();
|
||||
var hangupMessage = callMessage.getHangupMessage().get();
|
||||
writer.println("Hangup message: {}", hangupMessage.getId());
|
||||
}
|
||||
if (callMessage.getIceUpdateMessages().isPresent()) {
|
||||
writer.println("Ice update messages:");
|
||||
List<IceUpdateMessage> iceUpdateMessages = callMessage.getIceUpdateMessages().get();
|
||||
for (IceUpdateMessage iceUpdateMessage : iceUpdateMessages) {
|
||||
var iceUpdateMessages = callMessage.getIceUpdateMessages().get();
|
||||
for (var iceUpdateMessage : iceUpdateMessages) {
|
||||
writer.println("- {}, sdp: {}", iceUpdateMessage.getId(), iceUpdateMessage.getSdp());
|
||||
}
|
||||
}
|
||||
if (callMessage.getOfferMessage().isPresent()) {
|
||||
OfferMessage offerMessage = callMessage.getOfferMessage().get();
|
||||
var offerMessage = callMessage.getOfferMessage().get();
|
||||
writer.println("Offer message: {}, sdp: {}", offerMessage.getId(), offerMessage.getSdp());
|
||||
}
|
||||
if (callMessage.getOpaqueMessage().isPresent()) {
|
||||
final OpaqueMessage opaqueMessage = callMessage.getOpaqueMessage().get();
|
||||
final var opaqueMessage = callMessage.getOpaqueMessage().get();
|
||||
writer.println("Opaque message: size {}", opaqueMessage.getOpaque().length);
|
||||
}
|
||||
}
|
||||
|
@ -297,8 +275,8 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
final PlainTextWriter writer, final SignalServiceSyncMessage syncMessage
|
||||
) throws IOException {
|
||||
if (syncMessage.getContacts().isPresent()) {
|
||||
final ContactsMessage contactsMessage = syncMessage.getContacts().get();
|
||||
String type = contactsMessage.isComplete() ? "complete" : "partial";
|
||||
final var contactsMessage = syncMessage.getContacts().get();
|
||||
var type = contactsMessage.isComplete() ? "complete" : "partial";
|
||||
writer.println("Received {} sync contacts:", type);
|
||||
printAttachment(writer.indentedWriter(), contactsMessage.getContactsStream());
|
||||
}
|
||||
|
@ -308,7 +286,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
}
|
||||
if (syncMessage.getRead().isPresent()) {
|
||||
writer.println("Received sync read messages list");
|
||||
for (ReadMessage rm : syncMessage.getRead().get()) {
|
||||
for (var rm : syncMessage.getRead().get()) {
|
||||
writer.println("- From: {} Message timestamp: {}",
|
||||
formatContact(rm.getSender()),
|
||||
DateUtils.formatTimestamp(rm.getTimestamp()));
|
||||
|
@ -333,7 +311,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
}
|
||||
if (syncMessage.getSent().isPresent()) {
|
||||
writer.println("Received sync sent message");
|
||||
final SentTranscriptMessage sentTranscriptMessage = syncMessage.getSent().get();
|
||||
final var sentTranscriptMessage = syncMessage.getSent().get();
|
||||
String to;
|
||||
if (sentTranscriptMessage.getDestination().isPresent()) {
|
||||
to = formatContact(sentTranscriptMessage.getDestination().get());
|
||||
|
@ -353,28 +331,28 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
.println("Expiration started at: {}",
|
||||
DateUtils.formatTimestamp(sentTranscriptMessage.getExpirationStartTimestamp()));
|
||||
}
|
||||
SignalServiceDataMessage message = sentTranscriptMessage.getMessage();
|
||||
var message = sentTranscriptMessage.getMessage();
|
||||
printDataMessage(writer.indentedWriter(), message);
|
||||
}
|
||||
if (syncMessage.getBlockedList().isPresent()) {
|
||||
writer.println("Received sync message with block list");
|
||||
writer.println("Blocked numbers:");
|
||||
final BlockedListMessage blockedList = syncMessage.getBlockedList().get();
|
||||
for (SignalServiceAddress address : blockedList.getAddresses()) {
|
||||
final var blockedList = syncMessage.getBlockedList().get();
|
||||
for (var address : blockedList.getAddresses()) {
|
||||
writer.println("- {}", address.getLegacyIdentifier());
|
||||
}
|
||||
}
|
||||
if (syncMessage.getVerified().isPresent()) {
|
||||
writer.println("Received sync message with verified identities:");
|
||||
final VerifiedMessage verifiedMessage = syncMessage.getVerified().get();
|
||||
final var verifiedMessage = syncMessage.getVerified().get();
|
||||
writer.println("- {}: {}", formatContact(verifiedMessage.getDestination()), verifiedMessage.getVerified());
|
||||
String safetyNumber = Util.formatSafetyNumber(m.computeSafetyNumber(verifiedMessage.getDestination(),
|
||||
var safetyNumber = Util.formatSafetyNumber(m.computeSafetyNumber(verifiedMessage.getDestination(),
|
||||
verifiedMessage.getIdentityKey()));
|
||||
writer.indentedWriter().println(safetyNumber);
|
||||
}
|
||||
if (syncMessage.getConfiguration().isPresent()) {
|
||||
writer.println("Received sync message with configuration:");
|
||||
final ConfigurationMessage configurationMessage = syncMessage.getConfiguration().get();
|
||||
final var configurationMessage = syncMessage.getConfiguration().get();
|
||||
if (configurationMessage.getReadReceipts().isPresent()) {
|
||||
writer.println("- Read receipts: {}",
|
||||
configurationMessage.getReadReceipts().get() ? "enabled" : "disabled");
|
||||
|
@ -393,21 +371,20 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
}
|
||||
}
|
||||
if (syncMessage.getFetchType().isPresent()) {
|
||||
final SignalServiceSyncMessage.FetchType fetchType = syncMessage.getFetchType().get();
|
||||
final var fetchType = syncMessage.getFetchType().get();
|
||||
writer.println("Received sync message with fetch type: {}", fetchType);
|
||||
}
|
||||
if (syncMessage.getViewOnceOpen().isPresent()) {
|
||||
final ViewOnceOpenMessage viewOnceOpenMessage = syncMessage.getViewOnceOpen().get();
|
||||
final var viewOnceOpenMessage = syncMessage.getViewOnceOpen().get();
|
||||
writer.println("Received sync message with view once open message:");
|
||||
writer.indentedWriter().println("Sender: {}", formatContact(viewOnceOpenMessage.getSender()));
|
||||
writer.indentedWriter()
|
||||
.println("Timestamp: {}", DateUtils.formatTimestamp(viewOnceOpenMessage.getTimestamp()));
|
||||
}
|
||||
if (syncMessage.getStickerPackOperations().isPresent()) {
|
||||
final List<StickerPackOperationMessage> stickerPackOperationMessages = syncMessage.getStickerPackOperations()
|
||||
.get();
|
||||
final var stickerPackOperationMessages = syncMessage.getStickerPackOperations().get();
|
||||
writer.println("Received sync message with sticker pack operations:");
|
||||
for (StickerPackOperationMessage m : stickerPackOperationMessages) {
|
||||
for (var m : stickerPackOperationMessages) {
|
||||
writer.println("- {}", m.getType().isPresent() ? m.getType().get() : "<unknown>");
|
||||
if (m.getPackId().isPresent()) {
|
||||
writer.indentedWriter()
|
||||
|
@ -420,7 +397,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
}
|
||||
}
|
||||
if (syncMessage.getMessageRequestResponse().isPresent()) {
|
||||
final MessageRequestResponseMessage requestResponseMessage = syncMessage.getMessageRequestResponse().get();
|
||||
final var requestResponseMessage = syncMessage.getMessageRequestResponse().get();
|
||||
writer.println("Received message request response:");
|
||||
writer.indentedWriter().println("Type: {}", requestResponseMessage.getType());
|
||||
if (requestResponseMessage.getGroupId().isPresent()) {
|
||||
|
@ -434,7 +411,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
}
|
||||
}
|
||||
if (syncMessage.getKeys().isPresent()) {
|
||||
final KeysMessage keysMessage = syncMessage.getKeys().get();
|
||||
final var keysMessage = syncMessage.getKeys().get();
|
||||
writer.println("Received sync message with keys:");
|
||||
if (keysMessage.getStorageService().isPresent()) {
|
||||
writer.println("- storage key: length: {}", keysMessage.getStorageService().get().serialize().length);
|
||||
|
@ -482,13 +459,13 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
writer.println("Text: {}", quote.getText());
|
||||
if (quote.getMentions() != null && quote.getMentions().size() > 0) {
|
||||
writer.println("Mentions:");
|
||||
for (SignalServiceDataMessage.Mention mention : quote.getMentions()) {
|
||||
for (var mention : quote.getMentions()) {
|
||||
printMention(writer, mention);
|
||||
}
|
||||
}
|
||||
if (quote.getAttachments().size() > 0) {
|
||||
writer.println("Attachments:");
|
||||
for (SignalServiceDataMessage.Quote.QuotedAttachment attachment : quote.getAttachments()) {
|
||||
for (var attachment : quote.getAttachments()) {
|
||||
writer.println("- Filename: {}", attachment.getFileName());
|
||||
writer.indent(w -> {
|
||||
w.println("Type: {}", attachment.getContentType());
|
||||
|
@ -503,7 +480,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
|
||||
private void printSharedContact(final PlainTextWriter writer, final SharedContact contact) throws IOException {
|
||||
writer.println("Name:");
|
||||
SharedContact.Name name = contact.getName();
|
||||
var name = contact.getName();
|
||||
writer.indent(w -> {
|
||||
if (name.getDisplay().isPresent() && !name.getDisplay().get().isBlank()) {
|
||||
w.println("Display name: {}", name.getDisplay().get());
|
||||
|
@ -526,7 +503,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
});
|
||||
|
||||
if (contact.getAvatar().isPresent()) {
|
||||
SharedContact.Avatar avatar = contact.getAvatar().get();
|
||||
var avatar = contact.getAvatar().get();
|
||||
writer.println("Avatar: (profile: {})", avatar.isProfile());
|
||||
printAttachment(writer.indentedWriter(), avatar.getAttachment());
|
||||
}
|
||||
|
@ -537,7 +514,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
|
||||
if (contact.getPhone().isPresent()) {
|
||||
writer.println("Phone details:");
|
||||
for (SharedContact.Phone phone : contact.getPhone().get()) {
|
||||
for (var phone : contact.getPhone().get()) {
|
||||
writer.println("- Phone:");
|
||||
writer.indent(w -> {
|
||||
if (phone.getValue() != null) {
|
||||
|
@ -555,7 +532,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
|
||||
if (contact.getEmail().isPresent()) {
|
||||
writer.println("Email details:");
|
||||
for (SharedContact.Email email : contact.getEmail().get()) {
|
||||
for (var email : contact.getEmail().get()) {
|
||||
writer.println("- Email:");
|
||||
writer.indent(w -> {
|
||||
if (email.getValue() != null) {
|
||||
|
@ -573,7 +550,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
|
||||
if (contact.getAddress().isPresent()) {
|
||||
writer.println("Address details:");
|
||||
for (SharedContact.PostalAddress address : contact.getAddress().get()) {
|
||||
for (var address : contact.getAddress().get()) {
|
||||
writer.println("- Address:");
|
||||
writer.indent(w -> {
|
||||
if (address.getType() != null) {
|
||||
|
@ -611,14 +588,14 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
private void printGroupContext(
|
||||
final PlainTextWriter writer, final SignalServiceGroupContext groupContext
|
||||
) throws IOException {
|
||||
final GroupId groupId = GroupUtils.getGroupId(groupContext);
|
||||
final var groupId = GroupUtils.getGroupId(groupContext);
|
||||
if (groupContext.getGroupV1().isPresent()) {
|
||||
SignalServiceGroup groupInfo = groupContext.getGroupV1().get();
|
||||
var groupInfo = groupContext.getGroupV1().get();
|
||||
printGroupInfo(writer, groupId);
|
||||
writer.println("Type: {}", groupInfo.getType());
|
||||
if (groupInfo.getMembers().isPresent()) {
|
||||
writer.println("Members:");
|
||||
for (SignalServiceAddress member : groupInfo.getMembers().get()) {
|
||||
for (var member : groupInfo.getMembers().get()) {
|
||||
writer.println("- {}", formatContact(member));
|
||||
}
|
||||
}
|
||||
|
@ -627,7 +604,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
printAttachment(writer.indentedWriter(), groupInfo.getAvatar().get());
|
||||
}
|
||||
} else if (groupContext.getGroupV2().isPresent()) {
|
||||
final SignalServiceGroupV2 groupInfo = groupContext.getGroupV2().get();
|
||||
final var groupInfo = groupContext.getGroupV2().get();
|
||||
printGroupInfo(writer, groupId);
|
||||
writer.println("Revision: {}", groupInfo.getRevision());
|
||||
writer.println("Master key length: {}", groupInfo.getMasterKey().serialize().length);
|
||||
|
@ -638,7 +615,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
private void printGroupInfo(final PlainTextWriter writer, final GroupId groupId) throws IOException {
|
||||
writer.println("Id: {}", groupId.toBase64());
|
||||
|
||||
GroupInfo group = m.getGroup(groupId);
|
||||
var group = m.getGroup(groupId);
|
||||
if (group != null) {
|
||||
writer.println("Name: {}", group.getTitle());
|
||||
} else {
|
||||
|
@ -649,8 +626,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
private void printMention(
|
||||
PlainTextWriter writer, SignalServiceDataMessage.Mention mention
|
||||
) throws IOException {
|
||||
final SignalServiceAddress address = m.resolveSignalServiceAddress(new SignalServiceAddress(mention.getUuid(),
|
||||
null));
|
||||
final var address = m.resolveSignalServiceAddress(new SignalServiceAddress(mention.getUuid(), null));
|
||||
writer.println("- {}: {} (length: {})", formatContact(address), mention.getStart(), mention.getLength());
|
||||
}
|
||||
|
||||
|
@ -658,7 +634,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
writer.println("Content-Type: {}", attachment.getContentType());
|
||||
writer.println("Type: {}", attachment.isPointer() ? "Pointer" : attachment.isStream() ? "Stream" : "<unknown>");
|
||||
if (attachment.isPointer()) {
|
||||
final SignalServiceAttachmentPointer pointer = attachment.asPointer();
|
||||
final var pointer = attachment.asPointer();
|
||||
writer.println("Id: {} Key length: {}", pointer.getRemoteId(), pointer.getKey().length);
|
||||
if (pointer.getUploadTimestamp() > 0) {
|
||||
writer.println("Upload timestamp: {}", DateUtils.formatTimestamp(pointer.getUploadTimestamp()));
|
||||
|
@ -679,7 +655,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
if (pointer.getWidth() > 0 || pointer.getHeight() > 0) {
|
||||
writer.println("Dimensions: {}x{}", pointer.getWidth(), pointer.getHeight());
|
||||
}
|
||||
File file = m.getAttachmentFile(pointer.getRemoteId());
|
||||
var file = m.getAttachmentFile(pointer.getRemoteId());
|
||||
if (file.exists()) {
|
||||
writer.println("Stored plaintext in: {}", file);
|
||||
}
|
||||
|
@ -687,8 +663,8 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
}
|
||||
|
||||
private String formatContact(SignalServiceAddress address) {
|
||||
final String number = address.getLegacyIdentifier();
|
||||
String name = m.getContactOrProfileName(number);
|
||||
final var number = address.getLegacyIdentifier();
|
||||
var name = m.getContactOrProfileName(number);
|
||||
if (name == null) {
|
||||
return number;
|
||||
} else {
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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.");
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)" : "")
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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) + "\" …");
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -6,10 +6,8 @@ import org.asamk.signal.manager.Manager;
|
|||
import org.asamk.signal.manager.groups.GroupId;
|
||||
import org.asamk.signal.manager.groups.GroupNotFoundException;
|
||||
import org.asamk.signal.manager.groups.NotAGroupMemberException;
|
||||
import org.asamk.signal.manager.storage.groups.GroupInfo;
|
||||
import org.asamk.signal.util.ErrorUtils;
|
||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||
import org.whispersystems.libsignal.util.Pair;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
import org.whispersystems.signalservice.api.messages.SendMessageResult;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
|
@ -41,19 +39,19 @@ public class DbusSignalImpl implements Signal {
|
|||
|
||||
@Override
|
||||
public long sendMessage(final String message, final List<String> attachments, final String recipient) {
|
||||
List<String> recipients = new ArrayList<>(1);
|
||||
var recipients = new ArrayList<String>(1);
|
||||
recipients.add(recipient);
|
||||
return sendMessage(message, attachments, recipients);
|
||||
}
|
||||
|
||||
private static void checkSendMessageResult(long timestamp, SendMessageResult result) throws DBusExecutionException {
|
||||
String error = ErrorUtils.getErrorMessageFromSendMessageResult(result);
|
||||
var error = ErrorUtils.getErrorMessageFromSendMessageResult(result);
|
||||
|
||||
if (error == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String message = timestamp + "\nFailed to send message:\n" + error + '\n';
|
||||
final var message = timestamp + "\nFailed to send message:\n" + error + '\n';
|
||||
|
||||
if (result.getIdentityFailure() != null) {
|
||||
throw new Error.UntrustedIdentity(message);
|
||||
|
@ -70,15 +68,15 @@ public class DbusSignalImpl implements Signal {
|
|||
return;
|
||||
}
|
||||
|
||||
List<String> errors = ErrorUtils.getErrorMessagesFromSendMessageResults(results);
|
||||
var errors = ErrorUtils.getErrorMessagesFromSendMessageResults(results);
|
||||
if (errors.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder message = new StringBuilder();
|
||||
var message = new StringBuilder();
|
||||
message.append(timestamp).append('\n');
|
||||
message.append("Failed to send (some) messages:\n");
|
||||
for (String error : errors) {
|
||||
for (var error : errors) {
|
||||
message.append(error).append('\n');
|
||||
}
|
||||
|
||||
|
@ -88,7 +86,7 @@ public class DbusSignalImpl implements Signal {
|
|||
@Override
|
||||
public long sendMessage(final String message, final List<String> attachments, final List<String> recipients) {
|
||||
try {
|
||||
final Pair<Long, List<SendMessageResult>> results = m.sendMessage(message, attachments, recipients);
|
||||
final var results = m.sendMessage(message, attachments, recipients);
|
||||
checkSendMessageResults(results.first(), results.second());
|
||||
return results.first();
|
||||
} catch (InvalidNumberException e) {
|
||||
|
@ -105,7 +103,7 @@ public class DbusSignalImpl implements Signal {
|
|||
final String message, final List<String> attachments
|
||||
) throws Error.AttachmentInvalid, Error.Failure, Error.UntrustedIdentity {
|
||||
try {
|
||||
final Pair<Long, SendMessageResult> results = m.sendSelfMessage(message, attachments);
|
||||
final var results = m.sendSelfMessage(message, attachments);
|
||||
checkSendMessageResult(results.first(), results.second());
|
||||
return results.first();
|
||||
} catch (AttachmentInvalidException e) {
|
||||
|
@ -118,7 +116,7 @@ public class DbusSignalImpl implements Signal {
|
|||
@Override
|
||||
public void sendEndSessionMessage(final List<String> recipients) {
|
||||
try {
|
||||
final Pair<Long, List<SendMessageResult>> results = m.sendEndSessionMessage(recipients);
|
||||
final var results = m.sendEndSessionMessage(recipients);
|
||||
checkSendMessageResults(results.first(), results.second());
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure(e.getMessage());
|
||||
|
@ -130,9 +128,7 @@ public class DbusSignalImpl implements Signal {
|
|||
@Override
|
||||
public long sendGroupMessage(final String message, final List<String> attachments, final byte[] groupId) {
|
||||
try {
|
||||
Pair<Long, List<SendMessageResult>> results = m.sendGroupMessage(message,
|
||||
attachments,
|
||||
GroupId.unknownVersion(groupId));
|
||||
var results = m.sendGroupMessage(message, attachments, GroupId.unknownVersion(groupId));
|
||||
checkSendMessageResults(results.first(), results.second());
|
||||
return results.first();
|
||||
} catch (IOException e) {
|
||||
|
@ -182,9 +178,9 @@ public class DbusSignalImpl implements Signal {
|
|||
|
||||
@Override
|
||||
public List<byte[]> getGroupIds() {
|
||||
List<GroupInfo> groups = m.getGroups();
|
||||
List<byte[]> ids = new ArrayList<>(groups.size());
|
||||
for (GroupInfo group : groups) {
|
||||
var groups = m.getGroups();
|
||||
var ids = new ArrayList<byte[]>(groups.size());
|
||||
for (var group : groups) {
|
||||
ids.add(group.getGroupId().serialize());
|
||||
}
|
||||
return ids;
|
||||
|
@ -192,7 +188,7 @@ public class DbusSignalImpl implements Signal {
|
|||
|
||||
@Override
|
||||
public String getGroupName(final byte[] groupId) {
|
||||
GroupInfo group = m.getGroup(GroupId.unknownVersion(groupId));
|
||||
var group = m.getGroup(GroupId.unknownVersion(groupId));
|
||||
if (group == null) {
|
||||
return "";
|
||||
} else {
|
||||
|
@ -202,7 +198,7 @@ public class DbusSignalImpl implements Signal {
|
|||
|
||||
@Override
|
||||
public List<String> getGroupMembers(final byte[] groupId) {
|
||||
GroupInfo group = m.getGroup(GroupId.unknownVersion(groupId));
|
||||
var group = m.getGroup(GroupId.unknownVersion(groupId));
|
||||
if (group == null) {
|
||||
return List.of();
|
||||
} else {
|
||||
|
@ -229,9 +225,10 @@ public class DbusSignalImpl implements Signal {
|
|||
if (avatar.isEmpty()) {
|
||||
avatar = null;
|
||||
}
|
||||
final Pair<GroupId, List<SendMessageResult>> results = m.updateGroup(groupId == null
|
||||
? null
|
||||
: GroupId.unknownVersion(groupId), name, members, avatar == null ? null : new File(avatar));
|
||||
final var results = m.updateGroup(groupId == null ? null : GroupId.unknownVersion(groupId),
|
||||
name,
|
||||
members,
|
||||
avatar == null ? null : new File(avatar));
|
||||
checkSendMessageResults(0, results.second());
|
||||
return results.first().serialize();
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -3,8 +3,6 @@ package org.asamk.signal.json;
|
|||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream;
|
||||
|
||||
class JsonAttachment {
|
||||
|
||||
|
@ -24,12 +22,12 @@ class JsonAttachment {
|
|||
this.contentType = attachment.getContentType();
|
||||
|
||||
if (attachment.isPointer()) {
|
||||
final SignalServiceAttachmentPointer pointer = attachment.asPointer();
|
||||
final var pointer = attachment.asPointer();
|
||||
this.id = pointer.getRemoteId().toString();
|
||||
this.filename = pointer.getFileName().orNull();
|
||||
this.size = pointer.getSize().transform(Integer::longValue).orNull();
|
||||
} else {
|
||||
final SignalServiceAttachmentStream stream = attachment.asStream();
|
||||
final var stream = attachment.asStream();
|
||||
this.id = null;
|
||||
this.filename = stream.getFileName().orNull();
|
||||
this.size = stream.getLength();
|
||||
|
|
|
@ -6,9 +6,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||
import org.asamk.Signal;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroupContext;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroupV2;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -63,12 +60,12 @@ class JsonDataMessage {
|
|||
JsonDataMessage(SignalServiceDataMessage dataMessage, Manager m) {
|
||||
this.timestamp = dataMessage.getTimestamp();
|
||||
if (dataMessage.getGroupContext().isPresent()) {
|
||||
final SignalServiceGroupContext groupContext = dataMessage.getGroupContext().get();
|
||||
final var groupContext = dataMessage.getGroupContext().get();
|
||||
if (groupContext.getGroupV1().isPresent()) {
|
||||
SignalServiceGroup groupInfo = groupContext.getGroupV1().get();
|
||||
var groupInfo = groupContext.getGroupV1().get();
|
||||
this.groupInfo = new JsonGroupInfo(groupInfo);
|
||||
} else if (groupContext.getGroupV2().isPresent()) {
|
||||
SignalServiceGroupV2 groupInfo = groupContext.getGroupV2().get();
|
||||
var groupInfo = groupContext.getGroupV2().get();
|
||||
this.groupInfo = new JsonGroupInfo(groupInfo);
|
||||
} else {
|
||||
this.groupInfo = null;
|
||||
|
|
|
@ -7,7 +7,6 @@ import org.asamk.Signal;
|
|||
import org.asamk.signal.manager.Manager;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceContent;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -48,7 +47,7 @@ public class JsonMessageEnvelope {
|
|||
|
||||
public JsonMessageEnvelope(SignalServiceEnvelope envelope, SignalServiceContent content, Manager m) {
|
||||
if (!envelope.isUnidentifiedSender() && envelope.hasSource()) {
|
||||
SignalServiceAddress source = envelope.getSourceAddress();
|
||||
var source = envelope.getSourceAddress();
|
||||
this.source = source.getLegacyIdentifier();
|
||||
this.sourceDevice = envelope.getSourceDevice();
|
||||
this.relay = source.getRelay().orNull();
|
||||
|
|
|
@ -45,7 +45,7 @@ class JsonSyncMessage {
|
|||
? new JsonSyncDataMessage(syncMessage.getSent().get(), m)
|
||||
: null;
|
||||
if (syncMessage.getBlockedList().isPresent()) {
|
||||
final Base64.Encoder base64 = Base64.getEncoder();
|
||||
final var base64 = Base64.getEncoder();
|
||||
this.blockedNumbers = syncMessage.getBlockedList()
|
||||
.get()
|
||||
.getAddresses()
|
||||
|
|
|
@ -22,7 +22,7 @@ class JsonTypingMessage {
|
|||
JsonTypingMessage(SignalServiceTypingMessage typingMessage) {
|
||||
this.action = typingMessage.getAction().name();
|
||||
this.timestamp = typingMessage.getTimestamp();
|
||||
final Base64.Encoder encoder = Base64.getEncoder();
|
||||
final var encoder = Base64.getEncoder();
|
||||
this.groupId = typingMessage.getGroupId().transform(encoder::encodeToString).orNull();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ public class DateUtils {
|
|||
}
|
||||
|
||||
public static String formatTimestamp(long timestamp) {
|
||||
Date date = new Date(timestamp);
|
||||
var date = new Date(timestamp);
|
||||
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"); // Quoted "Z" to indicate UTC, no timezone offset
|
||||
df.setTimeZone(tzUTC);
|
||||
return timestamp + " (" + df.format(date) + ")";
|
||||
|
|
|
@ -26,14 +26,14 @@ public class ErrorUtils {
|
|||
if (timestamp != 0) {
|
||||
System.out.println(timestamp);
|
||||
}
|
||||
List<String> errors = getErrorMessagesFromSendMessageResults(results);
|
||||
var errors = getErrorMessagesFromSendMessageResults(results);
|
||||
return handleSendMessageResultErrors(errors);
|
||||
}
|
||||
|
||||
public static List<String> getErrorMessagesFromSendMessageResults(List<SendMessageResult> results) {
|
||||
List<String> errors = new ArrayList<>();
|
||||
for (SendMessageResult result : results) {
|
||||
String error = getErrorMessageFromSendMessageResult(result);
|
||||
var errors = new ArrayList<String>();
|
||||
for (var result : results) {
|
||||
var error = getErrorMessageFromSendMessageResult(result);
|
||||
if (error != null) {
|
||||
errors.add(error);
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public class ErrorUtils {
|
|||
return 0;
|
||||
}
|
||||
System.err.println("Failed to send (some) messages:");
|
||||
for (String error : errors) {
|
||||
for (var error : errors) {
|
||||
System.err.println(error);
|
||||
}
|
||||
return 3;
|
||||
|
|
|
@ -8,8 +8,8 @@ public class Hex {
|
|||
}
|
||||
|
||||
public static String toString(byte[] bytes) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (final byte aByte : bytes) {
|
||||
var buf = new StringBuffer();
|
||||
for (final var aByte : bytes) {
|
||||
appendHexChar(buf, aByte);
|
||||
buf.append(" ");
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ public class Hex {
|
|||
}
|
||||
|
||||
public static String toStringCondensed(byte[] bytes) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (final byte aByte : bytes) {
|
||||
var buf = new StringBuffer();
|
||||
for (final var aByte : bytes) {
|
||||
appendHexChar(buf, aByte);
|
||||
}
|
||||
return buf.toString();
|
||||
|
@ -30,9 +30,9 @@ public class Hex {
|
|||
}
|
||||
|
||||
public static byte[] toByteArray(String s) {
|
||||
int len = s.length();
|
||||
byte[] data = new byte[len / 2];
|
||||
for (int i = 0; i < len; i += 2) {
|
||||
var len = s.length();
|
||||
var data = new byte[len / 2];
|
||||
for (var i = 0; i < len; i += 2) {
|
||||
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16));
|
||||
}
|
||||
return data;
|
||||
|
|
|
@ -12,8 +12,8 @@ public class IOUtils {
|
|||
}
|
||||
|
||||
public static String readAll(InputStream in, Charset charset) throws IOException {
|
||||
StringWriter output = new StringWriter();
|
||||
byte[] buffer = new byte[4096];
|
||||
var output = new StringWriter();
|
||||
var buffer = new byte[4096];
|
||||
int n;
|
||||
while (-1 != (n = in.read(buffer))) {
|
||||
output.write(new String(buffer, 0, n, charset));
|
||||
|
@ -22,7 +22,7 @@ public class IOUtils {
|
|||
}
|
||||
|
||||
public static File getDataHomeDir() {
|
||||
String dataHome = System.getenv("XDG_DATA_HOME");
|
||||
var dataHome = System.getenv("XDG_DATA_HOME");
|
||||
if (dataHome != null) {
|
||||
return new File(dataHome);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.security.SecureRandom;
|
|||
public class RandomUtils {
|
||||
|
||||
private static final ThreadLocal<SecureRandom> LOCAL_RANDOM = ThreadLocal.withInitial(() -> {
|
||||
SecureRandom rand = getSecureRandomUnseeded();
|
||||
var rand = getSecureRandomUnseeded();
|
||||
|
||||
// Let the SecureRandom seed it self initially
|
||||
rand.nextBoolean();
|
||||
|
|
|
@ -10,7 +10,7 @@ public class Util {
|
|||
}
|
||||
|
||||
public static String getStringIfNotBlank(Optional<String> value) {
|
||||
String string = value.orNull();
|
||||
var string = value.orNull();
|
||||
if (string == null || string.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
|
@ -18,10 +18,10 @@ public class Util {
|
|||
}
|
||||
|
||||
public static String formatSafetyNumber(String digits) {
|
||||
final int partCount = 12;
|
||||
int partSize = digits.length() / partCount;
|
||||
StringBuilder f = new StringBuilder(digits.length() + partCount);
|
||||
for (int i = 0; i < partCount; i++) {
|
||||
final var partCount = 12;
|
||||
var partSize = digits.length() / partCount;
|
||||
var f = new StringBuilder(digits.length() + partCount);
|
||||
for (var i = 0; i < partCount; i++) {
|
||||
f.append(digits, i * partSize, (i * partSize) + partSize).append(" ");
|
||||
}
|
||||
return f.toString();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue