Search in sources :

Example 6 with AttachmentId

use of org.thoughtcrime.securesms.attachments.AttachmentId 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)

Example 7 with AttachmentId

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

the class AttachmentDownloadJob method onRun.

@Override
public void onRun(MasterSecret masterSecret) throws IOException {
    final AttachmentId attachmentId = new AttachmentId(partRowId, partUniqueId);
    final Attachment attachment = DatabaseFactory.getAttachmentDatabase(context).getAttachment(attachmentId);
    if (attachment == null) {
        Log.w(TAG, "attachment no longer exists.");
        return;
    }
    if (!attachment.isInProgress()) {
        Log.w(TAG, "Attachment was already downloaded.");
        return;
    }
    Log.w(TAG, "Downloading push part " + attachmentId);
    retrieveAttachment(masterSecret, messageId, attachmentId, attachment);
    MessageNotifier.updateNotification(context, masterSecret);
}
Also used : Attachment(org.thoughtcrime.securesms.attachments.Attachment) AttachmentId(org.thoughtcrime.securesms.attachments.AttachmentId)

Aggregations

AttachmentId (org.thoughtcrime.securesms.attachments.AttachmentId)7 Attachment (org.thoughtcrime.securesms.attachments.Attachment)3 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)3 InputStream (java.io.InputStream)2 MasterSecret (org.thoughtcrime.securesms.crypto.MasterSecret)2 ContentValues (android.content.ContentValues)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 AttachmentDatabase (org.thoughtcrime.securesms.database.AttachmentDatabase)1 BitmapDecodingException (org.thoughtcrime.securesms.util.BitmapDecodingException)1