Always save when sending messages

This commit is contained in:
AsamK 2016-04-16 14:15:36 +02:00
parent 5c1127ced6
commit 800b92c4ba

View file

@ -548,36 +548,39 @@ class Manager implements Signal {
private void sendMessage(SignalServiceDataMessage message, Collection<String> recipients) private void sendMessage(SignalServiceDataMessage message, Collection<String> recipients)
throws IOException, EncapsulatedExceptions, UntrustedIdentityException { throws IOException, EncapsulatedExceptions, UntrustedIdentityException {
SignalServiceMessageSender messageSender = new SignalServiceMessageSender(URL, TRUST_STORE, username, password, try {
deviceId, signalProtocolStore, USER_AGENT, Optional.<SignalServiceMessageSender.EventListener>absent()); SignalServiceMessageSender messageSender = new SignalServiceMessageSender(URL, TRUST_STORE, username, password,
deviceId, signalProtocolStore, USER_AGENT, Optional.<SignalServiceMessageSender.EventListener>absent());
Set<SignalServiceAddress> recipientsTS = new HashSet<>(recipients.size()); Set<SignalServiceAddress> recipientsTS = new HashSet<>(recipients.size());
for (String recipient : recipients) { for (String recipient : recipients) {
try { try {
recipientsTS.add(getPushAddress(recipient)); recipientsTS.add(getPushAddress(recipient));
} catch (InvalidNumberException e) { } catch (InvalidNumberException e) {
System.err.println("Failed to add recipient \"" + recipient + "\": " + e.getMessage()); System.err.println("Failed to add recipient \"" + recipient + "\": " + e.getMessage());
System.err.println("Aborting sending."); System.err.println("Aborting sending.");
save(); save();
return; return;
}
} }
}
if (message.getGroupInfo().isPresent()) { if (message.getGroupInfo().isPresent()) {
messageSender.sendMessage(new ArrayList<>(recipientsTS), message); messageSender.sendMessage(new ArrayList<>(recipientsTS), message);
} else { } else {
// Send to all individually, so sync messages are sent correctly // Send to all individually, so sync messages are sent correctly
for (SignalServiceAddress address : recipientsTS) { for (SignalServiceAddress address : recipientsTS) {
messageSender.sendMessage(address, message); messageSender.sendMessage(address, message);
}
} }
}
if (message.isEndSession()) { if (message.isEndSession()) {
for (SignalServiceAddress recipient : recipientsTS) { for (SignalServiceAddress recipient : recipientsTS) {
handleEndSession(recipient.getNumber()); handleEndSession(recipient.getNumber());
}
} }
} finally {
save();
} }
save();
} }
private SignalServiceContent decryptMessage(SignalServiceEnvelope envelope) { private SignalServiceContent decryptMessage(SignalServiceEnvelope envelope) {