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

@ -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("Dont 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("Dont download attachments of received messages.")
.action(Arguments.storeTrue());
try {
Namespace ns = parser.parseArgs(args);

View 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();