Search in sources :

Example 1 with DatabaseAttachment

use of org.thoughtcrime.securesms.attachments.DatabaseAttachment in project Signal-Android by signalapp.

the class AttachmentDatabase method getPendingAttachments.

@NonNull
public List<DatabaseAttachment> getPendingAttachments() {
    final SQLiteDatabase database = databaseHelper.getReadableDatabase();
    final List<DatabaseAttachment> attachments = new LinkedList<>();
    Cursor cursor = null;
    try {
        cursor = database.query(TABLE_NAME, PROJECTION, TRANSFER_STATE + " = ?", new String[] { String.valueOf(TRANSFER_PROGRESS_STARTED) }, null, null, null);
        while (cursor != null && cursor.moveToNext()) {
            attachments.add(getAttachment(cursor));
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return attachments;
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) Cursor(android.database.Cursor) LinkedList(java.util.LinkedList) NonNull(android.support.annotation.NonNull)

Example 2 with DatabaseAttachment

use of org.thoughtcrime.securesms.attachments.DatabaseAttachment in project Signal-Android by signalapp.

the class AttachmentDatabase method updateAttachmentData.

@NonNull
public Attachment updateAttachmentData(@NonNull Attachment attachment, @NonNull MediaStream mediaStream) throws MmsException {
    SQLiteDatabase database = databaseHelper.getWritableDatabase();
    DatabaseAttachment databaseAttachment = (DatabaseAttachment) attachment;
    DataInfo dataInfo = getAttachmentDataFileInfo(databaseAttachment.getAttachmentId(), DATA);
    if (dataInfo == null) {
        throw new MmsException("No attachment data found!");
    }
    dataInfo = setAttachmentData(dataInfo.file, mediaStream.getStream());
    ContentValues contentValues = new ContentValues();
    contentValues.put(SIZE, dataInfo.length);
    contentValues.put(CONTENT_TYPE, mediaStream.getMimeType());
    contentValues.put(DATA_RANDOM, dataInfo.random);
    database.update(TABLE_NAME, contentValues, PART_ID_WHERE, databaseAttachment.getAttachmentId().toStrings());
    return new DatabaseAttachment(databaseAttachment.getAttachmentId(), databaseAttachment.getMmsId(), databaseAttachment.hasData(), databaseAttachment.hasThumbnail(), mediaStream.getMimeType(), databaseAttachment.getTransferState(), dataInfo.length, databaseAttachment.getFileName(), databaseAttachment.getLocation(), databaseAttachment.getKey(), databaseAttachment.getRelay(), databaseAttachment.getDigest(), databaseAttachment.getFastPreflightId(), databaseAttachment.isVoiceNote());
}
Also used : ContentValues(android.content.ContentValues) MmsException(org.thoughtcrime.securesms.mms.MmsException) SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) NonNull(android.support.annotation.NonNull)

Example 3 with DatabaseAttachment

use of org.thoughtcrime.securesms.attachments.DatabaseAttachment in project Signal-Android by signalapp.

the class AttachmentDatabase method markAttachmentUploaded.

public void markAttachmentUploaded(long messageId, Attachment attachment) {
    ContentValues values = new ContentValues(1);
    SQLiteDatabase database = databaseHelper.getWritableDatabase();
    values.put(TRANSFER_STATE, TRANSFER_PROGRESS_DONE);
    database.update(TABLE_NAME, values, PART_ID_WHERE, ((DatabaseAttachment) attachment).getAttachmentId().toStrings());
    notifyConversationListeners(DatabaseFactory.getMmsDatabase(context).getThreadIdForMessage(messageId));
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment)

Example 4 with DatabaseAttachment

use of org.thoughtcrime.securesms.attachments.DatabaseAttachment in project Signal-Android by signalapp.

the class PartProvider method getType.

@Override
public String getType(@NonNull Uri uri) {
    Log.w(TAG, "getType() called: " + uri);
    switch(uriMatcher.match(uri)) {
        case SINGLE_ROW:
            PartUriParser partUriParser = new PartUriParser(uri);
            DatabaseAttachment attachment = DatabaseFactory.getAttachmentDatabase(getContext()).getAttachment(partUriParser.getPartId());
            if (attachment != null) {
                return attachment.getContentType();
            }
    }
    return null;
}
Also used : PartUriParser(org.thoughtcrime.securesms.mms.PartUriParser) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment)

Example 5 with DatabaseAttachment

use of org.thoughtcrime.securesms.attachments.DatabaseAttachment in project Signal-Android by signalapp.

the class PartProvider method query.

@Override
public Cursor query(@NonNull Uri url, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    Log.w(TAG, "query() called: " + url);
    if (projection == null || projection.length <= 0)
        return null;
    switch(uriMatcher.match(url)) {
        case SINGLE_ROW:
            PartUriParser partUri = new PartUriParser(url);
            DatabaseAttachment attachment = DatabaseFactory.getAttachmentDatabase(getContext()).getAttachment(partUri.getPartId());
            if (attachment == null)
                return null;
            MatrixCursor matrixCursor = new MatrixCursor(projection, 1);
            Object[] resultRow = new Object[projection.length];
            for (int i = 0; i < projection.length; i++) {
                if (OpenableColumns.DISPLAY_NAME.equals(projection[i])) {
                    resultRow[i] = attachment.getFileName();
                }
            }
            matrixCursor.addRow(resultRow);
            return matrixCursor;
    }
    return null;
}
Also used : PartUriParser(org.thoughtcrime.securesms.mms.PartUriParser) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) MatrixCursor(android.database.MatrixCursor)

Aggregations

DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)51 LinkedList (java.util.LinkedList)15 AttachmentId (org.thoughtcrime.securesms.attachments.AttachmentId)14 Attachment (org.thoughtcrime.securesms.attachments.Attachment)12 MmsException (org.thoughtcrime.securesms.mms.MmsException)11 NonNull (androidx.annotation.NonNull)10 AttachmentDatabase (org.thoughtcrime.securesms.database.AttachmentDatabase)10 ContentValues (android.content.ContentValues)9 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)9 Nullable (androidx.annotation.Nullable)8 IOException (java.io.IOException)8 List (java.util.List)8 Recipient (org.thoughtcrime.securesms.recipients.Recipient)8 Cursor (android.database.Cursor)7 MessageDatabase (org.thoughtcrime.securesms.database.MessageDatabase)6 OutgoingSecureMediaMessage (org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage)6 Context (android.content.Context)5 HashMap (java.util.HashMap)5 Contact (org.thoughtcrime.securesms.contactshare.Contact)5 InputStream (java.io.InputStream)4