use of org.thoughtcrime.securesms.attachments.DatabaseAttachment in project Signal-Android by WhisperSystems.
the class AttachmentDatabase method getAttachmentsForMessage.
@NonNull
public List<DatabaseAttachment> getAttachmentsForMessage(long mmsId) {
SQLiteDatabase database = databaseHelper.getSignalReadableDatabase();
List<DatabaseAttachment> results = new LinkedList<>();
Cursor cursor = null;
try {
cursor = database.query(TABLE_NAME, PROJECTION, MMS_ID + " = ?", new String[] { mmsId + "" }, null, null, UNIQUE_ID + " ASC, " + ROW_ID + " ASC");
while (cursor != null && cursor.moveToNext()) {
results.addAll(getAttachments(cursor));
}
return results;
} finally {
if (cursor != null)
cursor.close();
}
}
use of org.thoughtcrime.securesms.attachments.DatabaseAttachment in project Signal-Android by WhisperSystems.
the class AttachmentDatabase method getAttachments.
public List<DatabaseAttachment> getAttachments(@NonNull Cursor cursor) {
try {
if (cursor.getColumnIndex(AttachmentDatabase.ATTACHMENT_JSON_ALIAS) != -1) {
if (cursor.isNull(cursor.getColumnIndexOrThrow(ATTACHMENT_JSON_ALIAS))) {
return new LinkedList<>();
}
List<DatabaseAttachment> result = new LinkedList<>();
JSONArray array = new JSONArray(cursor.getString(cursor.getColumnIndexOrThrow(ATTACHMENT_JSON_ALIAS)));
for (int i = 0; i < array.length(); i++) {
JsonUtils.SaneJSONObject object = new JsonUtils.SaneJSONObject(array.getJSONObject(i));
if (!object.isNull(ROW_ID)) {
String contentType = object.getString(CONTENT_TYPE);
result.add(new DatabaseAttachment(new AttachmentId(object.getLong(ROW_ID), object.getLong(UNIQUE_ID)), object.getLong(MMS_ID), !TextUtils.isEmpty(object.getString(DATA)), MediaUtil.isImageType(contentType) || MediaUtil.isVideoType(contentType), contentType, object.getInt(TRANSFER_STATE), object.getLong(SIZE), object.getString(FILE_NAME), object.getInt(CDN_NUMBER), object.getString(CONTENT_LOCATION), object.getString(CONTENT_DISPOSITION), object.getString(NAME), null, object.getString(FAST_PREFLIGHT_ID), object.getInt(VOICE_NOTE) == 1, object.getInt(BORDERLESS) == 1, object.getInt(VIDEO_GIF) == 1, object.getInt(WIDTH), object.getInt(HEIGHT), object.getInt(QUOTE) == 1, object.getString(CAPTION), object.getInt(STICKER_ID) >= 0 ? new StickerLocator(object.getString(STICKER_PACK_ID), object.getString(STICKER_PACK_KEY), object.getInt(STICKER_ID), object.getString(STICKER_EMOJI)) : null, MediaUtil.isAudioType(contentType) ? null : BlurHash.parseOrNull(object.getString(VISUAL_HASH)), MediaUtil.isAudioType(contentType) ? AudioHash.parseOrNull(object.getString(VISUAL_HASH)) : null, TransformProperties.parse(object.getString(TRANSFORM_PROPERTIES)), object.getInt(DISPLAY_ORDER), object.getLong(UPLOAD_TIMESTAMP)));
}
}
return result;
} else {
return Collections.singletonList(getAttachment(cursor));
}
} catch (JSONException e) {
throw new AssertionError(e);
}
}
use of org.thoughtcrime.securesms.attachments.DatabaseAttachment in project Signal-Android by WhisperSystems.
the class AttachmentDatabase method markAttachmentUploaded.
public void markAttachmentUploaded(long messageId, Attachment attachment) {
ContentValues values = new ContentValues(1);
SQLiteDatabase database = databaseHelper.getSignalWritableDatabase();
values.put(TRANSFER_STATE, TRANSFER_PROGRESS_DONE);
database.update(TABLE_NAME, values, PART_ID_WHERE, ((DatabaseAttachment) attachment).getAttachmentId().toStrings());
notifyConversationListeners(SignalDatabase.mms().getThreadIdForMessage(messageId));
}
use of org.thoughtcrime.securesms.attachments.DatabaseAttachment in project Signal-Android by WhisperSystems.
the class AttachmentDatabase method copyAttachmentData.
public void copyAttachmentData(@NonNull AttachmentId sourceId, @NonNull AttachmentId destinationId) throws MmsException {
DatabaseAttachment sourceAttachment = getAttachment(sourceId);
if (sourceAttachment == null) {
throw new MmsException("Cannot find attachment for source!");
}
SQLiteDatabase database = databaseHelper.getSignalWritableDatabase();
DataInfo sourceDataInfo = getAttachmentDataFileInfo(sourceId, DATA);
if (sourceDataInfo == null) {
throw new MmsException("No attachment data found for source!");
}
ContentValues contentValues = new ContentValues();
contentValues.put(DATA, sourceDataInfo.file.getAbsolutePath());
contentValues.put(DATA_HASH, sourceDataInfo.hash);
contentValues.put(SIZE, sourceDataInfo.length);
contentValues.put(DATA_RANDOM, sourceDataInfo.random);
contentValues.put(TRANSFER_STATE, sourceAttachment.getTransferState());
contentValues.put(CDN_NUMBER, sourceAttachment.getCdnNumber());
contentValues.put(CONTENT_LOCATION, sourceAttachment.getLocation());
contentValues.put(DIGEST, sourceAttachment.getDigest());
contentValues.put(CONTENT_DISPOSITION, sourceAttachment.getKey());
contentValues.put(NAME, sourceAttachment.getRelay());
contentValues.put(SIZE, sourceAttachment.getSize());
contentValues.put(FAST_PREFLIGHT_ID, sourceAttachment.getFastPreflightId());
contentValues.put(WIDTH, sourceAttachment.getWidth());
contentValues.put(HEIGHT, sourceAttachment.getHeight());
contentValues.put(CONTENT_TYPE, sourceAttachment.getContentType());
contentValues.put(VISUAL_HASH, getVisualHashStringOrNull(sourceAttachment));
database.update(TABLE_NAME, contentValues, PART_ID_WHERE, destinationId.toStrings());
}
use of org.thoughtcrime.securesms.attachments.DatabaseAttachment in project Signal-Android by WhisperSystems.
the class AttachmentDatabase method getAttachment.
@Nullable
public DatabaseAttachment getAttachment(@NonNull AttachmentId attachmentId) {
SQLiteDatabase database = databaseHelper.getSignalReadableDatabase();
Cursor cursor = null;
try {
cursor = database.query(TABLE_NAME, PROJECTION, PART_ID_WHERE, attachmentId.toStrings(), null, null, null);
if (cursor != null && cursor.moveToFirst()) {
List<DatabaseAttachment> list = getAttachments(cursor);
if (list != null && list.size() > 0) {
return list.get(0);
}
}
return null;
} finally {
if (cursor != null)
cursor.close();
}
}
Aggregations