Search in sources :

Example 21 with MessageDatabase

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

the class ConversationDataSource method load.

@Override
@Nullable
public ConversationMessage load(@NonNull MessageId messageId) {
    Stopwatch stopwatch = new Stopwatch("load(" + messageId + "), thread " + threadId);
    MessageDatabase database = messageId.isMms() ? SignalDatabase.mms() : SignalDatabase.sms();
    MessageRecord record = database.getMessageRecordOrNull(messageId.getId());
    stopwatch.split("message");
    try {
        if (record != null) {
            List<Mention> mentions;
            if (messageId.isMms()) {
                mentions = SignalDatabase.mentions().getMentionsForMessage(messageId.getId());
            } else {
                mentions = Collections.emptyList();
            }
            stopwatch.split("mentions");
            List<ReactionRecord> reactions = SignalDatabase.reactions().getReactions(messageId);
            record = ReactionHelper.recordWithReactions(record, reactions);
            stopwatch.split("reactions");
            if (messageId.isMms()) {
                List<DatabaseAttachment> attachments = SignalDatabase.attachments().getAttachmentsForMessage(messageId.getId());
                if (attachments.size() > 0) {
                    record = ((MediaMmsMessageRecord) record).withAttachments(context, attachments);
                }
            }
            stopwatch.split("attachments");
            return ConversationMessage.ConversationMessageFactory.createWithUnresolvedData(ApplicationDependencies.getApplication(), record, mentions);
        } else {
            return null;
        }
    } finally {
        stopwatch.stop(TAG);
    }
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) Mention(org.thoughtcrime.securesms.database.model.Mention) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) InMemoryMessageRecord(org.thoughtcrime.securesms.database.model.InMemoryMessageRecord) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) ReactionRecord(org.thoughtcrime.securesms.database.model.ReactionRecord) Nullable(androidx.annotation.Nullable)

Example 22 with MessageDatabase

use of org.thoughtcrime.securesms.database.MessageDatabase 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 23 with MessageDatabase

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

the class LegacyMigrationJob method schedulePendingIncomingParts.

private void schedulePendingIncomingParts(Context context) {
    final AttachmentDatabase attachmentDb = SignalDatabase.attachments();
    final MessageDatabase mmsDb = SignalDatabase.mms();
    final List<DatabaseAttachment> pendingAttachments = SignalDatabase.attachments().getPendingAttachments();
    Log.i(TAG, pendingAttachments.size() + " pending parts.");
    for (DatabaseAttachment attachment : pendingAttachments) {
        final Reader reader = MmsDatabase.readerFor(mmsDb.getMessageCursor(attachment.getMmsId()));
        final MessageRecord record = reader.getNext();
        if (attachment.hasData()) {
            Log.i(TAG, "corrected a pending media part " + attachment.getAttachmentId() + "that already had data.");
            attachmentDb.setTransferState(attachment.getMmsId(), attachment.getAttachmentId(), AttachmentDatabase.TRANSFER_PROGRESS_DONE);
        } else if (record != null && !record.isOutgoing() && record.isPush()) {
            Log.i(TAG, "queuing new attachment download job for incoming push part " + attachment.getAttachmentId() + ".");
            ApplicationDependencies.getJobManager().add(new AttachmentDownloadJob(attachment.getMmsId(), attachment.getAttachmentId(), false));
        }
        reader.close();
    }
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) AttachmentDownloadJob(org.thoughtcrime.securesms.jobs.AttachmentDownloadJob) Reader(org.thoughtcrime.securesms.database.MmsDatabase.Reader) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) AttachmentDatabase(org.thoughtcrime.securesms.database.AttachmentDatabase)

Example 24 with MessageDatabase

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

the class SafetyNumberChangeRepository method processOutgoingMessageRecord.

@WorkerThread
private void processOutgoingMessageRecord(@NonNull List<ChangedRecipient> changedRecipients, @NonNull MessageRecord messageRecord) {
    Log.d(TAG, "processOutgoingMessageRecord");
    MessageDatabase smsDatabase = SignalDatabase.sms();
    MessageDatabase mmsDatabase = SignalDatabase.mms();
    for (ChangedRecipient changedRecipient : changedRecipients) {
        RecipientId id = changedRecipient.getRecipient().getId();
        IdentityKey identityKey = changedRecipient.getIdentityRecord().getIdentityKey();
        if (messageRecord.isMms()) {
            mmsDatabase.removeMismatchedIdentity(messageRecord.getId(), id, identityKey);
            if (messageRecord.getRecipient().isPushGroup()) {
                MessageSender.resendGroupMessage(context, messageRecord, id);
            } else {
                MessageSender.resend(context, messageRecord);
            }
        } else {
            smsDatabase.removeMismatchedIdentity(messageRecord.getId(), id, identityKey);
            MessageSender.resend(context, messageRecord);
        }
    }
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) IdentityKey(org.whispersystems.libsignal.IdentityKey) WorkerThread(androidx.annotation.WorkerThread)

Example 25 with MessageDatabase

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

the class VoiceNotePlaybackService method sendViewedReceiptForCurrentWindowIndex.

private void sendViewedReceiptForCurrentWindowIndex() {
    if (player.getPlaybackState() == Player.STATE_READY && player.getPlayWhenReady() && player.getCurrentWindowIndex() != C.INDEX_UNSET) {
        MediaItem currentMediaItem = player.getCurrentMediaItem();
        if (currentMediaItem == null || currentMediaItem.playbackProperties == null) {
            return;
        }
        Uri mediaUri = currentMediaItem.playbackProperties.uri;
        if (!mediaUri.getScheme().equals("content")) {
            return;
        }
        SignalExecutors.BOUNDED.execute(() -> {
            Bundle extras = currentMediaItem.mediaMetadata.extras;
            if (extras == null) {
                return;
            }
            long messageId = extras.getLong(VoiceNoteMediaItemFactory.EXTRA_MESSAGE_ID);
            RecipientId recipientId = RecipientId.from(extras.getString(VoiceNoteMediaItemFactory.EXTRA_INDIVIDUAL_RECIPIENT_ID));
            MessageDatabase messageDatabase = SignalDatabase.mms();
            MessageDatabase.MarkedMessageInfo markedMessageInfo = messageDatabase.setIncomingMessageViewed(messageId);
            if (markedMessageInfo != null) {
                ApplicationDependencies.getJobManager().add(new SendViewedReceiptJob(markedMessageInfo.getThreadId(), recipientId, markedMessageInfo.getSyncMessageId().getTimetamp(), new MessageId(messageId, true)));
                MultiDeviceViewedUpdateJob.enqueue(Collections.singletonList(markedMessageInfo.getSyncMessageId()));
            }
        });
    }
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) MediaItem(com.google.android.exoplayer2.MediaItem) Bundle(android.os.Bundle) SendViewedReceiptJob(org.thoughtcrime.securesms.jobs.SendViewedReceiptJob) Uri(android.net.Uri) MessageId(org.thoughtcrime.securesms.database.model.MessageId)

Aggregations

MessageDatabase (org.thoughtcrime.securesms.database.MessageDatabase)94 Recipient (org.thoughtcrime.securesms.recipients.Recipient)36 InsertResult (org.thoughtcrime.securesms.database.MessageDatabase.InsertResult)28 SyncMessageId (org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId)26 MmsException (org.thoughtcrime.securesms.mms.MmsException)26 Nullable (androidx.annotation.Nullable)22 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)22 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)22 MessageId (org.thoughtcrime.securesms.database.model.MessageId)20 NoSuchMessageException (org.thoughtcrime.securesms.database.NoSuchMessageException)18 Attachment (org.thoughtcrime.securesms.attachments.Attachment)16 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)16 IncomingTextMessage (org.thoughtcrime.securesms.sms.IncomingTextMessage)16 WorkerThread (androidx.annotation.WorkerThread)14 IOException (java.io.IOException)14 List (java.util.List)14 MessageRecord (org.thoughtcrime.securesms.database.model.MessageRecord)14 SmsMessageRecord (org.thoughtcrime.securesms.database.model.SmsMessageRecord)14 ArrayList (java.util.ArrayList)12 LinkedList (java.util.LinkedList)12