Search in sources :

Example 1 with AttachmentId

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

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

the class AttachmentDatabase method insertAttachment.

private AttachmentId insertAttachment(MasterSecretUnion masterSecret, long mmsId, Attachment attachment) throws MmsException {
    Log.w(TAG, "Inserting attachment for mms id: " + mmsId);
    SQLiteDatabase database = databaseHelper.getWritableDatabase();
    Pair<File, Long> partData = null;
    long uniqueId = System.currentTimeMillis();
    if (masterSecret.getMasterSecret().isPresent() && attachment.getDataUri() != null) {
        partData = setAttachmentData(masterSecret.getMasterSecret().get(), attachment.getDataUri());
        Log.w(TAG, "Wrote part to file: " + partData.first.getAbsolutePath());
    }
    ContentValues contentValues = new ContentValues();
    contentValues.put(MMS_ID, mmsId);
    contentValues.put(CONTENT_TYPE, attachment.getContentType());
    contentValues.put(TRANSFER_STATE, attachment.getTransferState());
    contentValues.put(UNIQUE_ID, uniqueId);
    contentValues.put(CONTENT_LOCATION, attachment.getLocation());
    contentValues.put(DIGEST, attachment.getDigest());
    contentValues.put(CONTENT_DISPOSITION, attachment.getKey());
    contentValues.put(NAME, attachment.getRelay());
    if (partData != null) {
        contentValues.put(DATA, partData.first.getAbsolutePath());
        contentValues.put(SIZE, partData.second);
    }
    long rowId = database.insert(TABLE_NAME, null, contentValues);
    AttachmentId attachmentId = new AttachmentId(rowId, uniqueId);
    if (partData != null) {
        Log.w(TAG, "Submitting thumbnail generation job...");
        thumbnailExecutor.submit(new ThumbnailFetchCallable(masterSecret.getMasterSecret().get(), attachmentId));
    }
    return attachmentId;
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) File(java.io.File) AttachmentId(org.thoughtcrime.securesms.attachments.AttachmentId)

Example 3 with AttachmentId

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

the class AttachmentDownloadJob method onCanceled.

@Override
public void onCanceled() {
    final AttachmentId attachmentId = new AttachmentId(partRowId, partUniqueId);
    markFailed(messageId, attachmentId);
}
Also used : AttachmentId(org.thoughtcrime.securesms.attachments.AttachmentId)

Example 4 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 5 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