Correctly send to multiple recipients

This commit is contained in:
AsamK 2015-07-07 12:07:01 +02:00
parent 960e97bc12
commit 01702276c5

View file

@ -21,9 +21,10 @@ import net.sourceforge.argparse4j.impl.Arguments;
import net.sourceforge.argparse4j.inf.*; import net.sourceforge.argparse4j.inf.*;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.whispersystems.textsecure.api.TextSecureMessageSender; import org.whispersystems.textsecure.api.TextSecureMessageSender;
import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException;
import org.whispersystems.textsecure.api.messages.*; import org.whispersystems.textsecure.api.messages.*;
import org.whispersystems.textsecure.api.messages.multidevice.TextSecureSyncMessage; import org.whispersystems.textsecure.api.messages.multidevice.TextSecureSyncMessage;
import org.whispersystems.textsecure.api.push.TextSecureAddress;
import org.whispersystems.textsecure.api.push.exceptions.EncapsulatedExceptions;
import org.whispersystems.textsecure.api.util.InvalidNumberException; import org.whispersystems.textsecure.api.util.InvalidNumberException;
import java.io.File; import java.io.File;
@ -150,13 +151,20 @@ public class Main {
messageBuilder.withAttachments(textSecureAttachments); messageBuilder.withAttachments(textSecureAttachments);
} }
TextSecureDataMessage message = messageBuilder.build(); TextSecureDataMessage message = messageBuilder.build();
List<TextSecureAddress> recipients = new ArrayList<>(ns.<String>getList("recipient").size());
for (String recipient : ns.<String>getList("recipient")) { for (String recipient : ns.<String>getList("recipient")) {
try { try {
messageSender.sendMessage(m.getPushAddress(recipient), message); recipients.add(m.getPushAddress(recipient));
} catch (UntrustedIdentityException | IOException | InvalidNumberException e) { } catch (InvalidNumberException e) {
System.out.println("Failed to send message to \"" + recipient + "\": " + e.getMessage()); System.out.println("Failed to send message to \"" + recipient + "\": " + e.getMessage());
} }
} }
try {
messageSender.sendMessage(recipients, message);
} catch (IOException | EncapsulatedExceptions e) {
System.out.println("Failed to send message: " + e.getMessage());
}
break; break;
case "receive": case "receive":
if (!m.isRegistered()) { if (!m.isRegistered()) {