Search in sources :

Example 1 with SmsDatabase

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

the class PushDecryptJob method handleCallOfferMessage.

private void handleCallOfferMessage(@NonNull SignalServiceEnvelope envelope, @NonNull OfferMessage message, @NonNull Optional<Long> smsMessageId) {
    Log.w(TAG, "handleCallOfferMessage...");
    if (smsMessageId.isPresent()) {
        SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
        database.markAsMissedCall(smsMessageId.get());
    } else {
        Intent intent = new Intent(context, WebRtcCallService.class);
        intent.setAction(WebRtcCallService.ACTION_INCOMING_CALL);
        intent.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId());
        intent.putExtra(WebRtcCallService.EXTRA_REMOTE_NUMBER, envelope.getSource());
        intent.putExtra(WebRtcCallService.EXTRA_REMOTE_DESCRIPTION, message.getDescription());
        intent.putExtra(WebRtcCallService.EXTRA_TIMESTAMP, envelope.getTimestamp());
        context.startService(intent);
    }
}
Also used : SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) Intent(android.content.Intent)

Example 2 with SmsDatabase

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

the class IdentityUpdateJob method onRun.

@Override
public void onRun(MasterSecret masterSecret) throws Exception {
    Recipient recipient = RecipientFactory.getRecipientForId(context, recipientId, true);
    Recipients recipients = RecipientFactory.getRecipientsFor(context, recipient, true);
    String number = recipient.getNumber();
    long time = System.currentTimeMillis();
    SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context);
    ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context);
    GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context);
    GroupDatabase.Reader reader = groupDatabase.getGroups();
    GroupDatabase.GroupRecord groupRecord;
    while ((groupRecord = reader.getNext()) != null) {
        if (groupRecord.getMembers().contains(number) && groupRecord.isActive()) {
            SignalServiceGroup group = new SignalServiceGroup(groupRecord.getId());
            IncomingTextMessage incoming = new IncomingTextMessage(number, 1, time, null, Optional.of(group), 0);
            IncomingIdentityUpdateMessage groupUpdate = new IncomingIdentityUpdateMessage(incoming);
            smsDatabase.insertMessageInbox(groupUpdate);
        }
    }
    if (threadDatabase.getThreadIdIfExistsFor(recipients) != -1) {
        IncomingTextMessage incoming = new IncomingTextMessage(number, 1, time, null, Optional.<SignalServiceGroup>absent(), 0);
        IncomingIdentityUpdateMessage individualUpdate = new IncomingIdentityUpdateMessage(incoming);
        smsDatabase.insertMessageInbox(individualUpdate);
    }
}
Also used : IncomingIdentityUpdateMessage(org.thoughtcrime.securesms.sms.IncomingIdentityUpdateMessage) Recipients(org.thoughtcrime.securesms.recipients.Recipients) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) Recipient(org.thoughtcrime.securesms.recipients.Recipient) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) SignalServiceGroup(org.whispersystems.signalservice.api.messages.SignalServiceGroup)

Example 3 with SmsDatabase

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

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

the class ConversationItem method handleMessageApproval.

private void handleMessageApproval() {
    final int title;
    final int message;
    if (messageRecord.isMms())
        title = R.string.ConversationItem_click_to_approve_unencrypted_mms_dialog_title;
    else
        title = R.string.ConversationItem_click_to_approve_unencrypted_sms_dialog_title;
    message = R.string.ConversationItem_click_to_approve_unencrypted_dialog_message;
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(title);
    if (message > -1)
        builder.setMessage(message);
    builder.setPositiveButton(R.string.yes, (dialogInterface, i) -> {
        if (messageRecord.isMms()) {
            MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
            database.markAsInsecure(messageRecord.getId());
            database.markAsOutbox(messageRecord.getId());
            database.markAsForcedSms(messageRecord.getId());
            ApplicationContext.getInstance(context).getJobManager().add(new MmsSendJob(context, messageRecord.getId()));
        } else {
            SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
            database.markAsInsecure(messageRecord.getId());
            database.markAsOutbox(messageRecord.getId());
            database.markAsForcedSms(messageRecord.getId());
            ApplicationContext.getInstance(context).getJobManager().add(new SmsSendJob(context, messageRecord.getId(), messageRecord.getIndividualRecipient().getAddress().serialize()));
        }
    });
    builder.setNegativeButton(R.string.no, (dialogInterface, i) -> {
        if (messageRecord.isMms()) {
            DatabaseFactory.getMmsDatabase(context).markAsSentFailed(messageRecord.getId());
        } else {
            DatabaseFactory.getSmsDatabase(context).markAsSentFailed(messageRecord.getId());
        }
    });
    builder.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) MmsSmsDatabase(org.thoughtcrime.securesms.database.MmsSmsDatabase) SmsSendJob(org.thoughtcrime.securesms.jobs.SmsSendJob) SuppressLint(android.annotation.SuppressLint) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase) MmsSendJob(org.thoughtcrime.securesms.jobs.MmsSendJob)

Example 5 with SmsDatabase

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

the class PushDecryptJob method handleCorruptMessage.

private void handleCorruptMessage(@NonNull SignalServiceEnvelope envelope, @NonNull Optional<Long> smsMessageId) {
    SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context);
    if (!smsMessageId.isPresent()) {
        Optional<InsertResult> insertResult = insertPlaceholder(envelope);
        if (insertResult.isPresent()) {
            smsDatabase.markAsDecryptFailed(insertResult.get().getMessageId());
            MessageNotifier.updateNotification(context, insertResult.get().getThreadId());
        }
    } else {
        smsDatabase.markAsDecryptFailed(smsMessageId.get());
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase)

Aggregations

SmsDatabase (org.thoughtcrime.securesms.database.SmsDatabase)23 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)9 IncomingTextMessage (org.thoughtcrime.securesms.sms.IncomingTextMessage)7 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)5 Recipient (org.thoughtcrime.securesms.recipients.Recipient)5 SmsMessageRecord (org.thoughtcrime.securesms.database.model.SmsMessageRecord)4 Nullable (android.support.annotation.Nullable)3 EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)3 MmsSmsDatabase (org.thoughtcrime.securesms.database.MmsSmsDatabase)3 Intent (android.content.Intent)2 TextSecureSessionStore (org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore)2 Address (org.thoughtcrime.securesms.database.Address)2 ExpiringMessageManager (org.thoughtcrime.securesms.service.ExpiringMessageManager)2 IncomingEncryptedMessage (org.thoughtcrime.securesms.sms.IncomingEncryptedMessage)2 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)2 SessionStore (org.whispersystems.libsignal.state.SessionStore)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 AlertDialog (android.support.v7.app.AlertDialog)1 ByteString (com.google.protobuf.ByteString)1