Adapt code for new libtextsecure-java version

This commit is contained in:
AsamK 2015-07-06 10:41:19 +02:00
parent 067d14e1ca
commit 73e8c4cabf
3 changed files with 26 additions and 14 deletions

View file

@ -22,7 +22,9 @@ import org.apache.commons.io.IOUtils;
import org.whispersystems.libaxolotl.InvalidVersionException; import org.whispersystems.libaxolotl.InvalidVersionException;
import org.whispersystems.textsecure.api.TextSecureMessageSender; import org.whispersystems.textsecure.api.TextSecureMessageSender;
import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException; import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException;
import org.whispersystems.textsecure.api.messages.TextSecureMessage; import org.whispersystems.textsecure.api.messages.TextSecureContent;
import org.whispersystems.textsecure.api.messages.TextSecureDataMessage;
import org.whispersystems.textsecure.api.messages.multidevice.TextSecureSyncMessage;
import org.whispersystems.textsecure.api.push.TextSecureAddress; import org.whispersystems.textsecure.api.push.TextSecureAddress;
import java.io.IOException; import java.io.IOException;
@ -117,7 +119,7 @@ public class Main {
System.exit(1); System.exit(1);
} }
} }
TextSecureMessage message = TextSecureMessage.newBuilder().withBody(messageText).build(); TextSecureDataMessage message = TextSecureDataMessage.newBuilder().withBody(messageText).build();
for (String recipient : ns.<String>getList("recipient")) { for (String recipient : ns.<String>getList("recipient")) {
try { try {
messageSender.sendMessage(new TextSecureAddress(recipient), message); messageSender.sendMessage(new TextSecureAddress(recipient), message);
@ -132,11 +134,23 @@ public class Main {
System.exit(1); System.exit(1);
} }
try { try {
message = m.receiveMessage(); TextSecureContent content = m.receiveMessage();
if (message == null) { if (content.getDataMessage().isPresent()) {
System.exit(0); message = content.getDataMessage().get();
} else { if (message == null) {
System.out.println("Received message: " + message.getBody().get()); System.exit(0);
} else {
System.out.println("Received message: " + message.getBody().get());
}
}
if (content.getSyncMessage().isPresent()) {
TextSecureSyncMessage syncMessage = content.getSyncMessage().get();
if (syncMessage == null) {
System.exit(0);
} else {
System.out.println("Received sync message");
}
} }
} catch (IOException | InvalidVersionException e) { } catch (IOException | InvalidVersionException e) {
System.out.println("Receive message: " + e.getMessage()); System.out.println("Receive message: " + e.getMessage());

View file

@ -30,12 +30,12 @@ import org.whispersystems.textsecure.api.TextSecureMessagePipe;
import org.whispersystems.textsecure.api.TextSecureMessageReceiver; import org.whispersystems.textsecure.api.TextSecureMessageReceiver;
import org.whispersystems.textsecure.api.TextSecureMessageSender; import org.whispersystems.textsecure.api.TextSecureMessageSender;
import org.whispersystems.textsecure.api.crypto.TextSecureCipher; import org.whispersystems.textsecure.api.crypto.TextSecureCipher;
import org.whispersystems.textsecure.api.messages.TextSecureContent;
import org.whispersystems.textsecure.api.messages.TextSecureEnvelope; import org.whispersystems.textsecure.api.messages.TextSecureEnvelope;
import org.whispersystems.textsecure.api.messages.TextSecureMessage; import org.whispersystems.textsecure.api.push.TextSecureAddress;
import org.whispersystems.textsecure.api.push.TrustStore; import org.whispersystems.textsecure.api.push.TrustStore;
import java.io.*; import java.io.*;
import java.nio.file.Path;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
@ -151,7 +151,7 @@ public class Manager {
axolotlStore, Optional.<TextSecureMessageSender.EventListener>absent()); axolotlStore, Optional.<TextSecureMessageSender.EventListener>absent());
} }
public TextSecureMessage receiveMessage() throws IOException, InvalidVersionException { public TextSecureContent receiveMessage() throws IOException, InvalidVersionException {
TextSecureMessageReceiver messageReceiver = new TextSecureMessageReceiver(URL, TRUST_STORE, username, password, signalingKey); TextSecureMessageReceiver messageReceiver = new TextSecureMessageReceiver(URL, TRUST_STORE, username, password, signalingKey);
TextSecureMessagePipe messagePipe = null; TextSecureMessagePipe messagePipe = null;
@ -164,8 +164,8 @@ public class Manager {
} catch (TimeoutException e) { } catch (TimeoutException e) {
return null; return null;
} }
TextSecureCipher cipher = new TextSecureCipher(axolotlStore); TextSecureCipher cipher = new TextSecureCipher(new TextSecureAddress(username), axolotlStore);
TextSecureMessage message = null; TextSecureContent message = null;
try { try {
message = cipher.decrypt(envelope); message = cipher.decrypt(envelope);
} catch (Exception e) { } catch (Exception e) {

View file

@ -2,8 +2,6 @@ package cli;
import org.whispersystems.textsecure.api.push.TrustStore; import org.whispersystems.textsecure.api.push.TrustStore;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream; import java.io.InputStream;
public class WhisperTrustStore implements TrustStore { public class WhisperTrustStore implements TrustStore {