X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/6c9f26f49b46d39421e822cf0be6b299f161c5bf..0a68303ca448f69a5655beb23f4213187dbce0b4:/src/main/java/org/asamk/signal/Main.java diff --git a/src/main/java/org/asamk/signal/Main.java b/src/main/java/org/asamk/signal/Main.java index 5dd471f9..2377e125 100644 --- a/src/main/java/org/asamk/signal/Main.java +++ b/src/main/java/org/asamk/signal/Main.java @@ -46,6 +46,7 @@ import java.security.Security; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; public class Main { @@ -87,6 +88,9 @@ public class Main { ts = (Signal) dBusConn.getRemoteObject( SIGNAL_BUSNAME, SIGNAL_OBJECTPATH, Signal.class); + } catch (UnsatisfiedLinkError e) { + System.err.println("Missing native library dependency for dbus service: " + e.getMessage()); + return 1; } catch (DBusException e) { e.printStackTrace(); if (dBusConn != null) { @@ -134,6 +138,38 @@ public class Main { return 3; } break; + case "unregister": + if (dBusConn != null) { + System.err.println("unregister is not yet implemented via dbus"); + return 1; + } + if (!m.isRegistered()) { + System.err.println("User is not registered."); + return 1; + } + try { + m.unregister(); + } catch (IOException e) { + System.err.println("Unregister error: " + e.getMessage()); + return 3; + } + break; + case "updateAccount": + if (dBusConn != null) { + System.err.println("updateAccount is not yet implemented via dbus"); + return 1; + } + if (!m.isRegistered()) { + System.err.println("User is not registered."); + return 1; + } + try { + m.updateAccountAttributes(); + } catch (IOException e) { + System.err.println("UpdateAccount error: " + e.getMessage()); + return 3; + } + break; case "verify": if (dBusConn != null) { System.err.println("verify is not yet implemented via dbus"); @@ -177,6 +213,9 @@ public class Main { } catch (IOException e) { System.err.println("Link request error: " + e.getMessage()); return 3; + } catch (AssertionError e) { + handleAssertionError(e); + return 1; } catch (InvalidKeyException e) { e.printStackTrace(); return 2; @@ -202,6 +241,9 @@ public class Main { } catch (InvalidKeyException e) { e.printStackTrace(); return 2; + } catch (AssertionError e) { + handleAssertionError(e); + return 1; } catch (URISyntaxException e) { e.printStackTrace(); return 2; @@ -221,8 +263,8 @@ public class Main { for (DeviceInfo d : devices) { System.out.println("Device " + d.getId() + (d.getId() == m.getDeviceId() ? " (this device)" : "") + ":"); System.out.println(" Name: " + d.getName()); - System.out.println(" Created: " + d.getCreated()); - System.out.println(" Last seen: " + d.getLastSeen()); + System.out.println(" Created: " + formatTimestamp(d.getCreated())); + System.out.println(" Last seen: " + formatTimestamp(d.getLastSeen())); } } catch (IOException e) { e.printStackTrace(); @@ -343,6 +385,9 @@ public class Main { System.out.println(); } }); + } catch (UnsatisfiedLinkError e) { + System.err.println("Missing native library dependency for dbus service: " + e.getMessage()); + return 1; } catch (DBusException e) { e.printStackTrace(); return 1; @@ -359,17 +404,18 @@ public class Main { System.err.println("User is not registered."); return 1; } - int timeout = 5; - if (ns.getInt("timeout") != null) { - timeout = ns.getInt("timeout"); + double timeout = 5; + if (ns.getDouble("timeout") != null) { + timeout = ns.getDouble("timeout"); } boolean returnOnTimeout = true; if (timeout < 0) { returnOnTimeout = false; timeout = 3600; } + boolean ignoreAttachments = ns.getBoolean("ignore_attachments"); try { - m.receiveMessages(timeout, returnOnTimeout, new ReceiveMessageHandler(m)); + m.receiveMessages((long) (timeout * 1000), TimeUnit.MILLISECONDS, returnOnTimeout, ignoreAttachments, new ReceiveMessageHandler(m)); } catch (IOException e) { System.err.println("Error while receiving messages: " + e.getMessage()); return 3; @@ -538,12 +584,16 @@ public class Main { conn = DBusConnection.getConnection(busType); conn.exportObject(SIGNAL_OBJECTPATH, m); conn.requestBusName(SIGNAL_BUSNAME); + } catch (UnsatisfiedLinkError e) { + System.err.println("Missing native library dependency for dbus service: " + e.getMessage()); + return 1; } catch (DBusException e) { e.printStackTrace(); return 2; } + ignoreAttachments = ns.getBoolean("ignore_attachments"); try { - m.receiveMessages(3600, false, new DbusReceiveMessageHandler(m, conn)); + m.receiveMessages(1, TimeUnit.HOURS, false, ignoreAttachments, new DbusReceiveMessageHandler(m, conn)); } catch (IOException e) { System.err.println("Error while receiving messages: " + e.getMessage()); return 3; @@ -661,6 +711,12 @@ public class Main { .help("The verification should be done over voice, not sms.") .action(Arguments.storeTrue()); + Subparser parserUnregister = subparsers.addParser("unregister"); + parserUnregister.help("Unregister the current device from the signal server."); + + Subparser parserUpdateAccount = subparsers.addParser("updateAccount"); + parserUpdateAccount.help("Update the account attributes on the signal server."); + Subparser parserVerify = subparsers.addParser("verify"); parserVerify.addArgument("verificationCode") .help("The verification code you received via sms or voice call."); @@ -713,13 +769,19 @@ public class Main { Subparser parserReceive = subparsers.addParser("receive"); parserReceive.addArgument("-t", "--timeout") - .type(int.class) + .type(double.class) .help("Number of seconds to wait for new messages (negative values disable timeout)"); + parserReceive.addArgument("--ignore-attachments") + .help("Don’t download attachments of received messages.") + .action(Arguments.storeTrue()); Subparser parserDaemon = subparsers.addParser("daemon"); parserDaemon.addArgument("--system") .action(Arguments.storeTrue()) .help("Use DBus system bus instead of user bus."); + parserDaemon.addArgument("--ignore-attachments") + .help("Don’t download attachments of received messages.") + .action(Arguments.storeTrue()); try { Namespace ns = parser.parseArgs(args);