Search in sources :

Example 51 with DatabaseAttachment

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

the class AttachmentDatabase method getAttachmentsForMessages.

@NonNull
public Map<Long, List<DatabaseAttachment>> getAttachmentsForMessages(@NonNull Collection<Long> mmsIds) {
    if (mmsIds.isEmpty()) {
        return Collections.emptyMap();
    }
    SQLiteDatabase database = databaseHelper.getSignalReadableDatabase();
    SqlUtil.Query query = SqlUtil.buildCollectionQuery(MMS_ID, mmsIds);
    Map<Long, List<DatabaseAttachment>> output = new HashMap<>();
    try (Cursor cursor = database.query(TABLE_NAME, PROJECTION, query.getWhere(), query.getWhereArgs(), null, null, UNIQUE_ID + " ASC, " + ROW_ID + " ASC")) {
        while (cursor.moveToNext()) {
            DatabaseAttachment attachment = getAttachment(cursor);
            List<DatabaseAttachment> attachments = output.get(attachment.getMmsId());
            if (attachments == null) {
                attachments = new LinkedList<>();
                output.put(attachment.getMmsId(), attachments);
            }
            attachments.add(attachment);
        }
    }
    return output;
}
Also used : SqlUtil(org.thoughtcrime.securesms.util.SqlUtil) HashMap(java.util.HashMap) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) List(java.util.List) LinkedList(java.util.LinkedList) Cursor(android.database.Cursor) NonNull(androidx.annotation.NonNull)

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