Search in sources :

Example 11 with MmsDatabase

use of org.thoughtcrime.securesms.database.MmsDatabase in project Signal-Android by WhisperSystems.

the class MmsDownloadJob method storeRetrievedMms.

private void storeRetrievedMms(MasterSecret masterSecret, String contentLocation, long messageId, long threadId, RetrieveConf retrieved, int subscriptionId) throws MmsException, NoSessionException, DuplicateMessageException, InvalidMessageException, LegacyMessageException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    SingleUseBlobProvider provider = SingleUseBlobProvider.getInstance();
    String from = null;
    List<String> to = new LinkedList<>();
    List<String> cc = new LinkedList<>();
    String body = null;
    List<Attachment> attachments = new LinkedList<>();
    if (retrieved.getFrom() != null) {
        from = Util.toIsoString(retrieved.getFrom().getTextString());
    }
    if (retrieved.getTo() != null) {
        for (EncodedStringValue toValue : retrieved.getTo()) {
            to.add(Util.toIsoString(toValue.getTextString()));
        }
    }
    if (retrieved.getCc() != null) {
        for (EncodedStringValue ccValue : retrieved.getCc()) {
            cc.add(Util.toIsoString(ccValue.getTextString()));
        }
    }
    if (retrieved.getBody() != null) {
        body = PartParser.getMessageText(retrieved.getBody());
        PduBody media = PartParser.getSupportedMediaParts(retrieved.getBody());
        for (int i = 0; i < media.getPartsNum(); i++) {
            PduPart part = media.getPart(i);
            if (part.getData() != null) {
                Uri uri = provider.createUri(part.getData());
                attachments.add(new UriAttachment(uri, Util.toIsoString(part.getContentType()), AttachmentDatabase.TRANSFER_PROGRESS_DONE, part.getData().length));
            }
        }
    }
    IncomingMediaMessage message = new IncomingMediaMessage(from, to, cc, body, retrieved.getDate() * 1000L, attachments, subscriptionId, 0, false);
    Optional<InsertResult> insertResult = database.insertMessageInbox(new MasterSecretUnion(masterSecret), message, contentLocation, threadId);
    if (insertResult.isPresent()) {
        database.delete(messageId);
        MessageNotifier.updateNotification(context, masterSecret, insertResult.get().getThreadId());
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) EncodedStringValue(ws.com.google.android.mms.pdu.EncodedStringValue) MasterSecretUnion(org.thoughtcrime.securesms.crypto.MasterSecretUnion) PduBody(ws.com.google.android.mms.pdu.PduBody) IncomingMediaMessage(org.thoughtcrime.securesms.mms.IncomingMediaMessage) UriAttachment(org.thoughtcrime.securesms.attachments.UriAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) Uri(android.net.Uri) LinkedList(java.util.LinkedList) SingleUseBlobProvider(org.thoughtcrime.securesms.providers.SingleUseBlobProvider) PduPart(ws.com.google.android.mms.pdu.PduPart) UriAttachment(org.thoughtcrime.securesms.attachments.UriAttachment) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 12 with MmsDatabase

use of org.thoughtcrime.securesms.database.MmsDatabase in project Signal-Android by WhisperSystems.

the class MmsDownloadJob method handleDownloadError.

private void handleDownloadError(MasterSecret masterSecret, long messageId, long threadId, int downloadStatus, boolean automatic) {
    MmsDatabase db = DatabaseFactory.getMmsDatabase(context);
    db.markDownloadState(messageId, downloadStatus);
    if (automatic) {
        db.markIncomingNotificationReceived(threadId);
        MessageNotifier.updateNotification(context, masterSecret, threadId);
    }
}
Also used : MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 13 with MmsDatabase

use of org.thoughtcrime.securesms.database.MmsDatabase in project Signal-Android by WhisperSystems.

the class PushDecryptJob method handleMediaMessage.

private void handleMediaMessage(@NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceDataMessage message, @NonNull Optional<Long> smsMessageId) throws MmsException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    String localNumber = TextSecurePreferences.getLocalNumber(context);
    Recipients recipients = getMessageDestination(envelope, message);
    IncomingMediaMessage mediaMessage = new IncomingMediaMessage(masterSecret, envelope.getSource(), localNumber, message.getTimestamp(), -1, message.getExpiresInSeconds() * 1000, false, Optional.fromNullable(envelope.getRelay()), message.getBody(), message.getGroupInfo(), message.getAttachments());
    if (message.getExpiresInSeconds() != recipients.getExpireMessages()) {
        handleExpirationUpdate(masterSecret, envelope, message, Optional.<Long>absent());
    }
    Optional<InsertResult> insertResult = database.insertSecureDecryptedMessageInbox(masterSecret, 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()));
        }
        if (smsMessageId.isPresent()) {
            DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get());
        }
        MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), insertResult.get().getThreadId());
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) Recipients(org.thoughtcrime.securesms.recipients.Recipients) IncomingMediaMessage(org.thoughtcrime.securesms.mms.IncomingMediaMessage) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 14 with MmsDatabase

use of org.thoughtcrime.securesms.database.MmsDatabase in project Signal-Android by WhisperSystems.

the class PushDecryptJob method handleSynchronizeSentMediaMessage.

private long handleSynchronizeSentMediaMessage(@NonNull MasterSecretUnion masterSecret, @NonNull SentTranscriptMessage message, @NonNull Optional<Long> smsMessageId) throws MmsException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    Recipients recipients = getSyncMessageDestination(message);
    OutgoingMediaMessage mediaMessage = new OutgoingMediaMessage(recipients, message.getMessage().getBody().orNull(), PointerAttachment.forPointers(masterSecret, message.getMessage().getAttachments()), message.getTimestamp(), -1, message.getMessage().getExpiresInSeconds() * 1000, ThreadDatabase.DistributionTypes.DEFAULT);
    mediaMessage = new OutgoingSecureMediaMessage(mediaMessage);
    if (recipients.getExpireMessages() != message.getMessage().getExpiresInSeconds()) {
        handleSynchronizeSentExpirationUpdate(masterSecret, message, Optional.<Long>absent());
    }
    long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
    long messageId = database.insertMessageOutbox(masterSecret, mediaMessage, threadId, false);
    database.markAsSent(messageId, true);
    for (DatabaseAttachment attachment : DatabaseFactory.getAttachmentDatabase(context).getAttachmentsForMessage(messageId)) {
        ApplicationContext.getInstance(context).getJobManager().add(new AttachmentDownloadJob(context, messageId, attachment.getAttachmentId()));
    }
    if (smsMessageId.isPresent()) {
        DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get());
    }
    if (message.getMessage().getExpiresInSeconds() > 0) {
        database.markExpireStarted(messageId, message.getExpirationStartTimestamp());
        ApplicationContext.getInstance(context).getExpiringMessageManager().scheduleDeletion(messageId, true, message.getExpirationStartTimestamp(), message.getMessage().getExpiresInSeconds());
    }
    return threadId;
}
Also used : OutgoingSecureMediaMessage(org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage) Recipients(org.thoughtcrime.securesms.recipients.Recipients) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 15 with MmsDatabase

use of org.thoughtcrime.securesms.database.MmsDatabase in project Signal-Android by WhisperSystems.

the class PushDecryptJob method handleExpirationUpdate.

private void handleExpirationUpdate(@NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceDataMessage message, @NonNull Optional<Long> smsMessageId) throws MmsException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    String localNumber = TextSecurePreferences.getLocalNumber(context);
    Recipients recipients = getMessageDestination(envelope, message);
    IncomingMediaMessage mediaMessage = new IncomingMediaMessage(masterSecret, envelope.getSource(), localNumber, message.getTimestamp(), -1, message.getExpiresInSeconds() * 1000, true, Optional.fromNullable(envelope.getRelay()), Optional.<String>absent(), message.getGroupInfo(), Optional.<List<SignalServiceAttachment>>absent());
    database.insertSecureDecryptedMessageInbox(masterSecret, mediaMessage, -1);
    DatabaseFactory.getRecipientPreferenceDatabase(context).setExpireMessages(recipients, message.getExpiresInSeconds());
    if (smsMessageId.isPresent()) {
        DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get());
    }
}
Also used : SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) Recipients(org.thoughtcrime.securesms.recipients.Recipients) IncomingMediaMessage(org.thoughtcrime.securesms.mms.IncomingMediaMessage) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Aggregations

MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)17 Recipients (org.thoughtcrime.securesms.recipients.Recipients)7 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)4 MasterSecretUnion (org.thoughtcrime.securesms.crypto.MasterSecretUnion)3 EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)3 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)3 IncomingMediaMessage (org.thoughtcrime.securesms.mms.IncomingMediaMessage)3 MmsException (ws.com.google.android.mms.MmsException)3 Nullable (android.support.annotation.Nullable)2 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)2 SmsDatabase (org.thoughtcrime.securesms.database.SmsDatabase)2 CompatMmsConnection (org.thoughtcrime.securesms.mms.CompatMmsConnection)2 ExpiringMessageManager (org.thoughtcrime.securesms.service.ExpiringMessageManager)2 InsecureFallbackApprovalException (org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)2 UndeliverableMessageException (org.thoughtcrime.securesms.transport.UndeliverableMessageException)2 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)2 UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)2 Uri (android.net.Uri)1