Search in sources :

Example 11 with SignalServiceMessageSender

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

the class PushGroupUpdateJob method onRun.

@Override
public void onRun() throws IOException, UntrustedIdentityException {
    SignalServiceMessageSender messageSender = messageSenderFactory.create();
    GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context);
    GroupRecord record = groupDatabase.getGroup(groupId);
    SignalServiceAttachment avatar = null;
    if (record == null) {
        Log.w(TAG, "No information for group record info request: " + new String(groupId));
        return;
    }
    if (record.getAvatar() != null) {
        avatar = SignalServiceAttachmentStream.newStreamBuilder().withContentType("image/jpeg").withStream(new ByteArrayInputStream(record.getAvatar())).withLength(record.getAvatar().length).build();
    }
    SignalServiceGroup groupContext = SignalServiceGroup.newBuilder(Type.UPDATE).withAvatar(avatar).withId(groupId).withMembers(record.getMembers()).withName(record.getTitle()).build();
    SignalServiceDataMessage message = SignalServiceDataMessage.newBuilder().asGroupMessage(groupContext).withTimestamp(System.currentTimeMillis()).build();
    messageSender.sendMessage(new SignalServiceAddress(source), message);
}
Also used : SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) GroupRecord(org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord) SignalServiceGroup(org.whispersystems.signalservice.api.messages.SignalServiceGroup)

Example 12 with SignalServiceMessageSender

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

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

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