Search in sources :

Example 6 with InsertResult

use of org.thoughtcrime.securesms.database.MessageDatabase.InsertResult in project Signal-Android by signalapp.

the class MessageContentProcessor method handleInvalidMessage.

private void handleInvalidMessage(@NonNull SignalServiceAddress sender, int senderDevice, @NonNull Optional<GroupId> groupId, long timestamp, @NonNull Optional<Long> smsMessageId) {
    log(timestamp, "Invalid message.");
    MessageDatabase smsDatabase = SignalDatabase.sms();
    if (!smsMessageId.isPresent()) {
        Optional<InsertResult> insertResult = insertPlaceholder(sender.getIdentifier(), senderDevice, timestamp, groupId);
        if (insertResult.isPresent()) {
            smsDatabase.markAsInvalidMessage(insertResult.get().getMessageId());
            ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId());
        }
    } else {
        smsDatabase.markAsNoSession(smsMessageId.get());
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessageDatabase.InsertResult) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase)

Example 7 with InsertResult

use of org.thoughtcrime.securesms.database.MessageDatabase.InsertResult in project Signal-Android by signalapp.

the class MessageContentProcessor method handleLegacyMessage.

private void handleLegacyMessage(@NonNull String sender, int senderDevice, long timestamp, @NonNull Optional<Long> smsMessageId) {
    log(timestamp, "Legacy message.");
    MessageDatabase smsDatabase = SignalDatabase.sms();
    if (!smsMessageId.isPresent()) {
        Optional<InsertResult> insertResult = insertPlaceholder(sender, senderDevice, timestamp);
        if (insertResult.isPresent()) {
            smsDatabase.markAsLegacyVersion(insertResult.get().getMessageId());
            ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId());
        }
    } else {
        smsDatabase.markAsLegacyVersion(smsMessageId.get());
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessageDatabase.InsertResult) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase)

Example 8 with InsertResult

use of org.thoughtcrime.securesms.database.MessageDatabase.InsertResult in project Signal-Android by signalapp.

the class MessageContentProcessor method handleInvalidVersionMessage.

private void handleInvalidVersionMessage(@NonNull String sender, int senderDevice, long timestamp, @NonNull Optional<Long> smsMessageId) {
    log(timestamp, "Invalid version message.");
    MessageDatabase smsDatabase = SignalDatabase.sms();
    if (!smsMessageId.isPresent()) {
        Optional<InsertResult> insertResult = insertPlaceholder(sender, senderDevice, timestamp);
        if (insertResult.isPresent()) {
            smsDatabase.markAsInvalidVersionKeyExchange(insertResult.get().getMessageId());
            ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId());
        }
    } else {
        smsDatabase.markAsInvalidVersionKeyExchange(smsMessageId.get());
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessageDatabase.InsertResult) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase)

Example 9 with InsertResult

use of org.thoughtcrime.securesms.database.MessageDatabase.InsertResult in project Signal-Android by signalapp.

the class MessageContentProcessor method handleCorruptMessage.

private void handleCorruptMessage(@NonNull String sender, int senderDevice, long timestamp, @NonNull Optional<Long> smsMessageId) {
    log(timestamp, "Corrupt message.");
    MessageDatabase smsDatabase = SignalDatabase.sms();
    if (!smsMessageId.isPresent()) {
        Optional<InsertResult> insertResult = insertPlaceholder(sender, senderDevice, timestamp);
        if (insertResult.isPresent()) {
            smsDatabase.markAsDecryptFailed(insertResult.get().getMessageId());
            ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId());
        }
    } else {
        smsDatabase.markAsDecryptFailed(smsMessageId.get());
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessageDatabase.InsertResult) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase)

Example 10 with InsertResult

use of org.thoughtcrime.securesms.database.MessageDatabase.InsertResult in project Signal-Android by signalapp.

the class MessageContentProcessor method handleMediaMessage.

@Nullable
private MessageId handleMediaMessage(@NonNull SignalServiceContent content, @NonNull SignalServiceDataMessage message, @NonNull Optional<Long> smsMessageId, @NonNull Recipient senderRecipient, @NonNull Recipient threadRecipient, long receivedTime) throws StorageFailedException {
    log(message.getTimestamp(), "Media message.");
    notifyTypingStoppedFromIncomingMessage(senderRecipient, threadRecipient, content.getSenderDevice());
    Optional<InsertResult> insertResult;
    MessageDatabase database = SignalDatabase.mms();
    database.beginTransaction();
    try {
        Optional<QuoteModel> quote = getValidatedQuote(message.getQuote());
        Optional<List<Contact>> sharedContacts = getContacts(message.getSharedContacts());
        Optional<List<LinkPreview>> linkPreviews = getLinkPreviews(message.getPreviews(), message.getBody().or(""));
        Optional<List<Mention>> mentions = getMentions(message.getMentions());
        Optional<Attachment> sticker = getStickerAttachment(message.getSticker());
        IncomingMediaMessage mediaMessage = new IncomingMediaMessage(senderRecipient.getId(), message.getTimestamp(), content.getServerReceivedTimestamp(), receivedTime, -1, TimeUnit.SECONDS.toMillis(message.getExpiresInSeconds()), false, message.isViewOnce(), content.isNeedsReceipt(), message.getBody(), message.getGroupContext(), message.getAttachments(), quote, sharedContacts, linkPreviews, mentions, sticker, content.getServerUuid());
        insertResult = database.insertSecureDecryptedMessageInbox(mediaMessage, -1);
        if (insertResult.isPresent()) {
            if (smsMessageId.isPresent()) {
                SignalDatabase.sms().deleteMessage(smsMessageId.get());
            }
            database.setTransactionSuccessful();
        }
    } catch (MmsException e) {
        throw new StorageFailedException(e, content.getSender().getIdentifier(), content.getSenderDevice());
    } finally {
        database.endTransaction();
    }
    if (insertResult.isPresent()) {
        List<DatabaseAttachment> allAttachments = SignalDatabase.attachments().getAttachmentsForMessage(insertResult.get().getMessageId());
        List<DatabaseAttachment> stickerAttachments = Stream.of(allAttachments).filter(Attachment::isSticker).toList();
        List<DatabaseAttachment> attachments = Stream.of(allAttachments).filterNot(Attachment::isSticker).toList();
        forceStickerDownloadIfNecessary(insertResult.get().getMessageId(), stickerAttachments);
        for (DatabaseAttachment attachment : attachments) {
            ApplicationDependencies.getJobManager().add(new AttachmentDownloadJob(insertResult.get().getMessageId(), attachment.getAttachmentId(), false));
        }
        ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId());
        TrimThreadJob.enqueueAsync(insertResult.get().getThreadId());
        if (message.isViewOnce()) {
            ApplicationDependencies.getViewOnceMessageManager().scheduleIfNecessary();
        }
        return new MessageId(insertResult.get().getMessageId(), true);
    } else {
        return null;
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessageDatabase.InsertResult) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) IncomingMediaMessage(org.thoughtcrime.securesms.mms.IncomingMediaMessage) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) PointerAttachment(org.thoughtcrime.securesms.attachments.PointerAttachment) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) UriAttachment(org.thoughtcrime.securesms.attachments.UriAttachment) TombstoneAttachment(org.thoughtcrime.securesms.attachments.TombstoneAttachment) QuoteModel(org.thoughtcrime.securesms.mms.QuoteModel) MmsException(org.thoughtcrime.securesms.mms.MmsException) AttachmentDownloadJob(org.thoughtcrime.securesms.jobs.AttachmentDownloadJob) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) MessageId(org.thoughtcrime.securesms.database.model.MessageId) SyncMessageId(org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId) Nullable(androidx.annotation.Nullable)

Aggregations

InsertResult (org.thoughtcrime.securesms.database.MessageDatabase.InsertResult)30 MessageDatabase (org.thoughtcrime.securesms.database.MessageDatabase)26 IncomingTextMessage (org.thoughtcrime.securesms.sms.IncomingTextMessage)12 Nullable (androidx.annotation.Nullable)10 SyncMessageId (org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId)8 MessageId (org.thoughtcrime.securesms.database.model.MessageId)8 IncomingMediaMessage (org.thoughtcrime.securesms.mms.IncomingMediaMessage)6 MmsException (org.thoughtcrime.securesms.mms.MmsException)6 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)6 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)4 Attachment (org.thoughtcrime.securesms.attachments.Attachment)4 UriAttachment (org.thoughtcrime.securesms.attachments.UriAttachment)4 Recipient (org.thoughtcrime.securesms.recipients.Recipient)4 SuppressLint (android.annotation.SuppressLint)2 Notification (android.app.Notification)2 NotificationManager (android.app.NotificationManager)2 Intent (android.content.Intent)2 Uri (android.net.Uri)2 EncodedStringValue (com.google.android.mms.pdu_alt.EncodedStringValue)2