Search in sources :

Example 6 with SignalServiceAddress

use of org.whispersystems.signalservice.api.push.SignalServiceAddress in project Signal-Android by WhisperSystems.

the class PushMediaSendJob method deliver.

private void deliver(MasterSecret masterSecret, OutgoingMediaMessage message) throws RetryLaterException, InsecureFallbackApprovalException, UntrustedIdentityException, UndeliverableMessageException {
    if (message.getRecipients() == null || message.getRecipients().getPrimaryRecipient() == null || message.getRecipients().getPrimaryRecipient().getNumber() == null) {
        throw new UndeliverableMessageException("No destination address.");
    }
    SignalServiceMessageSender messageSender = messageSenderFactory.create();
    try {
        SignalServiceAddress address = getPushAddress(message.getRecipients().getPrimaryRecipient().getNumber());
        List<Attachment> scaledAttachments = scaleAttachments(masterSecret, MediaConstraints.PUSH_CONSTRAINTS, message.getAttachments());
        List<SignalServiceAttachment> attachmentStreams = getAttachmentsFor(masterSecret, scaledAttachments);
        SignalServiceDataMessage mediaMessage = SignalServiceDataMessage.newBuilder().withBody(message.getBody()).withAttachments(attachmentStreams).withTimestamp(message.getSentTimeMillis()).withExpiration((int) (message.getExpiresIn() / 1000)).asExpirationUpdate(message.isExpirationUpdate()).build();
        messageSender.sendMessage(address, mediaMessage);
    } catch (InvalidNumberException | UnregisteredUserException e) {
        Log.w(TAG, e);
        throw new InsecureFallbackApprovalException(e);
    } catch (FileNotFoundException e) {
        Log.w(TAG, e);
        throw new UndeliverableMessageException(e);
    } catch (IOException e) {
        Log.w(TAG, e);
        throw new RetryLaterException(e);
    }
}
Also used : UnregisteredUserException(org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) FileNotFoundException(java.io.FileNotFoundException) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) IOException(java.io.IOException) InsecureFallbackApprovalException(org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) RetryLaterException(org.thoughtcrime.securesms.transport.RetryLaterException)

Example 7 with SignalServiceAddress

use of org.whispersystems.signalservice.api.push.SignalServiceAddress in project Signal-Android by WhisperSystems.

the class PushTextSendJob method deliver.

private void deliver(SmsMessageRecord message) throws UntrustedIdentityException, InsecureFallbackApprovalException, RetryLaterException {
    try {
        SignalServiceAddress address = getPushAddress(message.getIndividualRecipient().getNumber());
        SignalServiceMessageSender messageSender = messageSenderFactory.create();
        SignalServiceDataMessage textSecureMessage = SignalServiceDataMessage.newBuilder().withTimestamp(message.getDateSent()).withBody(message.getBody().getBody()).withExpiration((int) (message.getExpiresIn() / 1000)).asEndSessionMessage(message.isEndSession()).build();
        messageSender.sendMessage(address, textSecureMessage);
    } catch (InvalidNumberException | UnregisteredUserException e) {
        Log.w(TAG, e);
        throw new InsecureFallbackApprovalException(e);
    } catch (IOException e) {
        Log.w(TAG, e);
        throw new RetryLaterException(e);
    }
}
Also used : SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) UnregisteredUserException(org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) RetryLaterException(org.thoughtcrime.securesms.transport.RetryLaterException) IOException(java.io.IOException) InsecureFallbackApprovalException(org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)

Example 8 with SignalServiceAddress

use of org.whispersystems.signalservice.api.push.SignalServiceAddress in project Signal-Android by WhisperSystems.

the class WebRtcCallService method sendMessage.

private ListenableFutureTask<Boolean> sendMessage(@NonNull final Recipient recipient, @NonNull final SignalServiceCallMessage callMessage) {
    Callable<Boolean> callable = new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            try {
                String number = Util.canonicalizeNumber(WebRtcCallService.this, recipient.getNumber());
                messageSender.sendCallMessage(new SignalServiceAddress(number), callMessage);
                return true;
            } catch (InvalidNumberException e) {
                throw new IOException(e);
            }
        }
    };
    ListenableFutureTask<Boolean> listenableFutureTask = new ListenableFutureTask<>(callable, null, serviceExecutor);
    networkExecutor.execute(listenableFutureTask);
    return listenableFutureTask;
}
Also used : ListenableFutureTask(org.thoughtcrime.securesms.util.ListenableFutureTask) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) IOException(java.io.IOException) Callable(java.util.concurrent.Callable)

Example 9 with SignalServiceAddress

use of org.whispersystems.signalservice.api.push.SignalServiceAddress in project Signal-Android by WhisperSystems.

the class DeliveryReceiptJobTest method testDelivery.

@Test
public void testDelivery() throws IOException {
    SignalServiceMessageSender textSecureMessageSender = mock(SignalServiceMessageSender.class);
    long timestamp = System.currentTimeMillis();
    DeliveryReceiptJob deliveryReceiptJob = new DeliveryReceiptJob(context, "+14152222222", timestamp, "foo");
    ObjectGraph objectGraph = ObjectGraph.create(new TestModule(textSecureMessageSender));
    objectGraph.inject(deliveryReceiptJob);
    deliveryReceiptJob.onRun();
    ArgumentCaptor<SignalServiceAddress> captor = ArgumentCaptor.forClass(SignalServiceAddress.class);
    verify(textSecureMessageSender).sendDeliveryReceipt(captor.capture(), eq(timestamp));
    assertTrue(captor.getValue().getRelay().get().equals("foo"));
    assertTrue(captor.getValue().getNumber().equals("+14152222222"));
}
Also used : SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) ObjectGraph(dagger.ObjectGraph) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) Test(org.junit.Test) BaseUnitTest(org.thoughtcrime.securesms.BaseUnitTest)

Aggregations

SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)9 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)7 SignalServiceDataMessage (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage)6 IOException (java.io.IOException)3 SignalServiceAttachment (org.whispersystems.signalservice.api.messages.SignalServiceAttachment)3 SignalServiceGroup (org.whispersystems.signalservice.api.messages.SignalServiceGroup)3 InvalidNumberException (org.whispersystems.signalservice.api.util.InvalidNumberException)3 Attachment (org.thoughtcrime.securesms.attachments.Attachment)2 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)2 InsecureFallbackApprovalException (org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)2 RetryLaterException (org.thoughtcrime.securesms.transport.RetryLaterException)2 UnregisteredUserException (org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException)2 ObjectGraph (dagger.ObjectGraph)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 Callable (java.util.concurrent.Callable)1 Test (org.junit.Test)1 BaseUnitTest (org.thoughtcrime.securesms.BaseUnitTest)1 SignalProtocolStoreImpl (org.thoughtcrime.securesms.crypto.storage.SignalProtocolStoreImpl)1 GroupRecord (org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord)1