Search in sources :

Example 31 with MessageDatabase

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

the class MmsDownloadJob method onRun.

@Override
public void onRun() {
    if (SignalStore.account().getE164() == null) {
        throw new NotReadyException();
    }
    MessageDatabase database = SignalDatabase.mms();
    Optional<MmsDatabase.MmsNotificationInfo> notification = database.getNotification(messageId);
    if (!notification.isPresent()) {
        Log.w(TAG, "No notification for ID: " + messageId);
        return;
    }
    try {
        if (notification.get().getContentLocation() == null) {
            throw new MmsException("Notification content location was null.");
        }
        if (!SignalStore.account().isRegistered()) {
            throw new MmsException("Not registered");
        }
        database.markDownloadState(messageId, MmsDatabase.Status.DOWNLOAD_CONNECTING);
        String contentLocation = notification.get().getContentLocation();
        byte[] transactionId = new byte[0];
        try {
            if (notification.get().getTransactionId() != null) {
                transactionId = notification.get().getTransactionId().getBytes(CharacterSets.MIMENAME_ISO_8859_1);
            } else {
                Log.w(TAG, "No transaction ID!");
            }
        } catch (UnsupportedEncodingException e) {
            Log.w(TAG, e);
        }
        Log.i(TAG, "Downloading mms at " + Uri.parse(contentLocation).getHost() + ", subscription ID: " + notification.get().getSubscriptionId());
        RetrieveConf retrieveConf = new CompatMmsConnection(context).retrieve(contentLocation, transactionId, notification.get().getSubscriptionId());
        if (retrieveConf == null) {
            throw new MmsException("RetrieveConf was null");
        }
        storeRetrievedMms(contentLocation, messageId, threadId, retrieveConf, notification.get().getSubscriptionId(), notification.get().getFrom());
    } catch (ApnUnavailableException e) {
        Log.w(TAG, e);
        handleDownloadError(messageId, threadId, MmsDatabase.Status.DOWNLOAD_APN_UNAVAILABLE, automatic);
    } catch (MmsException e) {
        Log.w(TAG, e);
        handleDownloadError(messageId, threadId, MmsDatabase.Status.DOWNLOAD_HARD_FAILURE, automatic);
    } catch (MmsRadioException | IOException e) {
        Log.w(TAG, e);
        handleDownloadError(messageId, threadId, MmsDatabase.Status.DOWNLOAD_SOFT_FAILURE, automatic);
    }
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) CompatMmsConnection(org.thoughtcrime.securesms.mms.CompatMmsConnection) MmsException(org.thoughtcrime.securesms.mms.MmsException) ApnUnavailableException(org.thoughtcrime.securesms.mms.ApnUnavailableException) MmsRadioException(org.thoughtcrime.securesms.mms.MmsRadioException) RetrieveConf(com.google.android.mms.pdu_alt.RetrieveConf)

Example 32 with MessageDatabase

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

the class MessageSender method sendMediaBroadcast.

public static void sendMediaBroadcast(@NonNull Context context, @NonNull List<OutgoingSecureMediaMessage> messages, @NonNull Collection<PreUploadResult> preUploadResults) {
    Log.i(TAG, "Sending media broadcast to " + Stream.of(messages).map(m -> m.getRecipient().getId()).toList());
    Preconditions.checkArgument(messages.size() > 0, "No messages!");
    Preconditions.checkArgument(Stream.of(messages).allMatch(m -> m.getAttachments().isEmpty()), "Messages can't have attachments! They should be pre-uploaded.");
    JobManager jobManager = ApplicationDependencies.getJobManager();
    AttachmentDatabase attachmentDatabase = SignalDatabase.attachments();
    MessageDatabase mmsDatabase = SignalDatabase.mms();
    ThreadDatabase threadDatabase = SignalDatabase.threads();
    List<AttachmentId> preUploadAttachmentIds = Stream.of(preUploadResults).map(PreUploadResult::getAttachmentId).toList();
    List<String> preUploadJobIds = Stream.of(preUploadResults).map(PreUploadResult::getJobIds).flatMap(Stream::of).toList();
    List<Long> messageIds = new ArrayList<>(messages.size());
    List<String> messageDependsOnIds = new ArrayList<>(preUploadJobIds);
    mmsDatabase.beginTransaction();
    try {
        OutgoingSecureMediaMessage primaryMessage = messages.get(0);
        long primaryThreadId = threadDatabase.getOrCreateThreadIdFor(primaryMessage.getRecipient(), primaryMessage.getDistributionType());
        long primaryMessageId = mmsDatabase.insertMessageOutbox(applyUniversalExpireTimerIfNecessary(context, primaryMessage.getRecipient(), primaryMessage, primaryThreadId), primaryThreadId, false, null);
        attachmentDatabase.updateMessageId(preUploadAttachmentIds, primaryMessageId);
        messageIds.add(primaryMessageId);
        if (messages.size() > 0) {
            List<OutgoingSecureMediaMessage> secondaryMessages = messages.subList(1, messages.size());
            List<List<AttachmentId>> attachmentCopies = new ArrayList<>();
            List<DatabaseAttachment> preUploadAttachments = Stream.of(preUploadAttachmentIds).map(attachmentDatabase::getAttachment).toList();
            for (int i = 0; i < preUploadAttachmentIds.size(); i++) {
                attachmentCopies.add(new ArrayList<>(messages.size()));
            }
            for (OutgoingSecureMediaMessage secondaryMessage : secondaryMessages) {
                long allocatedThreadId = threadDatabase.getOrCreateThreadIdFor(secondaryMessage.getRecipient(), secondaryMessage.getDistributionType());
                long messageId = mmsDatabase.insertMessageOutbox(applyUniversalExpireTimerIfNecessary(context, secondaryMessage.getRecipient(), secondaryMessage, allocatedThreadId), allocatedThreadId, false, null);
                List<AttachmentId> attachmentIds = new ArrayList<>(preUploadAttachmentIds.size());
                for (int i = 0; i < preUploadAttachments.size(); i++) {
                    AttachmentId attachmentId = attachmentDatabase.insertAttachmentForPreUpload(preUploadAttachments.get(i)).getAttachmentId();
                    attachmentCopies.get(i).add(attachmentId);
                    attachmentIds.add(attachmentId);
                }
                attachmentDatabase.updateMessageId(attachmentIds, messageId);
                messageIds.add(messageId);
            }
            for (int i = 0; i < attachmentCopies.size(); i++) {
                Job copyJob = new AttachmentCopyJob(preUploadAttachmentIds.get(i), attachmentCopies.get(i));
                jobManager.add(copyJob, preUploadJobIds);
                messageDependsOnIds.add(copyJob.getId());
            }
        }
        for (int i = 0; i < messageIds.size(); i++) {
            long messageId = messageIds.get(i);
            OutgoingSecureMediaMessage message = messages.get(i);
            Recipient recipient = message.getRecipient();
            if (isLocalSelfSend(context, recipient, false)) {
                sendLocalMediaSelf(context, messageId);
            } else if (isGroupPushSend(recipient)) {
                jobManager.add(new PushGroupSendJob(messageId, recipient.getId(), null, true), messageDependsOnIds, recipient.getId().toQueueKey());
            } else {
                jobManager.add(new PushMediaSendJob(messageId, recipient, true), messageDependsOnIds, recipient.getId().toQueueKey());
            }
        }
        onMessageSent();
        mmsDatabase.setTransactionSuccessful();
    } catch (MmsException e) {
        Log.w(TAG, "Failed to send messages.", e);
    } finally {
        mmsDatabase.endTransaction();
    }
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) Arrays(java.util.Arrays) LinkPreview(org.thoughtcrime.securesms.linkpreview.LinkPreview) NonNull(androidx.annotation.NonNull) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) RecipientUtil(org.thoughtcrime.securesms.recipients.RecipientUtil) AttachmentMarkUploadedJob(org.thoughtcrime.securesms.jobs.AttachmentMarkUploadedJob) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) Preconditions(org.whispersystems.libsignal.util.guava.Preconditions) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) ParcelUtil(org.thoughtcrime.securesms.util.ParcelUtil) ReactionSendJob(org.thoughtcrime.securesms.jobs.ReactionSendJob) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SyncMessageId(org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId) PushMediaSendJob(org.thoughtcrime.securesms.jobs.PushMediaSendJob) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Collection(java.util.Collection) OutgoingSecureMediaMessage(org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage) ReactionRecord(org.thoughtcrime.securesms.database.model.ReactionRecord) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) Log(org.signal.core.util.logging.Log) List(java.util.List) Nullable(androidx.annotation.Nullable) Job(org.thoughtcrime.securesms.jobmanager.Job) ResumableUploadSpecJob(org.thoughtcrime.securesms.jobs.ResumableUploadSpecJob) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) PushGroupSendJob(org.thoughtcrime.securesms.jobs.PushGroupSendJob) NoSuchMessageException(org.thoughtcrime.securesms.database.NoSuchMessageException) Attachment(org.thoughtcrime.securesms.attachments.Attachment) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) AttachmentCompressionJob(org.thoughtcrime.securesms.jobs.AttachmentCompressionJob) Context(android.content.Context) MmsSmsDatabase(org.thoughtcrime.securesms.database.MmsSmsDatabase) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) ProfileKeySendJob(org.thoughtcrime.securesms.jobs.ProfileKeySendJob) Stream(com.annimon.stream.Stream) DirectoryHelper(org.thoughtcrime.securesms.contacts.sync.DirectoryHelper) SignalLocalMetrics(org.thoughtcrime.securesms.util.SignalLocalMetrics) WorkerThread(androidx.annotation.WorkerThread) AttachmentDatabase(org.thoughtcrime.securesms.database.AttachmentDatabase) RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) Parcel(android.os.Parcel) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) ArrayList(java.util.ArrayList) RemoteDeleteSendJob(org.thoughtcrime.securesms.jobs.RemoteDeleteSendJob) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) MmsSendJob(org.thoughtcrime.securesms.jobs.MmsSendJob) AttachmentUploadJob(org.thoughtcrime.securesms.jobs.AttachmentUploadJob) PushTextSendJob(org.thoughtcrime.securesms.jobs.PushTextSendJob) EventBus(org.greenrobot.eventbus.EventBus) AttachmentCopyJob(org.thoughtcrime.securesms.jobs.AttachmentCopyJob) LinkedList(java.util.LinkedList) Parcelable(android.os.Parcelable) MessageId(org.thoughtcrime.securesms.database.model.MessageId) Contact(org.thoughtcrime.securesms.contactshare.Contact) MmsException(org.thoughtcrime.securesms.mms.MmsException) IOException(java.io.IOException) Optional(org.whispersystems.libsignal.util.guava.Optional) TimeUnit(java.util.concurrent.TimeUnit) AttachmentId(org.thoughtcrime.securesms.attachments.AttachmentId) SmsSendJob(org.thoughtcrime.securesms.jobs.SmsSendJob) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) Collections(java.util.Collections) PushGroupSendJob(org.thoughtcrime.securesms.jobs.PushGroupSendJob) ArrayList(java.util.ArrayList) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) MmsException(org.thoughtcrime.securesms.mms.MmsException) AttachmentCopyJob(org.thoughtcrime.securesms.jobs.AttachmentCopyJob) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) PushMediaSendJob(org.thoughtcrime.securesms.jobs.PushMediaSendJob) AttachmentMarkUploadedJob(org.thoughtcrime.securesms.jobs.AttachmentMarkUploadedJob) ReactionSendJob(org.thoughtcrime.securesms.jobs.ReactionSendJob) PushMediaSendJob(org.thoughtcrime.securesms.jobs.PushMediaSendJob) Job(org.thoughtcrime.securesms.jobmanager.Job) ResumableUploadSpecJob(org.thoughtcrime.securesms.jobs.ResumableUploadSpecJob) PushGroupSendJob(org.thoughtcrime.securesms.jobs.PushGroupSendJob) AttachmentCompressionJob(org.thoughtcrime.securesms.jobs.AttachmentCompressionJob) ProfileKeySendJob(org.thoughtcrime.securesms.jobs.ProfileKeySendJob) RemoteDeleteSendJob(org.thoughtcrime.securesms.jobs.RemoteDeleteSendJob) MmsSendJob(org.thoughtcrime.securesms.jobs.MmsSendJob) AttachmentUploadJob(org.thoughtcrime.securesms.jobs.AttachmentUploadJob) PushTextSendJob(org.thoughtcrime.securesms.jobs.PushTextSendJob) AttachmentCopyJob(org.thoughtcrime.securesms.jobs.AttachmentCopyJob) SmsSendJob(org.thoughtcrime.securesms.jobs.SmsSendJob) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) AttachmentDatabase(org.thoughtcrime.securesms.database.AttachmentDatabase) AttachmentId(org.thoughtcrime.securesms.attachments.AttachmentId) OutgoingSecureMediaMessage(org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage)

Example 33 with MessageDatabase

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

the class MessageSender method sendLocalMediaSelf.

private static void sendLocalMediaSelf(Context context, long messageId) {
    try {
        ExpiringMessageManager expirationManager = ApplicationDependencies.getExpiringMessageManager();
        MessageDatabase mmsDatabase = SignalDatabase.mms();
        MmsSmsDatabase mmsSmsDatabase = SignalDatabase.mmsSms();
        OutgoingMediaMessage message = mmsDatabase.getOutgoingMessage(messageId);
        SyncMessageId syncId = new SyncMessageId(Recipient.self().getId(), message.getSentTimeMillis());
        List<Attachment> attachments = new LinkedList<>();
        attachments.addAll(message.getAttachments());
        attachments.addAll(Stream.of(message.getLinkPreviews()).map(LinkPreview::getThumbnail).filter(Optional::isPresent).map(Optional::get).toList());
        attachments.addAll(Stream.of(message.getSharedContacts()).map(Contact::getAvatar).withoutNulls().map(Contact.Avatar::getAttachment).withoutNulls().toList());
        List<AttachmentCompressionJob> compressionJobs = Stream.of(attachments).map(a -> AttachmentCompressionJob.fromAttachment((DatabaseAttachment) a, false, -1)).toList();
        List<AttachmentMarkUploadedJob> fakeUploadJobs = Stream.of(attachments).map(a -> new AttachmentMarkUploadedJob(messageId, ((DatabaseAttachment) a).getAttachmentId())).toList();
        ApplicationDependencies.getJobManager().startChain(compressionJobs).then(fakeUploadJobs).enqueue();
        mmsDatabase.markAsSent(messageId, true);
        mmsDatabase.markUnidentified(messageId, true);
        mmsSmsDatabase.incrementDeliveryReceiptCount(syncId, System.currentTimeMillis());
        mmsSmsDatabase.incrementReadReceiptCount(syncId, System.currentTimeMillis());
        mmsSmsDatabase.incrementViewedReceiptCount(syncId, System.currentTimeMillis());
        if (message.getExpiresIn() > 0 && !message.isExpirationUpdate()) {
            mmsDatabase.markExpireStarted(messageId);
            expirationManager.scheduleDeletion(messageId, true, message.getExpiresIn());
        }
    } catch (NoSuchMessageException | MmsException e) {
        Log.w(TAG, "Failed to update self-sent message.", e);
    }
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) Arrays(java.util.Arrays) LinkPreview(org.thoughtcrime.securesms.linkpreview.LinkPreview) NonNull(androidx.annotation.NonNull) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) RecipientUtil(org.thoughtcrime.securesms.recipients.RecipientUtil) AttachmentMarkUploadedJob(org.thoughtcrime.securesms.jobs.AttachmentMarkUploadedJob) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) Preconditions(org.whispersystems.libsignal.util.guava.Preconditions) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) ParcelUtil(org.thoughtcrime.securesms.util.ParcelUtil) ReactionSendJob(org.thoughtcrime.securesms.jobs.ReactionSendJob) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SyncMessageId(org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId) PushMediaSendJob(org.thoughtcrime.securesms.jobs.PushMediaSendJob) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Collection(java.util.Collection) OutgoingSecureMediaMessage(org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage) ReactionRecord(org.thoughtcrime.securesms.database.model.ReactionRecord) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) Log(org.signal.core.util.logging.Log) List(java.util.List) Nullable(androidx.annotation.Nullable) Job(org.thoughtcrime.securesms.jobmanager.Job) ResumableUploadSpecJob(org.thoughtcrime.securesms.jobs.ResumableUploadSpecJob) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) PushGroupSendJob(org.thoughtcrime.securesms.jobs.PushGroupSendJob) NoSuchMessageException(org.thoughtcrime.securesms.database.NoSuchMessageException) Attachment(org.thoughtcrime.securesms.attachments.Attachment) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) AttachmentCompressionJob(org.thoughtcrime.securesms.jobs.AttachmentCompressionJob) Context(android.content.Context) MmsSmsDatabase(org.thoughtcrime.securesms.database.MmsSmsDatabase) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) ProfileKeySendJob(org.thoughtcrime.securesms.jobs.ProfileKeySendJob) Stream(com.annimon.stream.Stream) DirectoryHelper(org.thoughtcrime.securesms.contacts.sync.DirectoryHelper) SignalLocalMetrics(org.thoughtcrime.securesms.util.SignalLocalMetrics) WorkerThread(androidx.annotation.WorkerThread) AttachmentDatabase(org.thoughtcrime.securesms.database.AttachmentDatabase) RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) Parcel(android.os.Parcel) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) ArrayList(java.util.ArrayList) RemoteDeleteSendJob(org.thoughtcrime.securesms.jobs.RemoteDeleteSendJob) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) MmsSendJob(org.thoughtcrime.securesms.jobs.MmsSendJob) AttachmentUploadJob(org.thoughtcrime.securesms.jobs.AttachmentUploadJob) PushTextSendJob(org.thoughtcrime.securesms.jobs.PushTextSendJob) EventBus(org.greenrobot.eventbus.EventBus) AttachmentCopyJob(org.thoughtcrime.securesms.jobs.AttachmentCopyJob) LinkedList(java.util.LinkedList) Parcelable(android.os.Parcelable) MessageId(org.thoughtcrime.securesms.database.model.MessageId) Contact(org.thoughtcrime.securesms.contactshare.Contact) MmsException(org.thoughtcrime.securesms.mms.MmsException) IOException(java.io.IOException) Optional(org.whispersystems.libsignal.util.guava.Optional) TimeUnit(java.util.concurrent.TimeUnit) AttachmentId(org.thoughtcrime.securesms.attachments.AttachmentId) SmsSendJob(org.thoughtcrime.securesms.jobs.SmsSendJob) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) Collections(java.util.Collections) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) NoSuchMessageException(org.thoughtcrime.securesms.database.NoSuchMessageException) Optional(org.whispersystems.libsignal.util.guava.Optional) LinkPreview(org.thoughtcrime.securesms.linkpreview.LinkPreview) AttachmentMarkUploadedJob(org.thoughtcrime.securesms.jobs.AttachmentMarkUploadedJob) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) Attachment(org.thoughtcrime.securesms.attachments.Attachment) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) LinkedList(java.util.LinkedList) Contact(org.thoughtcrime.securesms.contactshare.Contact) MmsException(org.thoughtcrime.securesms.mms.MmsException) MmsSmsDatabase(org.thoughtcrime.securesms.database.MmsSmsDatabase) SyncMessageId(org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId) AttachmentCompressionJob(org.thoughtcrime.securesms.jobs.AttachmentCompressionJob)

Example 34 with MessageDatabase

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

the class MessageSender method sendPushWithPreUploadedMedia.

public static long sendPushWithPreUploadedMedia(final Context context, final OutgoingMediaMessage message, final Collection<PreUploadResult> preUploadResults, final long threadId, final SmsDatabase.InsertListener insertListener) {
    Log.i(TAG, "Sending media message with pre-uploads to " + message.getRecipient().getId() + ", thread: " + threadId);
    Preconditions.checkArgument(message.getAttachments().isEmpty(), "If the media is pre-uploaded, there should be no attachments on the message.");
    try {
        ThreadDatabase threadDatabase = SignalDatabase.threads();
        MessageDatabase mmsDatabase = SignalDatabase.mms();
        AttachmentDatabase attachmentDatabase = SignalDatabase.attachments();
        long allocatedThreadId;
        if (threadId == -1) {
            allocatedThreadId = threadDatabase.getOrCreateThreadIdFor(message.getRecipient(), message.getDistributionType());
        } else {
            allocatedThreadId = threadId;
        }
        Recipient recipient = message.getRecipient();
        long messageId = mmsDatabase.insertMessageOutbox(applyUniversalExpireTimerIfNecessary(context, recipient, message, allocatedThreadId), allocatedThreadId, false, insertListener);
        List<AttachmentId> attachmentIds = Stream.of(preUploadResults).map(PreUploadResult::getAttachmentId).toList();
        List<String> jobIds = Stream.of(preUploadResults).map(PreUploadResult::getJobIds).flatMap(Stream::of).toList();
        attachmentDatabase.updateMessageId(attachmentIds, messageId);
        sendMediaMessage(context, recipient, false, messageId, jobIds);
        onMessageSent();
        threadDatabase.update(threadId, true);
        return allocatedThreadId;
    } catch (MmsException e) {
        Log.w(TAG, e);
        return threadId;
    }
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) MmsException(org.thoughtcrime.securesms.mms.MmsException) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) AttachmentDatabase(org.thoughtcrime.securesms.database.AttachmentDatabase) AttachmentId(org.thoughtcrime.securesms.attachments.AttachmentId)

Example 35 with MessageDatabase

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

the class MessageSender method sendLocalTextSelf.

private static void sendLocalTextSelf(Context context, long messageId) {
    try {
        ExpiringMessageManager expirationManager = ApplicationDependencies.getExpiringMessageManager();
        MessageDatabase smsDatabase = SignalDatabase.sms();
        MmsSmsDatabase mmsSmsDatabase = SignalDatabase.mmsSms();
        SmsMessageRecord message = smsDatabase.getSmsMessage(messageId);
        SyncMessageId syncId = new SyncMessageId(Recipient.self().getId(), message.getDateSent());
        smsDatabase.markAsSent(messageId, true);
        smsDatabase.markUnidentified(messageId, true);
        mmsSmsDatabase.incrementDeliveryReceiptCount(syncId, System.currentTimeMillis());
        mmsSmsDatabase.incrementReadReceiptCount(syncId, System.currentTimeMillis());
        if (message.getExpiresIn() > 0) {
            smsDatabase.markExpireStarted(messageId);
            expirationManager.scheduleDeletion(message.getId(), message.isMms(), message.getExpiresIn());
        }
    } catch (NoSuchMessageException e) {
        Log.w(TAG, "Failed to update self-sent message.", e);
    }
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) NoSuchMessageException(org.thoughtcrime.securesms.database.NoSuchMessageException) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) MmsSmsDatabase(org.thoughtcrime.securesms.database.MmsSmsDatabase) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager) SyncMessageId(org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId)

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