Add --ignore-attachments flag to receive and daemon command

Fixes #41
This commit is contained in:
AsamK 2016-12-22 12:27:43 +01:00
parent aa9aadacf1
commit d89e93ad47
3 changed files with 24 additions and 12 deletions

View file

@ -120,6 +120,8 @@ attachments are downloaded to the config directory.
*-t* TIMEOUT, *--timeout* TIMEOUT:: *-t* TIMEOUT, *--timeout* TIMEOUT::
Number of seconds to wait for new messages (negative values disable timeout). Number of seconds to wait for new messages (negative values disable timeout).
Default is 5 seconds. Default is 5 seconds.
*--ignore-attachments*::
Dont download attachments of received messages.
updateGroup updateGroup
~~~~~~~~~~~ ~~~~~~~~~~~
@ -179,6 +181,8 @@ libunixsocket-java ArchLinux: libmatthew-unix-java (AUR)).
*--system*:: *--system*::
Use DBus system bus instead of user bus. Use DBus system bus instead of user bus.
*--ignore-attachments*::
Dont download attachments of received messages.
Examples Examples

View file

@ -375,8 +375,9 @@ public class Main {
returnOnTimeout = false; returnOnTimeout = false;
timeout = 3600; timeout = 3600;
} }
boolean ignoreAttachments = ns.getBoolean("ignore_attachments");
try { 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) { } catch (IOException e) {
System.err.println("Error while receiving messages: " + e.getMessage()); System.err.println("Error while receiving messages: " + e.getMessage());
return 3; return 3;
@ -549,8 +550,9 @@ public class Main {
e.printStackTrace(); e.printStackTrace();
return 2; return 2;
} }
ignoreAttachments = ns.getBoolean("ignore_attachments");
try { 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) { } catch (IOException e) {
System.err.println("Error while receiving messages: " + e.getMessage()); System.err.println("Error while receiving messages: " + e.getMessage());
return 3; return 3;
@ -722,11 +724,17 @@ public class Main {
parserReceive.addArgument("-t", "--timeout") parserReceive.addArgument("-t", "--timeout")
.type(double.class) .type(double.class)
.help("Number of seconds to wait for new messages (negative values disable timeout)"); .help("Number of seconds to wait for new messages (negative values disable timeout)");
parserReceive.addArgument("--ignore-attachments")
.help("Dont download attachments of received messages.")
.action(Arguments.storeTrue());
Subparser parserDaemon = subparsers.addParser("daemon"); Subparser parserDaemon = subparsers.addParser("daemon");
parserDaemon.addArgument("--system") parserDaemon.addArgument("--system")
.action(Arguments.storeTrue()) .action(Arguments.storeTrue())
.help("Use DBus system bus instead of user bus."); .help("Use DBus system bus instead of user bus.");
parserDaemon.addArgument("--ignore-attachments")
.help("Dont download attachments of received messages.")
.action(Arguments.storeTrue());
try { try {
Namespace ns = parser.parseArgs(args); Namespace ns = parser.parseArgs(args);

View file

@ -883,7 +883,7 @@ class Manager implements Signal {
void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent decryptedContent, Throwable e); 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; String threadId;
if (message.getGroupInfo().isPresent()) { if (message.getGroupInfo().isPresent()) {
SignalServiceGroup groupInfo = message.getGroupInfo().get(); SignalServiceGroup groupInfo = message.getGroupInfo().get();
@ -970,7 +970,7 @@ class Manager implements Signal {
threadStore.updateThread(thread); threadStore.updateThread(thread);
} }
} }
if (message.getAttachments().isPresent()) { if (message.getAttachments().isPresent() && !ignoreAttachments) {
for (SignalServiceAttachment attachment : message.getAttachments().get()) { for (SignalServiceAttachment attachment : message.getAttachments().get()) {
if (attachment.isPointer()) { if (attachment.isPointer()) {
try { 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()); final File cachePath = new File(getMessageCachePath());
if (!cachePath.exists()) { if (!cachePath.exists()) {
return; return;
@ -1014,7 +1014,7 @@ class Manager implements Signal {
} catch (Exception e) { } catch (Exception e) {
continue; continue;
} }
handleMessage(envelope, content); handleMessage(envelope, content, ignoreAttachments);
} }
save(); save();
handler.handleMessage(envelope, content, null); 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 { public void receiveMessages(long timeout, TimeUnit unit, boolean returnOnTimeout, boolean ignoreAttachments, ReceiveMessageHandler handler) throws IOException {
retryFailedReceivedMessages(handler); retryFailedReceivedMessages(handler, ignoreAttachments);
final SignalServiceMessageReceiver messageReceiver = new SignalServiceMessageReceiver(URL, TRUST_STORE, username, password, deviceId, signalingKey, USER_AGENT); final SignalServiceMessageReceiver messageReceiver = new SignalServiceMessageReceiver(URL, TRUST_STORE, username, password, deviceId, signalingKey, USER_AGENT);
SignalServiceMessagePipe messagePipe = null; SignalServiceMessagePipe messagePipe = null;
@ -1067,7 +1067,7 @@ class Manager implements Signal {
} catch (Exception e) { } catch (Exception e) {
exception = e; exception = e;
} }
handleMessage(envelope, content); handleMessage(envelope, content, ignoreAttachments);
} }
save(); save();
handler.handleMessage(envelope, content, exception); 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 != null) {
if (content.getDataMessage().isPresent()) { if (content.getDataMessage().isPresent()) {
SignalServiceDataMessage message = content.getDataMessage().get(); SignalServiceDataMessage message = content.getDataMessage().get();
handleSignalServiceDataMessage(message, false, envelope.getSource(), username); handleSignalServiceDataMessage(message, false, envelope.getSource(), username, ignoreAttachments);
} }
if (content.getSyncMessage().isPresent()) { if (content.getSyncMessage().isPresent()) {
SignalServiceSyncMessage syncMessage = content.getSyncMessage().get(); SignalServiceSyncMessage syncMessage = content.getSyncMessage().get();
if (syncMessage.getSent().isPresent()) { if (syncMessage.getSent().isPresent()) {
SignalServiceDataMessage message = syncMessage.getSent().get().getMessage(); 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()) { if (syncMessage.getRequest().isPresent()) {
RequestMessage rm = syncMessage.getRequest().get(); RequestMessage rm = syncMessage.getRequest().get();