Search in sources :

Example 16 with InsertResult

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

the class MessageContentProcessor method handleUnsupportedDataMessage.

private void handleUnsupportedDataMessage(@NonNull String sender, int senderDevice, @NonNull Optional<GroupId> groupId, long timestamp, @NonNull Optional<Long> smsMessageId) {
    log(timestamp, "Unsupported data message.");
    MessageDatabase smsDatabase = SignalDatabase.sms();
    if (!smsMessageId.isPresent()) {
        Optional<InsertResult> insertResult = insertPlaceholder(sender, senderDevice, timestamp, groupId);
        if (insertResult.isPresent()) {
            smsDatabase.markAsUnsupportedProtocolVersion(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 17 with InsertResult

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

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 18 with InsertResult

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

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 19 with InsertResult

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

the class GroupV1MessageProcessor method storeMessage.

@Nullable
private static Long storeMessage(@NonNull Context context, @NonNull SignalServiceContent content, @NonNull SignalServiceGroup group, @NonNull GroupContext storage, boolean outgoing) {
    if (group.getAvatar().isPresent()) {
        ApplicationDependencies.getJobManager().add(new AvatarGroupsV1DownloadJob(GroupId.v1orThrow(group.getGroupId())));
    }
    try {
        if (outgoing) {
            MessageDatabase mmsDatabase = SignalDatabase.mms();
            RecipientId recipientId = SignalDatabase.recipients().getOrInsertFromGroupId(GroupId.v1orThrow(group.getGroupId()));
            Recipient recipient = Recipient.resolved(recipientId);
            OutgoingGroupUpdateMessage outgoingMessage = new OutgoingGroupUpdateMessage(recipient, storage, null, content.getTimestamp(), 0, false, null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
            long threadId = SignalDatabase.threads().getOrCreateThreadIdFor(recipient);
            long messageId = mmsDatabase.insertMessageOutbox(outgoingMessage, threadId, false, null);
            mmsDatabase.markAsSent(messageId, true);
            return threadId;
        } else {
            MessageDatabase smsDatabase = SignalDatabase.sms();
            String body = Base64.encodeBytes(storage.toByteArray());
            IncomingTextMessage incoming = new IncomingTextMessage(Recipient.externalHighTrustPush(context, content.getSender()).getId(), content.getSenderDevice(), content.getTimestamp(), content.getServerReceivedTimestamp(), System.currentTimeMillis(), body, Optional.of(GroupId.v1orThrow(group.getGroupId())), 0, content.isNeedsReceipt(), content.getServerUuid());
            IncomingGroupUpdateMessage groupMessage = new IncomingGroupUpdateMessage(incoming, storage, body);
            Optional<InsertResult> insertResult = smsDatabase.insertMessageInbox(groupMessage);
            if (insertResult.isPresent()) {
                ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId());
                return insertResult.get().getThreadId();
            } else {
                return null;
            }
        }
    } catch (MmsException e) {
        Log.w(TAG, e);
    }
    return null;
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessageDatabase.InsertResult) AvatarGroupsV1DownloadJob(org.thoughtcrime.securesms.jobs.AvatarGroupsV1DownloadJob) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) MmsException(org.thoughtcrime.securesms.mms.MmsException) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) IncomingGroupUpdateMessage(org.thoughtcrime.securesms.sms.IncomingGroupUpdateMessage) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ByteString(com.google.protobuf.ByteString) OutgoingGroupUpdateMessage(org.thoughtcrime.securesms.mms.OutgoingGroupUpdateMessage) Nullable(androidx.annotation.Nullable)

Example 20 with InsertResult

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

the class SmsReceiveJob method storeMessage.

private Optional<InsertResult> storeMessage(IncomingTextMessage message) throws MigrationPendingException {
    MessageDatabase database = SignalDatabase.sms();
    database.ensureMigration();
    if (TextSecurePreferences.getNeedsSqlCipherMigration(context)) {
        throw new MigrationPendingException();
    }
    if (message.isSecureMessage()) {
        IncomingTextMessage placeholder = new IncomingTextMessage(message, "");
        Optional<InsertResult> insertResult = database.insertMessageInbox(placeholder);
        database.markAsLegacyVersion(insertResult.get().getMessageId());
        return insertResult;
    } else {
        return database.insertMessageInbox(message);
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessageDatabase.InsertResult) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage)

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