X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/845e93ec0f8931b7f501318853b5750c37721621..208e12bdc6bfcfd141d46a40b105d2559340ead0:/src/main/java/cli/Manager.java diff --git a/src/main/java/cli/Manager.java b/src/main/java/cli/Manager.java index 2a1ddb22..86850ed4 100644 --- a/src/main/java/cli/Manager.java +++ b/src/main/java/cli/Manager.java @@ -50,7 +50,7 @@ import java.util.*; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -class Manager { +class Manager implements TextSecure { private final static String URL = "https://textsecure-service.whispersystems.org"; private final static TrustStore TRUST_STORE = new WhisperTrustStore(); @@ -136,7 +136,7 @@ class Manager { accountManager = new TextSecureAccountManager(URL, TRUST_STORE, username, password, USER_AGENT); } - public void save() { + private void save() { ObjectNode rootNode = jsonProcessot.createObjectNode(); rootNode.put("username", username) .put("password", password) @@ -160,6 +160,7 @@ class Manager { axolotlStore = new JsonAxolotlStore(identityKey, registrationId); groupStore = new JsonGroupStore(); registered = false; + save(); } public boolean isRegistered() { @@ -177,6 +178,7 @@ class Manager { accountManager.requestSmsVerificationCode(); registered = false; + save(); } private static final int BATCH_SIZE = 100; @@ -194,6 +196,8 @@ class Manager { } preKeyIdOffset = (preKeyIdOffset + BATCH_SIZE + 1) % Medium.MAX_VALUE; + save(); + return records; } @@ -210,6 +214,7 @@ class Manager { PreKeyRecord record = new PreKeyRecord(Medium.MAX_VALUE, keyPair); axolotlStore.storePreKey(Medium.MAX_VALUE, record); + save(); return record; } @@ -222,6 +227,7 @@ class Manager { axolotlStore.storeSignedPreKey(nextSignedPreKeyId, record); nextSignedPreKeyId = (nextSignedPreKeyId + 1) % Medium.MAX_VALUE; + save(); return record; } catch (InvalidKeyException e) { @@ -244,6 +250,7 @@ class Manager { SignedPreKeyRecord signedPreKeyRecord = generateSignedPreKey(axolotlStore.getIdentityKeyPair()); accountManager.setPreKeys(axolotlStore.getIdentityKeyPair().getPublicKey(), lastResortKey, signedPreKeyRecord, oneTimePreKeys); + save(); } @@ -270,6 +277,7 @@ class Manager { return new TextSecureAttachmentStream(attachmentStream, mime, attachmentSize, null); } + @Override public void sendGroupMessage(String messageText, List attachments, byte[] groupId) throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException { @@ -351,9 +359,17 @@ class Manager { return g.groupId; } + @Override + public void sendMessage(String message, List attachments, String recipient) + throws EncapsulatedExceptions, AttachmentInvalidException, IOException { + List recipients = new ArrayList<>(1); + recipients.add(recipient); + sendMessage(message, attachments, recipients); + } + public void sendMessage(String messageText, List attachments, Collection recipients) - throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException { + throws IOException, EncapsulatedExceptions, AttachmentInvalidException { final TextSecureDataMessage.Builder messageBuilder = TextSecureDataMessage.newBuilder().withBody(messageText); if (attachments != null) { messageBuilder.withAttachments(getTextSecureAttachments(attachments)); @@ -383,6 +399,7 @@ class Manager { } catch (InvalidNumberException e) { System.err.println("Failed to add recipient \"" + recipient + "\": " + e.getMessage()); System.err.println("Aborting sending."); + save(); return; } } @@ -394,6 +411,7 @@ class Manager { handleEndSession(recipient.getNumber()); } } + save(); } private TextSecureContent decryptMessage(TextSecureEnvelope envelope) { @@ -498,6 +516,7 @@ class Manager { } } } + save(); handler.handleMessage(envelope, content, group); } catch (TimeoutException e) { if (returnOnTimeout) @@ -505,7 +524,6 @@ class Manager { } catch (InvalidVersionException e) { System.err.println("Ignoring error: " + e.getMessage()); } - save(); } } finally { if (messagePipe != null) @@ -581,4 +599,9 @@ class Manager { private void setGroupInfo(GroupInfo group) { groupStore.updateGroup(group); } + + @Override + public boolean isRemote() { + return false; + } }