mirror of
https://github.com/AsamK/signal-cli
synced 2025-09-02 20:40:38 +00:00
Cleanups and proper logging.
This commit is contained in:
parent
ee99815918
commit
9d3dc8f735
1 changed files with 19 additions and 6 deletions
|
@ -8,9 +8,13 @@ import net.sourceforge.argparse4j.inf.Namespace;
|
|||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
|
||||
import org.asamk.signal.JsonReceiveMessageHandler;
|
||||
import org.asamk.signal.JsonWriter;
|
||||
import org.asamk.signal.OutputType;
|
||||
import org.asamk.signal.ReceiveMessageHandler;
|
||||
import org.asamk.signal.manager.AttachmentInvalidException;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
|
||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||
|
||||
|
@ -19,6 +23,7 @@ import java.io.IOException;
|
|||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
|
||||
|
@ -32,6 +37,7 @@ class JsonInterface {
|
|||
}
|
||||
|
||||
class InputReader implements Runnable {
|
||||
private final static Logger logger = LoggerFactory.getLogger(InputReader.class);
|
||||
|
||||
private volatile boolean alive = true;
|
||||
private final Manager m;
|
||||
|
@ -66,11 +72,11 @@ class InputReader implements Runnable {
|
|||
}
|
||||
try {
|
||||
// verbosity flag? better yet, json acknowledgement with timestamp or message id?
|
||||
System.out.println("sentMessage '" + command.content + "' to " + command.recipient);
|
||||
this.m.sendMessage(command.content, attachments, recipients);
|
||||
logger.info("sentMessage '" + command.content + "' to " + command.recipient);
|
||||
} catch (AssertionError | AttachmentInvalidException | InvalidNumberException e) {
|
||||
System.err.println("error in sending message");
|
||||
e.printStackTrace(System.out);
|
||||
logger.error("Error in sending message", e);
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
} /* elif (command.commandName == "sendTyping") {
|
||||
getMessageSender().sendTyping(signalServiceAddress?, ....)
|
||||
|
@ -87,19 +93,26 @@ class InputReader implements Runnable {
|
|||
}
|
||||
|
||||
public class StdioCommand implements LocalCommand {
|
||||
private final static Logger logger = LoggerFactory.getLogger(StdioCommand.class);
|
||||
|
||||
@Override
|
||||
public void attachToSubparser(final Subparser subparser) {
|
||||
subparser.addArgument("--ignore-attachments")
|
||||
.help("Don’t download attachments of received messages.")
|
||||
.action(Arguments.storeTrue());
|
||||
subparser.addArgument("--json") // should maybe remove this
|
||||
.help("Output received messages in json format, one json object per line.")
|
||||
subparser.addArgument("--json")
|
||||
.help("WARNING: This parameter is now deprecated! Please use the global \"--output=json\" option instead.\n\nOutput received messages in json format, one json object per line.")
|
||||
.action(Arguments.storeTrue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<OutputType> getSupportedOutputTypes() {
|
||||
return Set.of(OutputType.PLAIN_TEXT, OutputType.JSON);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCommand(final Namespace ns, final Manager m) {
|
||||
var inJson = ns.get("output") == OutputType.JSON || ns.getBoolean("json");
|
||||
boolean ignoreAttachments = ns.getBoolean("ignore_attachments");
|
||||
InputReader reader = new InputReader(m);
|
||||
Thread readerThread = new Thread(reader);
|
||||
|
@ -109,7 +122,7 @@ public class StdioCommand implements LocalCommand {
|
|||
TimeUnit.HOURS,
|
||||
false,
|
||||
ignoreAttachments,
|
||||
ns.getBoolean("json") ? new JsonReceiveMessageHandler(m) : new ReceiveMessageHandler(m)
|
||||
inJson ? new JsonReceiveMessageHandler(m) : new ReceiveMessageHandler(m)
|
||||
/*true*/);
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error while receiving messages: " + e.getMessage());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue