Search in sources :

Example 1 with MediaStream

use of org.thoughtcrime.securesms.mms.MediaStream in project Signal-Android by WhisperSystems.

the class SendJob method scaleAttachments.

protected List<Attachment> scaleAttachments(@NonNull MasterSecret masterSecret, @NonNull MediaConstraints constraints, @NonNull List<Attachment> attachments) throws UndeliverableMessageException {
    AttachmentDatabase attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context);
    List<Attachment> results = new LinkedList<>();
    for (Attachment attachment : attachments) {
        try {
            if (constraints.isSatisfied(context, masterSecret, attachment)) {
                results.add(attachment);
            } else if (constraints.canResize(attachment)) {
                MediaStream resized = constraints.getResizedMedia(context, masterSecret, attachment);
                results.add(attachmentDatabase.updateAttachmentData(masterSecret, attachment, resized));
            } else {
                throw new UndeliverableMessageException("Size constraints could not be met!");
            }
        } catch (IOException | MmsException e) {
            throw new UndeliverableMessageException(e);
        }
    }
    return results;
}
Also used : MmsException(ws.com.google.android.mms.MmsException) MediaStream(org.thoughtcrime.securesms.mms.MediaStream) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) Attachment(org.thoughtcrime.securesms.attachments.Attachment) IOException(java.io.IOException) AttachmentDatabase(org.thoughtcrime.securesms.database.AttachmentDatabase) LinkedList(java.util.LinkedList)

Aggregations

IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 Attachment (org.thoughtcrime.securesms.attachments.Attachment)1 AttachmentDatabase (org.thoughtcrime.securesms.database.AttachmentDatabase)1 MediaStream (org.thoughtcrime.securesms.mms.MediaStream)1 UndeliverableMessageException (org.thoughtcrime.securesms.transport.UndeliverableMessageException)1 MmsException (ws.com.google.android.mms.MmsException)1