Search in sources :

Example 16 with ExpiringMessageManager

use of org.thoughtcrime.securesms.service.ExpiringMessageManager in project Signal-Android by signalapp.

the class MessageSender method sendMediaSelf.

private static void sendMediaSelf(Context context, long messageId, long expiresIn) throws MmsException {
    ExpiringMessageManager expiringMessageManager = ApplicationContext.getInstance(context).getExpiringMessageManager();
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    database.markAsSent(messageId, true);
    database.copyMessageInbox(messageId);
    if (expiresIn > 0) {
        database.markExpireStarted(messageId);
        expiringMessageManager.scheduleDeletion(messageId, true, expiresIn);
    }
}
Also used : ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 17 with ExpiringMessageManager

use of org.thoughtcrime.securesms.service.ExpiringMessageManager in project Signal-Android by WhisperSystems.

the class MarkReadReceiver method scheduleDeletion.

private static void scheduleDeletion(@NonNull Context context, @NonNull List<ExpirationInfo> smsExpirationInfo, @NonNull List<ExpirationInfo> mmsExpirationInfo) {
    if (smsExpirationInfo.size() > 0) {
        SignalDatabase.sms().markExpireStarted(Stream.of(smsExpirationInfo).map(ExpirationInfo::getId).toList(), System.currentTimeMillis());
    }
    if (mmsExpirationInfo.size() > 0) {
        SignalDatabase.mms().markExpireStarted(Stream.of(mmsExpirationInfo).map(ExpirationInfo::getId).toList(), System.currentTimeMillis());
    }
    if (smsExpirationInfo.size() + mmsExpirationInfo.size() > 0) {
        ExpiringMessageManager expirationManager = ApplicationDependencies.getExpiringMessageManager();
        Stream.concat(Stream.of(smsExpirationInfo), Stream.of(mmsExpirationInfo)).forEach(info -> expirationManager.scheduleDeletion(info.getId(), info.isMms(), info.getExpiresIn()));
    }
}
Also used : ExpirationInfo(org.thoughtcrime.securesms.database.MessageDatabase.ExpirationInfo) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager)

Example 18 with ExpiringMessageManager

use of org.thoughtcrime.securesms.service.ExpiringMessageManager in project Signal-Android by signalapp.

the class MarkReadReceiver method scheduleDeletion.

private static void scheduleDeletion(@NonNull Context context, @NonNull List<ExpirationInfo> smsExpirationInfo, @NonNull List<ExpirationInfo> mmsExpirationInfo) {
    if (smsExpirationInfo.size() > 0) {
        SignalDatabase.sms().markExpireStarted(Stream.of(smsExpirationInfo).map(ExpirationInfo::getId).toList(), System.currentTimeMillis());
    }
    if (mmsExpirationInfo.size() > 0) {
        SignalDatabase.mms().markExpireStarted(Stream.of(mmsExpirationInfo).map(ExpirationInfo::getId).toList(), System.currentTimeMillis());
    }
    if (smsExpirationInfo.size() + mmsExpirationInfo.size() > 0) {
        ExpiringMessageManager expirationManager = ApplicationDependencies.getExpiringMessageManager();
        Stream.concat(Stream.of(smsExpirationInfo), Stream.of(mmsExpirationInfo)).forEach(info -> expirationManager.scheduleDeletion(info.getId(), info.isMms(), info.getExpiresIn()));
    }
}
Also used : ExpirationInfo(org.thoughtcrime.securesms.database.MessageDatabase.ExpirationInfo) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager)

Example 19 with ExpiringMessageManager

use of org.thoughtcrime.securesms.service.ExpiringMessageManager in project Signal-Android by signalapp.

the class PushMediaSendJob method onPushSend.

@Override
public void onPushSend() throws IOException, MmsException, NoSuchMessageException, UndeliverableMessageException, RetryLaterException {
    ExpiringMessageManager expirationManager = ApplicationDependencies.getExpiringMessageManager();
    MessageDatabase database = SignalDatabase.mms();
    OutgoingMediaMessage message = database.getOutgoingMessage(messageId);
    long threadId = database.getMessageRecord(messageId).getThreadId();
    if (database.isSent(messageId)) {
        warn(TAG, String.valueOf(message.getSentTimeMillis()), "Message " + messageId + " was already sent. Ignoring.");
        return;
    }
    try {
        log(TAG, String.valueOf(message.getSentTimeMillis()), "Sending message: " + messageId + ", Recipient: " + message.getRecipient().getId() + ", Thread: " + threadId + ", Attachments: " + buildAttachmentString(message.getAttachments()));
        RecipientUtil.shareProfileIfFirstSecureMessage(context, message.getRecipient());
        Recipient recipient = message.getRecipient().fresh();
        byte[] profileKey = recipient.getProfileKey();
        UnidentifiedAccessMode accessMode = recipient.getUnidentifiedAccessMode();
        boolean unidentified = deliver(message);
        database.markAsSent(messageId, true);
        markAttachmentsUploaded(messageId, message);
        database.markUnidentified(messageId, unidentified);
        if (recipient.isSelf()) {
            SyncMessageId id = new SyncMessageId(recipient.getId(), message.getSentTimeMillis());
            SignalDatabase.mmsSms().incrementDeliveryReceiptCount(id, System.currentTimeMillis());
            SignalDatabase.mmsSms().incrementReadReceiptCount(id, System.currentTimeMillis());
            SignalDatabase.mmsSms().incrementViewedReceiptCount(id, System.currentTimeMillis());
        }
        if (unidentified && accessMode == UnidentifiedAccessMode.UNKNOWN && profileKey == null) {
            log(TAG, String.valueOf(message.getSentTimeMillis()), "Marking recipient as UD-unrestricted following a UD send.");
            SignalDatabase.recipients().setUnidentifiedAccessMode(recipient.getId(), UnidentifiedAccessMode.UNRESTRICTED);
        } else if (unidentified && accessMode == UnidentifiedAccessMode.UNKNOWN) {
            log(TAG, String.valueOf(message.getSentTimeMillis()), "Marking recipient as UD-enabled following a UD send.");
            SignalDatabase.recipients().setUnidentifiedAccessMode(recipient.getId(), UnidentifiedAccessMode.ENABLED);
        } else if (!unidentified && accessMode != UnidentifiedAccessMode.DISABLED) {
            log(TAG, String.valueOf(message.getSentTimeMillis()), "Marking recipient as UD-disabled following a non-UD send.");
            SignalDatabase.recipients().setUnidentifiedAccessMode(recipient.getId(), UnidentifiedAccessMode.DISABLED);
        }
        if (message.getExpiresIn() > 0 && !message.isExpirationUpdate()) {
            database.markExpireStarted(messageId);
            expirationManager.scheduleDeletion(messageId, true, message.getExpiresIn());
        }
        if (message.isViewOnce()) {
            SignalDatabase.attachments().deleteAttachmentFilesForViewOnceMessage(messageId);
        }
        log(TAG, String.valueOf(message.getSentTimeMillis()), "Sent message: " + messageId);
    } catch (InsecureFallbackApprovalException ifae) {
        warn(TAG, "Failure", ifae);
        database.markAsPendingInsecureSmsFallback(messageId);
        notifyMediaMessageDeliveryFailed(context, messageId);
        ApplicationDependencies.getJobManager().add(new DirectoryRefreshJob(false));
    } catch (UntrustedIdentityException uie) {
        warn(TAG, "Failure", uie);
        RecipientId recipientId = Recipient.external(context, uie.getIdentifier()).getId();
        database.addMismatchedIdentity(messageId, recipientId, uie.getIdentityKey());
        database.markAsSentFailed(messageId);
        RetrieveProfileJob.enqueue(recipientId);
    } catch (ProofRequiredException e) {
        handleProofRequiredException(e, SignalDatabase.threads().getRecipientForThreadId(threadId), threadId, messageId, true);
    }
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ProofRequiredException(org.whispersystems.signalservice.api.push.exceptions.ProofRequiredException) UnidentifiedAccessMode(org.thoughtcrime.securesms.database.RecipientDatabase.UnidentifiedAccessMode) InsecureFallbackApprovalException(org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException) SyncMessageId(org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId)

Example 20 with ExpiringMessageManager

use of org.thoughtcrime.securesms.service.ExpiringMessageManager in project Signal-Android by signalapp.

the class PushTextSendJob method onPushSend.

@Override
public void onPushSend() throws IOException, NoSuchMessageException, UndeliverableMessageException, RetryLaterException {
    SignalLocalMetrics.IndividualMessageSend.onJobStarted(messageId);
    ExpiringMessageManager expirationManager = ApplicationDependencies.getExpiringMessageManager();
    MessageDatabase database = SignalDatabase.sms();
    SmsMessageRecord record = database.getSmsMessage(messageId);
    if (!record.isPending() && !record.isFailed()) {
        warn(TAG, String.valueOf(record.getDateSent()), "Message " + messageId + " was already sent. Ignoring.");
        return;
    }
    try {
        log(TAG, String.valueOf(record.getDateSent()), "Sending message: " + messageId + ",  Recipient: " + record.getRecipient().getId() + ", Thread: " + record.getThreadId());
        RecipientUtil.shareProfileIfFirstSecureMessage(context, record.getRecipient());
        Recipient recipient = record.getRecipient().resolve();
        byte[] profileKey = recipient.getProfileKey();
        UnidentifiedAccessMode accessMode = recipient.getUnidentifiedAccessMode();
        boolean unidentified = deliver(record);
        database.markAsSent(messageId, true);
        database.markUnidentified(messageId, unidentified);
        if (recipient.isSelf()) {
            SyncMessageId id = new SyncMessageId(recipient.getId(), record.getDateSent());
            SignalDatabase.mmsSms().incrementDeliveryReceiptCount(id, System.currentTimeMillis());
            SignalDatabase.mmsSms().incrementReadReceiptCount(id, System.currentTimeMillis());
        }
        if (unidentified && accessMode == UnidentifiedAccessMode.UNKNOWN && profileKey == null) {
            log(TAG, String.valueOf(record.getDateSent()), "Marking recipient as UD-unrestricted following a UD send.");
            SignalDatabase.recipients().setUnidentifiedAccessMode(recipient.getId(), UnidentifiedAccessMode.UNRESTRICTED);
        } else if (unidentified && accessMode == UnidentifiedAccessMode.UNKNOWN) {
            log(TAG, String.valueOf(record.getDateSent()), "Marking recipient as UD-enabled following a UD send.");
            SignalDatabase.recipients().setUnidentifiedAccessMode(recipient.getId(), UnidentifiedAccessMode.ENABLED);
        } else if (!unidentified && accessMode != UnidentifiedAccessMode.DISABLED) {
            log(TAG, String.valueOf(record.getDateSent()), "Marking recipient as UD-disabled following a non-UD send.");
            SignalDatabase.recipients().setUnidentifiedAccessMode(recipient.getId(), UnidentifiedAccessMode.DISABLED);
        }
        if (record.getExpiresIn() > 0) {
            database.markExpireStarted(messageId);
            expirationManager.scheduleDeletion(record.getId(), record.isMms(), record.getExpiresIn());
        }
        log(TAG, String.valueOf(record.getDateSent()), "Sent message: " + messageId);
    } catch (InsecureFallbackApprovalException e) {
        warn(TAG, String.valueOf(record.getDateSent()), "Failure", e);
        database.markAsPendingInsecureSmsFallback(record.getId());
        ApplicationDependencies.getMessageNotifier().notifyMessageDeliveryFailed(context, record.getRecipient(), record.getThreadId());
        ApplicationDependencies.getJobManager().add(new DirectoryRefreshJob(false));
    } catch (UntrustedIdentityException e) {
        warn(TAG, String.valueOf(record.getDateSent()), "Failure", e);
        RecipientId recipientId = Recipient.external(context, e.getIdentifier()).getId();
        database.addMismatchedIdentity(record.getId(), recipientId, e.getIdentityKey());
        database.markAsSentFailed(record.getId());
        database.markAsPush(record.getId());
        RetrieveProfileJob.enqueue(recipientId);
    } catch (ProofRequiredException e) {
        handleProofRequiredException(e, record.getRecipient(), record.getThreadId(), messageId, false);
    }
    SignalLocalMetrics.IndividualMessageSend.onJobFinished(messageId);
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ProofRequiredException(org.whispersystems.signalservice.api.push.exceptions.ProofRequiredException) UnidentifiedAccessMode(org.thoughtcrime.securesms.database.RecipientDatabase.UnidentifiedAccessMode) InsecureFallbackApprovalException(org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException) SyncMessageId(org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId)

Aggregations

ExpiringMessageManager (org.thoughtcrime.securesms.service.ExpiringMessageManager)20 MessageDatabase (org.thoughtcrime.securesms.database.MessageDatabase)8 SyncMessageId (org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId)8 SmsMessageRecord (org.thoughtcrime.securesms.database.model.SmsMessageRecord)7 Recipient (org.thoughtcrime.securesms.recipients.Recipient)6 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)6 InsecureFallbackApprovalException (org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)6 UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)6 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)5 MmsSmsDatabase (org.thoughtcrime.securesms.database.MmsSmsDatabase)4 NoSuchMessageException (org.thoughtcrime.securesms.database.NoSuchMessageException)4 UnidentifiedAccessMode (org.thoughtcrime.securesms.database.RecipientDatabase.UnidentifiedAccessMode)4 SmsDatabase (org.thoughtcrime.securesms.database.SmsDatabase)3 Context (android.content.Context)2 Parcel (android.os.Parcel)2 Parcelable (android.os.Parcelable)2 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 WorkerThread (androidx.annotation.WorkerThread)2 Stream (com.annimon.stream.Stream)2