Search in sources :

Example 1 with Attachment

use of org.thoughtcrime.securesms.attachments.Attachment in project Signal-Android by WhisperSystems.

the class AttachmentDatabase method insertAttachmentsForMessage.

void insertAttachmentsForMessage(@NonNull MasterSecretUnion masterSecret, long mmsId, @NonNull List<Attachment> attachments) throws MmsException {
    Log.w(TAG, "insertParts(" + attachments.size() + ")");
    for (Attachment attachment : attachments) {
        AttachmentId attachmentId = insertAttachment(masterSecret, mmsId, attachment);
        Log.w(TAG, "Inserted attachment at ID: " + attachmentId);
    }
}
Also used : DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) AttachmentId(org.thoughtcrime.securesms.attachments.AttachmentId)

Example 2 with Attachment

use of org.thoughtcrime.securesms.attachments.Attachment 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 3 with Attachment

use of org.thoughtcrime.securesms.attachments.Attachment in project Signal-Android by WhisperSystems.

the class PushSendJob method getAttachmentsFor.

protected List<SignalServiceAttachment> getAttachmentsFor(MasterSecret masterSecret, List<Attachment> parts) {
    List<SignalServiceAttachment> attachments = new LinkedList<>();
    for (final Attachment attachment : parts) {
        if (ContentType.isImageType(attachment.getContentType()) || ContentType.isAudioType(attachment.getContentType()) || ContentType.isVideoType(attachment.getContentType())) {
            try {
                if (attachment.getDataUri() == null || attachment.getSize() == 0)
                    throw new IOException("Assertion failed, outgoing attachment has no data!");
                InputStream is = PartAuthority.getAttachmentStream(context, masterSecret, attachment.getDataUri());
                attachments.add(SignalServiceAttachment.newStreamBuilder().withStream(is).withContentType(attachment.getContentType()).withLength(attachment.getSize()).withListener(new ProgressListener() {

                    @Override
                    public void onAttachmentProgress(long total, long progress) {
                        EventBus.getDefault().postSticky(new PartProgressEvent(attachment, total, progress));
                    }
                }).build());
            } catch (IOException ioe) {
                Log.w(TAG, "Couldn't open attachment", ioe);
            }
        }
    }
    return attachments;
}
Also used : SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) ProgressListener(org.whispersystems.signalservice.api.messages.SignalServiceAttachment.ProgressListener) InputStream(java.io.InputStream) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) PartProgressEvent(org.thoughtcrime.securesms.events.PartProgressEvent) IOException(java.io.IOException) LinkedList(java.util.LinkedList)

Example 4 with Attachment

use of org.thoughtcrime.securesms.attachments.Attachment 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 5 with Attachment

use of org.thoughtcrime.securesms.attachments.Attachment in project Signal-Android by WhisperSystems.

the class MediaNetworkRequirement method isPresent.

@Override
public boolean isPresent() {
    final AttachmentId attachmentId = new AttachmentId(partRowId, partUniqueId);
    final AttachmentDatabase db = DatabaseFactory.getAttachmentDatabase(context);
    final Attachment attachment = db.getAttachment(attachmentId);
    if (attachment == null) {
        Log.w(TAG, "attachment was null, returning vacuous true");
        return true;
    }
    Log.w(TAG, "part transfer progress is " + attachment.getTransferState());
    switch(attachment.getTransferState()) {
        case AttachmentDatabase.TRANSFER_PROGRESS_STARTED:
            return true;
        case AttachmentDatabase.TRANSFER_PROGRESS_AUTO_PENDING:
            final Set<String> allowedTypes = getAllowedAutoDownloadTypes();
            final boolean isAllowed = allowedTypes.contains(MediaUtil.getDiscreteMimeType(attachment.getContentType()));
            // *modifying the database* just by calling isPresent().
            if (isAllowed)
                db.setTransferState(messageId, attachmentId, AttachmentDatabase.TRANSFER_PROGRESS_STARTED);
            return isAllowed;
        default:
            return false;
    }
}
Also used : Attachment(org.thoughtcrime.securesms.attachments.Attachment) AttachmentId(org.thoughtcrime.securesms.attachments.AttachmentId) AttachmentDatabase(org.thoughtcrime.securesms.database.AttachmentDatabase)

Aggregations

Attachment (org.thoughtcrime.securesms.attachments.Attachment)14 IOException (java.io.IOException)5 LinkedList (java.util.LinkedList)5 AttachmentId (org.thoughtcrime.securesms.attachments.AttachmentId)3 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)3 OutgoingGroupMediaMessage (org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage)3 Recipients (org.thoughtcrime.securesms.recipients.Recipients)3 SignalServiceAttachment (org.whispersystems.signalservice.api.messages.SignalServiceAttachment)3 MmsException (ws.com.google.android.mms.MmsException)3 Uri (android.net.Uri)2 Test (org.junit.Test)2 BaseUnitTest (org.thoughtcrime.securesms.BaseUnitTest)2 MmsNotificationAttachment (org.thoughtcrime.securesms.attachments.MmsNotificationAttachment)2 UriAttachment (org.thoughtcrime.securesms.attachments.UriAttachment)2 MasterSecretUnion (org.thoughtcrime.securesms.crypto.MasterSecretUnion)2 AttachmentDatabase (org.thoughtcrime.securesms.database.AttachmentDatabase)2 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)2 UndeliverableMessageException (org.thoughtcrime.securesms.transport.UndeliverableMessageException)2 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)2 SignalServiceDataMessage (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage)2