Search in sources :

Example 1 with ExpiringMessageManager

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

the class PushMediaSendJob method onPushSend.

@Override
public void onPushSend(MasterSecret masterSecret) throws RetryLaterException, MmsException, NoSuchMessageException, UndeliverableMessageException {
    ExpiringMessageManager expirationManager = ApplicationContext.getInstance(context).getExpiringMessageManager();
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    OutgoingMediaMessage message = database.getOutgoingMessage(masterSecret, messageId);
    try {
        deliver(masterSecret, message);
        database.markAsSent(messageId, true);
        markAttachmentsUploaded(messageId, message.getAttachments());
        if (message.getExpiresIn() > 0 && !message.isExpirationUpdate()) {
            database.markExpireStarted(messageId);
            expirationManager.scheduleDeletion(messageId, true, message.getExpiresIn());
        }
    } catch (InsecureFallbackApprovalException ifae) {
        Log.w(TAG, ifae);
        database.markAsPendingInsecureSmsFallback(messageId);
        notifyMediaMessageDeliveryFailed(context, messageId);
        ApplicationContext.getInstance(context).getJobManager().add(new DirectoryRefreshJob(context));
    } catch (UntrustedIdentityException uie) {
        Log.w(TAG, uie);
        Recipients recipients = RecipientFactory.getRecipientsFromString(context, uie.getE164Number(), false);
        long recipientId = recipients.getPrimaryRecipient().getRecipientId();
        database.addMismatchedIdentity(messageId, recipientId, uie.getIdentityKey());
        database.markAsSentFailed(messageId);
    }
}
Also used : UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) Recipients(org.thoughtcrime.securesms.recipients.Recipients) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) InsecureFallbackApprovalException(org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 2 with ExpiringMessageManager

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

the class PushTextSendJob method onPushSend.

@Override
public void onPushSend(MasterSecret masterSecret) throws NoSuchMessageException, RetryLaterException {
    ExpiringMessageManager expirationManager = ApplicationContext.getInstance(context).getExpiringMessageManager();
    EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
    SmsMessageRecord record = database.getMessage(masterSecret, messageId);
    try {
        Log.w(TAG, "Sending message: " + messageId);
        deliver(record);
        database.markAsSent(messageId, true);
        if (record.getExpiresIn() > 0) {
            database.markExpireStarted(messageId);
            expirationManager.scheduleDeletion(record.getId(), record.isMms(), record.getExpiresIn());
        }
    } catch (InsecureFallbackApprovalException e) {
        Log.w(TAG, e);
        database.markAsPendingInsecureSmsFallback(record.getId());
        MessageNotifier.notifyMessageDeliveryFailed(context, record.getRecipients(), record.getThreadId());
        ApplicationContext.getInstance(context).getJobManager().add(new DirectoryRefreshJob(context));
    } catch (UntrustedIdentityException e) {
        Log.w(TAG, e);
        Recipients recipients = RecipientFactory.getRecipientsFromString(context, e.getE164Number(), false);
        long recipientId = recipients.getPrimaryRecipient().getRecipientId();
        database.addMismatchedIdentity(record.getId(), recipientId, e.getIdentityKey());
        database.markAsSentFailed(record.getId());
        database.markAsPush(record.getId());
    }
}
Also used : UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) Recipients(org.thoughtcrime.securesms.recipients.Recipients) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager) InsecureFallbackApprovalException(org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)

Example 3 with ExpiringMessageManager

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

the class MarkReadReceiver method scheduleDeletion.

private static void scheduleDeletion(Context context, ExpirationInfo expirationInfo) {
    if (expirationInfo.getExpiresIn() > 0 && expirationInfo.getExpireStarted() <= 0) {
        ExpiringMessageManager expirationManager = ApplicationContext.getInstance(context).getExpiringMessageManager();
        if (expirationInfo.isMms())
            DatabaseFactory.getMmsDatabase(context).markExpireStarted(expirationInfo.getId());
        else
            DatabaseFactory.getSmsDatabase(context).markExpireStarted(expirationInfo.getId());
        expirationManager.scheduleDeletion(expirationInfo.getId(), expirationInfo.isMms(), expirationInfo.getExpiresIn());
    }
}
Also used : ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager)

Example 4 with ExpiringMessageManager

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

the class MessageSender method sendTextSelf.

private static void sendTextSelf(Context context, long messageId, long expiresIn) {
    SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
    database.markAsSent(messageId, true);
    Pair<Long, Long> messageAndThreadId = database.copyMessageInbox(messageId);
    database.markAsPush(messageAndThreadId.first);
    if (expiresIn > 0) {
        ExpiringMessageManager expiringMessageManager = ApplicationContext.getInstance(context).getExpiringMessageManager();
        database.markExpireStarted(messageId);
        expiringMessageManager.scheduleDeletion(messageId, false, expiresIn);
    }
}
Also used : SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager)

Example 5 with ExpiringMessageManager

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

the class ConversationItem method setExpiration.

@SuppressLint("StaticFieldLeak")
private void setExpiration(final MessageRecord messageRecord) {
    if (messageRecord.getExpiresIn() > 0) {
        this.expirationTimer.setVisibility(View.VISIBLE);
        this.expirationTimer.setPercentage(0);
        if (messageRecord.getExpireStarted() > 0) {
            this.expirationTimer.setExpirationTime(messageRecord.getExpireStarted(), messageRecord.getExpiresIn());
            this.expirationTimer.startAnimation();
        } else if (!messageRecord.isOutgoing() && !messageRecord.isMediaPending()) {
            new AsyncTask<Void, Void, Void>() {

                @Override
                protected Void doInBackground(Void... params) {
                    ExpiringMessageManager expirationManager = ApplicationContext.getInstance(context).getExpiringMessageManager();
                    long id = messageRecord.getId();
                    boolean mms = messageRecord.isMms();
                    if (mms)
                        DatabaseFactory.getMmsDatabase(context).markExpireStarted(id);
                    else
                        DatabaseFactory.getSmsDatabase(context).markExpireStarted(id);
                    expirationManager.scheduleDeletion(id, mms, messageRecord.getExpiresIn());
                    return null;
                }
            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    } else {
        this.expirationTimer.setVisibility(View.GONE);
    }
}
Also used : AsyncTask(android.os.AsyncTask) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager) SuppressLint(android.annotation.SuppressLint)

Aggregations

ExpiringMessageManager (org.thoughtcrime.securesms.service.ExpiringMessageManager)12 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)4 InsecureFallbackApprovalException (org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)4 UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)4 AsyncTask (android.os.AsyncTask)2 EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)2 SmsDatabase (org.thoughtcrime.securesms.database.SmsDatabase)2 SmsMessageRecord (org.thoughtcrime.securesms.database.model.SmsMessageRecord)2 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)2 Recipients (org.thoughtcrime.securesms.recipients.Recipients)2 SuppressLint (android.annotation.SuppressLint)1