Search in sources :

Example 6 with SignalServiceAttachment

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

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

the class GroupMessageProcessor method handleGroupCreate.

@Nullable
private static Long handleGroupCreate(@NonNull Context context, @NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceGroup group, boolean outgoing) {
    GroupDatabase database = DatabaseFactory.getGroupDatabase(context);
    byte[] id = group.getGroupId();
    GroupContext.Builder builder = createGroupContext(group);
    builder.setType(GroupContext.Type.UPDATE);
    SignalServiceAttachment avatar = group.getAvatar().orNull();
    database.create(id, group.getName().orNull(), group.getMembers().orNull(), avatar != null && avatar.isPointer() ? avatar.asPointer() : null, envelope.getRelay());
    return storeMessage(context, masterSecret, envelope, group, builder.build(), outgoing);
}
Also used : SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext) Nullable(android.support.annotation.Nullable)

Example 8 with SignalServiceAttachment

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

the class PushDecryptJob method handleExpirationUpdate.

private void handleExpirationUpdate(@NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceDataMessage message, @NonNull Optional<Long> smsMessageId) throws MmsException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    String localNumber = TextSecurePreferences.getLocalNumber(context);
    Recipients recipients = getMessageDestination(envelope, message);
    IncomingMediaMessage mediaMessage = new IncomingMediaMessage(masterSecret, envelope.getSource(), localNumber, message.getTimestamp(), -1, message.getExpiresInSeconds() * 1000, true, Optional.fromNullable(envelope.getRelay()), Optional.<String>absent(), message.getGroupInfo(), Optional.<List<SignalServiceAttachment>>absent());
    database.insertSecureDecryptedMessageInbox(masterSecret, mediaMessage, -1);
    DatabaseFactory.getRecipientPreferenceDatabase(context).setExpireMessages(recipients, message.getExpiresInSeconds());
    if (smsMessageId.isPresent()) {
        DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get());
    }
}
Also used : SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) Recipients(org.thoughtcrime.securesms.recipients.Recipients) IncomingMediaMessage(org.thoughtcrime.securesms.mms.IncomingMediaMessage) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Aggregations

SignalServiceAttachment (org.whispersystems.signalservice.api.messages.SignalServiceAttachment)8 Attachment (org.thoughtcrime.securesms.attachments.Attachment)3 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)3 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)3 SignalServiceDataMessage (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage)3 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)3 GroupContext (org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext)3 Nullable (android.support.annotation.Nullable)2 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 Recipients (org.thoughtcrime.securesms.recipients.Recipients)2 SignalServiceGroup (org.whispersystems.signalservice.api.messages.SignalServiceGroup)2 ByteString (com.google.protobuf.ByteString)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)1 GroupRecord (org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord)1 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)1 PartProgressEvent (org.thoughtcrime.securesms.events.PartProgressEvent)1