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;
}
}
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);
}
Aggregations