]> nmode's Git Repositories - signal-cli/commitdiff
Add --ignore-attachments flag to receive and daemon command
authorAsamK <asamk@gmx.de>
Thu, 22 Dec 2016 11:27:43 +0000 (12:27 +0100)
committerAsamK <asamk@gmx.de>
Thu, 22 Dec 2016 11:27:55 +0000 (12:27 +0100)
Fixes #41

man/signal-cli.1.txt
src/main/java/org/asamk/signal/Main.java
src/main/java/org/asamk/signal/Manager.java

index 52d56f68eb7b467c179e3face6bbb77ef2747b7e..c4800d61656e6f6b43b4eccae2e600d912ea31ab 100644 (file)
@@ -120,6 +120,8 @@ attachments are downloaded to the config directory.
 *-t* TIMEOUT, *--timeout* TIMEOUT::
        Number of seconds to wait for new messages (negative values disable timeout).
        Default is 5 seconds.
+*--ignore-attachments*::
+       Don’t download attachments of received messages.
 
 updateGroup
 ~~~~~~~~~~~
@@ -179,6 +181,8 @@ libunixsocket-java ArchLinux: libmatthew-unix-java (AUR)).
 
 *--system*::
        Use DBus system bus instead of user bus.
+*--ignore-attachments*::
+       Don’t download attachments of received messages.
 
 
 Examples
index d67bfca00779cab2f50b55dd9dadd351d54977d6..7d89d4802e9eb946f3174d87eb974b4c68f40d5b 100644 (file)
@@ -375,8 +375,9 @@ public class Main {
                         returnOnTimeout = false;
                         timeout = 3600;
                     }
+                    boolean ignoreAttachments = ns.getBoolean("ignore_attachments");
                     try {
-                        m.receiveMessages((long) (timeout * 1000), TimeUnit.MILLISECONDS, 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;
@@ -549,8 +550,9 @@ public class Main {
                             e.printStackTrace();
                             return 2;
                         }
+                        ignoreAttachments = ns.getBoolean("ignore_attachments");
                         try {
-                            m.receiveMessages(1, TimeUnit.HOURS, 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;
@@ -722,11 +724,17 @@ public class Main {
         parserReceive.addArgument("-t", "--timeout")
                 .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);
index 78b66da7328fbc2bdeb4e983fbf70197a7541714..e5214302700dfce1491ce3ccb0e4226b69b1fa9a 100644 (file)
@@ -883,7 +883,7 @@ class Manager implements Signal {
         void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent decryptedContent, Throwable e);
     }
 
-    private void handleSignalServiceDataMessage(SignalServiceDataMessage message, boolean isSync, String source, String destination) {
+    private void handleSignalServiceDataMessage(SignalServiceDataMessage message, boolean isSync, String source, String destination, boolean ignoreAttachments) {
         String threadId;
         if (message.getGroupInfo().isPresent()) {
             SignalServiceGroup groupInfo = message.getGroupInfo().get();
@@ -970,7 +970,7 @@ class Manager implements Signal {
                 threadStore.updateThread(thread);
             }
         }
-        if (message.getAttachments().isPresent()) {
+        if (message.getAttachments().isPresent() && !ignoreAttachments) {
             for (SignalServiceAttachment attachment : message.getAttachments().get()) {
                 if (attachment.isPointer()) {
                     try {
@@ -983,7 +983,7 @@ class Manager implements Signal {
         }
     }
 
-    public void retryFailedReceivedMessages(ReceiveMessageHandler handler) {
+    public void retryFailedReceivedMessages(ReceiveMessageHandler handler, boolean ignoreAttachments) {
         final File cachePath = new File(getMessageCachePath());
         if (!cachePath.exists()) {
             return;
@@ -1014,7 +1014,7 @@ class Manager implements Signal {
                     } catch (Exception e) {
                         continue;
                     }
-                    handleMessage(envelope, content);
+                    handleMessage(envelope, content, ignoreAttachments);
                 }
                 save();
                 handler.handleMessage(envelope, content, null);
@@ -1027,8 +1027,8 @@ class Manager implements Signal {
         }
     }
 
-    public void receiveMessages(long timeout, TimeUnit unit, boolean returnOnTimeout, ReceiveMessageHandler handler) throws IOException {
-        retryFailedReceivedMessages(handler);
+    public void receiveMessages(long timeout, TimeUnit unit, boolean returnOnTimeout, boolean ignoreAttachments, ReceiveMessageHandler handler) throws IOException {
+        retryFailedReceivedMessages(handler, ignoreAttachments);
         final SignalServiceMessageReceiver messageReceiver = new SignalServiceMessageReceiver(URL, TRUST_STORE, username, password, deviceId, signalingKey, USER_AGENT);
         SignalServiceMessagePipe messagePipe = null;
 
@@ -1067,7 +1067,7 @@ class Manager implements Signal {
                     } catch (Exception e) {
                         exception = e;
                     }
-                    handleMessage(envelope, content);
+                    handleMessage(envelope, content, ignoreAttachments);
                 }
                 save();
                 handler.handleMessage(envelope, content, exception);
@@ -1087,17 +1087,17 @@ class Manager implements Signal {
         }
     }
 
-    private void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content) {
+    private void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, boolean ignoreAttachments) {
         if (content != null) {
             if (content.getDataMessage().isPresent()) {
                 SignalServiceDataMessage message = content.getDataMessage().get();
-                handleSignalServiceDataMessage(message, false, envelope.getSource(), username);
+                handleSignalServiceDataMessage(message, false, envelope.getSource(), username, ignoreAttachments);
             }
             if (content.getSyncMessage().isPresent()) {
                 SignalServiceSyncMessage syncMessage = content.getSyncMessage().get();
                 if (syncMessage.getSent().isPresent()) {
                     SignalServiceDataMessage message = syncMessage.getSent().get().getMessage();
-                    handleSignalServiceDataMessage(message, true, envelope.getSource(), syncMessage.getSent().get().getDestination().get());
+                    handleSignalServiceDataMessage(message, true, envelope.getSource(), syncMessage.getSent().get().getDestination().get(), ignoreAttachments);
                 }
                 if (syncMessage.getRequest().isPresent()) {
                     RequestMessage rm = syncMessage.getRequest().get();