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);
}
}
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);
}
}
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;
}
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"));
}
Aggregations