Search in sources :

Example 6 with DatabaseAttachment

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

the class AttachmentDatabaseTest method getMockAttachment.

private DatabaseAttachment getMockAttachment(String contentType) {
    DatabaseAttachment attachment = mock(DatabaseAttachment.class);
    when(attachment.getContentType()).thenReturn(contentType);
    when(attachment.getDataUri()).thenReturn(Uri.EMPTY);
    when(attachment.hasData()).thenReturn(true);
    return attachment;
}
Also used : DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment)

Example 7 with DatabaseAttachment

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

the class PushDecryptJob method handleMediaMessage.

private void handleMediaMessage(@NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceDataMessage message, @NonNull Optional<Long> smsMessageId) throws MmsException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    Recipient recipient = getMessageDestination(envelope, message);
    IncomingMediaMessage mediaMessage = new IncomingMediaMessage(Address.fromExternal(context, envelope.getSource()), message.getTimestamp(), -1, message.getExpiresInSeconds() * 1000L, false, Optional.fromNullable(envelope.getRelay()), message.getBody(), message.getGroupInfo(), message.getAttachments());
    if (message.getExpiresInSeconds() != recipient.getExpireMessages()) {
        handleExpirationUpdate(envelope, message, Optional.absent());
    }
    Optional<InsertResult> insertResult = database.insertSecureDecryptedMessageInbox(mediaMessage, -1);
    if (insertResult.isPresent()) {
        List<DatabaseAttachment> attachments = DatabaseFactory.getAttachmentDatabase(context).getAttachmentsForMessage(insertResult.get().getMessageId());
        for (DatabaseAttachment attachment : attachments) {
            ApplicationContext.getInstance(context).getJobManager().add(new AttachmentDownloadJob(context, insertResult.get().getMessageId(), attachment.getAttachmentId(), false));
        }
        if (smsMessageId.isPresent()) {
            DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get());
        }
        MessageNotifier.updateNotification(context, insertResult.get().getThreadId());
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) IncomingMediaMessage(org.thoughtcrime.securesms.mms.IncomingMediaMessage) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) Recipient(org.thoughtcrime.securesms.recipients.Recipient) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 8 with DatabaseAttachment

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

the class AttachmentDownloadJob method doWork.

public void doWork() throws IOException, RetryLaterException {
    Log.i(TAG, "onRun() messageId: " + messageId + "  partRowId: " + partRowId + "  partUniqueId: " + partUniqueId + "  manual: " + manual);
    final AttachmentDatabase database = SignalDatabase.attachments();
    final AttachmentId attachmentId = new AttachmentId(partRowId, partUniqueId);
    final DatabaseAttachment attachment = database.getAttachment(attachmentId);
    if (attachment == null) {
        Log.w(TAG, "attachment no longer exists.");
        return;
    }
    if (!attachment.isInProgress()) {
        Log.w(TAG, "Attachment was already downloaded.");
        return;
    }
    if (!manual && !AttachmentUtil.isAutoDownloadPermitted(context, attachment)) {
        Log.w(TAG, "Attachment can't be auto downloaded...");
        database.setTransferState(messageId, attachmentId, AttachmentDatabase.TRANSFER_PROGRESS_PENDING);
        return;
    }
    Log.i(TAG, "Downloading push part " + attachmentId);
    database.setTransferState(messageId, attachmentId, AttachmentDatabase.TRANSFER_PROGRESS_STARTED);
    if (attachment.getCdnNumber() != ReleaseChannel.CDN_NUMBER) {
        retrieveAttachment(messageId, attachmentId, attachment);
    } else {
        retrieveUrlAttachment(messageId, attachmentId, attachment);
    }
}
Also used : DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) AttachmentDatabase(org.thoughtcrime.securesms.database.AttachmentDatabase) AttachmentId(org.thoughtcrime.securesms.attachments.AttachmentId)

Example 9 with DatabaseAttachment

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

the class AttachmentDownloadJob method onAdded.

@Override
public void onAdded() {
    Log.i(TAG, "onAdded() messageId: " + messageId + "  partRowId: " + partRowId + "  partUniqueId: " + partUniqueId + "  manual: " + manual);
    final AttachmentDatabase database = SignalDatabase.attachments();
    final AttachmentId attachmentId = new AttachmentId(partRowId, partUniqueId);
    final DatabaseAttachment attachment = database.getAttachment(attachmentId);
    final boolean pending = attachment != null && attachment.getTransferState() != AttachmentDatabase.TRANSFER_PROGRESS_DONE;
    if (pending && (manual || AttachmentUtil.isAutoDownloadPermitted(context, attachment))) {
        Log.i(TAG, "onAdded() Marking attachment progress as 'started'");
        database.setTransferState(messageId, attachmentId, AttachmentDatabase.TRANSFER_PROGRESS_STARTED);
    }
}
Also used : DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) AttachmentDatabase(org.thoughtcrime.securesms.database.AttachmentDatabase) AttachmentId(org.thoughtcrime.securesms.attachments.AttachmentId)

Example 10 with DatabaseAttachment

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

the class AttachmentMarkUploadedJob method onRun.

@Override
public void onRun() throws Exception {
    AttachmentDatabase database = SignalDatabase.attachments();
    DatabaseAttachment databaseAttachment = database.getAttachment(attachmentId);
    if (databaseAttachment == null) {
        throw new InvalidAttachmentException("Cannot find the specified attachment.");
    }
    database.markAttachmentUploaded(messageId, databaseAttachment);
}
Also used : DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) AttachmentDatabase(org.thoughtcrime.securesms.database.AttachmentDatabase)

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