X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/f3878c54a627d278e503de1f4497a86f76519bc8..35181251bfe672a21f84a105b5f9dc8080b83cd9:/src/main/java/org/asamk/signal/manager/Manager.java diff --git a/src/main/java/org/asamk/signal/manager/Manager.java b/src/main/java/org/asamk/signal/manager/Manager.java index 44ec6445..a719dcf7 100644 --- a/src/main/java/org/asamk/signal/manager/Manager.java +++ b/src/main/java/org/asamk/signal/manager/Manager.java @@ -56,6 +56,7 @@ import org.whispersystems.signalservice.api.util.InvalidNumberException; import org.whispersystems.signalservice.api.util.SleepTimer; import org.whispersystems.signalservice.api.util.UptimeSleepTimer; import org.whispersystems.signalservice.internal.push.SignalServiceProtos; +import org.whispersystems.signalservice.internal.push.UnsupportedDataMessageException; import org.whispersystems.signalservice.internal.util.Base64; import java.io.*; @@ -189,9 +190,9 @@ public class Manager implements Signal { accountManager = new SignalServiceAccountManager(BaseConfig.serviceConfiguration, account.getUsername(), account.getPassword(), BaseConfig.USER_AGENT, timer); if (voiceVerification) { - accountManager.requestVoiceVerificationCode(Locale.getDefault()); + accountManager.requestVoiceVerificationCode(Locale.getDefault(), Optional.absent()); } else { - accountManager.requestSmsVerificationCode(false); + accountManager.requestSmsVerificationCode(false, Optional.absent()); } account.setRegistered(false); @@ -762,7 +763,8 @@ public class Manager implements Signal { message = messageBuilder.build(); if (message.getGroupInfo().isPresent()) { try { - List result = messageSender.sendMessage(new ArrayList<>(recipientsTS), getAccessFor(recipientsTS), message); + final boolean isRecipientUpdate = true; + List result = messageSender.sendMessage(new ArrayList<>(recipientsTS), getAccessFor(recipientsTS), isRecipientUpdate, message); for (SendMessageResult r : result) { if (r.getIdentityFailure() != null) { account.getSignalProtocolStore().saveIdentity(r.getAddress().getNumber(), r.getIdentityFailure().getIdentityKey(), TrustLevel.UNTRUSTED); @@ -773,6 +775,25 @@ public class Manager implements Signal { account.getSignalProtocolStore().saveIdentity(e.getE164Number(), e.getIdentityKey(), TrustLevel.UNTRUSTED); return Collections.emptyList(); } + } else if (recipientsTS.size() == 1 && recipientsTS.contains(new SignalServiceAddress(username))) { + SignalServiceAddress recipient = new SignalServiceAddress(username); + final Optional unidentifiedAccess = getAccessFor(recipient); + SentTranscriptMessage transcript = new SentTranscriptMessage(recipient.getNumber(), + message.getTimestamp(), + message, + message.getExpiresInSeconds(), + Collections.singletonMap(recipient.getNumber(), unidentifiedAccess.isPresent()), + false); + SignalServiceSyncMessage syncMessage = SignalServiceSyncMessage.forSentTranscript(transcript); + + List results = new ArrayList<>(recipientsTS.size()); + try { + messageSender.sendMessage(syncMessage, unidentifiedAccess); + } catch (UntrustedIdentityException e) { + account.getSignalProtocolStore().saveIdentity(e.getE164Number(), e.getIdentityKey(), TrustLevel.UNTRUSTED); + results.add(SendMessageResult.identityFailure(recipient, e.getIdentityKey())); + } + return results; } else { // Send to all individually, so sync messages are sent correctly List results = new ArrayList<>(recipientsTS.size()); @@ -804,7 +825,7 @@ public class Manager implements Signal { } } - private SignalServiceContent decryptMessage(SignalServiceEnvelope envelope) throws InvalidMetadataMessageException, ProtocolInvalidMessageException, ProtocolDuplicateMessageException, ProtocolLegacyMessageException, ProtocolInvalidKeyIdException, InvalidMetadataVersionException, ProtocolInvalidVersionException, ProtocolNoSessionException, ProtocolInvalidKeyException, ProtocolUntrustedIdentityException, SelfSendException { + private SignalServiceContent decryptMessage(SignalServiceEnvelope envelope) throws InvalidMetadataMessageException, ProtocolInvalidMessageException, ProtocolDuplicateMessageException, ProtocolLegacyMessageException, ProtocolInvalidKeyIdException, InvalidMetadataVersionException, ProtocolInvalidVersionException, ProtocolNoSessionException, ProtocolInvalidKeyException, ProtocolUntrustedIdentityException, SelfSendException, UnsupportedDataMessageException { SignalServiceCipher cipher = new SignalServiceCipher(new SignalServiceAddress(username), account.getSignalProtocolStore(), Utils.getCertificateValidator()); try { return cipher.decrypt(envelope); @@ -1149,6 +1170,10 @@ public class Manager implements Signal { } if (c.getExpirationTimer().isPresent()) { ThreadInfo thread = account.getThreadStore().getThread(c.getNumber()); + if (thread == null) { + thread = new ThreadInfo(); + thread.id = c.getNumber(); + } thread.messageExpirationTime = c.getExpirationTimer().get(); account.getThreadStore().updateThread(thread); }