Search in sources :

Example 6 with SignalServiceMessageSender

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

the class PushGroupSendJob method deliver.

private void deliver(MasterSecret masterSecret, OutgoingMediaMessage message, long filterRecipientId) throws IOException, RecipientFormattingException, InvalidNumberException, EncapsulatedExceptions, UndeliverableMessageException {
    SignalServiceMessageSender messageSender = messageSenderFactory.create();
    byte[] groupId = GroupUtil.getDecodedId(message.getRecipients().getPrimaryRecipient().getNumber());
    Recipients recipients = DatabaseFactory.getGroupDatabase(context).getGroupMembers(groupId, false);
    List<Attachment> scaledAttachments = scaleAttachments(masterSecret, MediaConstraints.PUSH_CONSTRAINTS, message.getAttachments());
    List<SignalServiceAttachment> attachmentStreams = getAttachmentsFor(masterSecret, scaledAttachments);
    List<SignalServiceAddress> addresses;
    if (filterRecipientId >= 0)
        addresses = getPushAddresses(filterRecipientId);
    else
        addresses = getPushAddresses(recipients);
    if (message.isGroup()) {
        OutgoingGroupMediaMessage groupMessage = (OutgoingGroupMediaMessage) message;
        GroupContext groupContext = groupMessage.getGroupContext();
        SignalServiceAttachment avatar = attachmentStreams.isEmpty() ? null : attachmentStreams.get(0);
        SignalServiceGroup.Type type = groupMessage.isGroupQuit() ? SignalServiceGroup.Type.QUIT : SignalServiceGroup.Type.UPDATE;
        SignalServiceGroup group = new SignalServiceGroup(type, groupId, groupContext.getName(), groupContext.getMembersList(), avatar);
        SignalServiceDataMessage groupDataMessage = new SignalServiceDataMessage(message.getSentTimeMillis(), group, null, null);
        messageSender.sendMessage(addresses, groupDataMessage);
    } else {
        SignalServiceGroup group = new SignalServiceGroup(groupId);
        SignalServiceDataMessage groupMessage = new SignalServiceDataMessage(message.getSentTimeMillis(), group, attachmentStreams, message.getBody(), false, (int) (message.getExpiresIn() / 1000), message.isExpirationUpdate());
        messageSender.sendMessage(addresses, groupMessage);
    }
}
Also used : Recipients(org.thoughtcrime.securesms.recipients.Recipients) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) OutgoingGroupMediaMessage(org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SignalServiceGroup(org.whispersystems.signalservice.api.messages.SignalServiceGroup) GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext)

Example 7 with SignalServiceMessageSender

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

the class RequestGroupInfoJob method onRun.

@Override
public void onRun() throws IOException, UntrustedIdentityException {
    SignalServiceMessageSender messageSender = messageSenderFactory.create();
    SignalServiceGroup group = SignalServiceGroup.newBuilder(Type.REQUEST_INFO).withId(groupId).build();
    SignalServiceDataMessage message = SignalServiceDataMessage.newBuilder().asGroupMessage(group).withTimestamp(System.currentTimeMillis()).build();
    messageSender.sendMessage(new SignalServiceAddress(source), message);
}
Also used : SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SignalServiceGroup(org.whispersystems.signalservice.api.messages.SignalServiceGroup)

Example 8 with SignalServiceMessageSender

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

the class DeliveryReceiptJob method onRun.

@Override
public void onRun() throws IOException {
    Log.w("DeliveryReceiptJob", "Sending delivery receipt...");
    SignalServiceMessageSender messageSender = messageSenderFactory.create();
    SignalServiceAddress textSecureAddress = new SignalServiceAddress(destination, Optional.fromNullable(relay));
    messageSender.sendDeliveryReceipt(textSecureAddress, timestamp);
}
Also used : SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress)

Example 9 with SignalServiceMessageSender

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

the class DeliveryReceiptJobTest method testNetworkError.

@Test
public void testNetworkError() throws IOException {
    SignalServiceMessageSender textSecureMessageSender = mock(SignalServiceMessageSender.class);
    long timestamp = System.currentTimeMillis();
    Mockito.doThrow(new PushNetworkException("network error")).when(textSecureMessageSender).sendDeliveryReceipt(any(SignalServiceAddress.class), eq(timestamp));
    DeliveryReceiptJob deliveryReceiptJob = new DeliveryReceiptJob(context, "+14152222222", timestamp, "foo");
    ObjectGraph objectGraph = ObjectGraph.create(new TestModule(textSecureMessageSender));
    objectGraph.inject(deliveryReceiptJob);
    try {
        deliveryReceiptJob.onRun();
        throw new AssertionError();
    } catch (IOException e) {
        assertTrue(deliveryReceiptJob.onShouldRetry(e));
    }
    Mockito.doThrow(new NotFoundException("not found")).when(textSecureMessageSender).sendDeliveryReceipt(any(SignalServiceAddress.class), eq(timestamp));
    try {
        deliveryReceiptJob.onRun();
        throw new AssertionError();
    } catch (IOException e) {
        assertFalse(deliveryReceiptJob.onShouldRetry(e));
    }
}
Also used : PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) ObjectGraph(dagger.ObjectGraph) NotFoundException(org.whispersystems.signalservice.api.push.exceptions.NotFoundException) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) IOException(java.io.IOException) Test(org.junit.Test) BaseUnitTest(org.thoughtcrime.securesms.BaseUnitTest)

Example 10 with SignalServiceMessageSender

use of org.whispersystems.signalservice.api.SignalServiceMessageSender 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

SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)13 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)8 SignalServiceDataMessage (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage)5 InvalidNumberException (org.whispersystems.signalservice.api.util.InvalidNumberException)5 File (java.io.File)3 FileOutputStream (java.io.FileOutputStream)3 IOException (java.io.IOException)3 SignalServiceAttachment (org.whispersystems.signalservice.api.messages.SignalServiceAttachment)3 SignalServiceGroup (org.whispersystems.signalservice.api.messages.SignalServiceGroup)3 ObjectGraph (dagger.ObjectGraph)2 LinkedList (java.util.LinkedList)2 Test (org.junit.Test)2 BaseUnitTest (org.thoughtcrime.securesms.BaseUnitTest)2 Attachment (org.thoughtcrime.securesms.attachments.Attachment)2 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)2 Recipients (org.thoughtcrime.securesms.recipients.Recipients)2 InsecureFallbackApprovalException (org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)2 RetryLaterException (org.thoughtcrime.securesms.transport.RetryLaterException)2 DeviceContact (org.whispersystems.signalservice.api.messages.multidevice.DeviceContact)2 DeviceContactsOutputStream (org.whispersystems.signalservice.api.messages.multidevice.DeviceContactsOutputStream)2