Search in sources :

Example 6 with TrimThreadJob

use of org.thoughtcrime.securesms.jobs.TrimThreadJob in project Signal-Android by WhisperSystems.

the class MmsDatabase method insertMessageOutbox.

public long insertMessageOutbox(@NonNull MasterSecretUnion masterSecret, @NonNull OutgoingMediaMessage message, long threadId, boolean forceSms) throws MmsException {
    long type = Types.BASE_SENDING_TYPE;
    if (masterSecret.getMasterSecret().isPresent())
        type |= Types.ENCRYPTION_SYMMETRIC_BIT;
    else
        type |= Types.ENCRYPTION_ASYMMETRIC_BIT;
    if (message.isSecure())
        type |= (Types.SECURE_MESSAGE_BIT | Types.PUSH_MESSAGE_BIT);
    if (forceSms)
        type |= Types.MESSAGE_FORCE_SMS_BIT;
    if (message.isGroup()) {
        if (((OutgoingGroupMediaMessage) message).isGroupUpdate())
            type |= Types.GROUP_UPDATE_BIT;
        else if (((OutgoingGroupMediaMessage) message).isGroupQuit())
            type |= Types.GROUP_QUIT_BIT;
    }
    if (message.isExpirationUpdate()) {
        type |= Types.EXPIRATION_TIMER_UPDATE_BIT;
    }
    List<String> recipientNumbers = message.getRecipients().toNumberStringList(true);
    MmsAddresses addresses;
    if (!message.getRecipients().isSingleRecipient() && message.getDistributionType() == ThreadDatabase.DistributionTypes.BROADCAST) {
        addresses = MmsAddresses.forBcc(recipientNumbers);
    } else {
        addresses = MmsAddresses.forTo(recipientNumbers);
    }
    ContentValues contentValues = new ContentValues();
    contentValues.put(DATE_SENT, message.getSentTimeMillis());
    contentValues.put(MESSAGE_TYPE, PduHeaders.MESSAGE_TYPE_SEND_REQ);
    contentValues.put(MESSAGE_BOX, type);
    contentValues.put(THREAD_ID, threadId);
    contentValues.put(READ, 1);
    contentValues.put(DATE_RECEIVED, System.currentTimeMillis());
    contentValues.put(SUBSCRIPTION_ID, message.getSubscriptionId());
    contentValues.put(EXPIRES_IN, message.getExpiresIn());
    if (message.getRecipients().isSingleRecipient()) {
        try {
            contentValues.put(RECEIPT_COUNT, earlyReceiptCache.remove(message.getSentTimeMillis(), canonicalizeNumber(context, message.getRecipients().getPrimaryRecipient().getNumber())));
        } catch (InvalidNumberException e) {
            Log.w(TAG, e);
        }
    }
    contentValues.remove(ADDRESS);
    long messageId = insertMediaMessage(masterSecret, addresses, message.getBody(), message.getAttachments(), contentValues);
    DatabaseFactory.getThreadDatabase(context).setLastSeen(threadId);
    jobManager.add(new TrimThreadJob(context, threadId));
    return messageId;
}
Also used : ContentValues(android.content.ContentValues) TrimThreadJob(org.thoughtcrime.securesms.jobs.TrimThreadJob) OutgoingGroupMediaMessage(org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException)

Example 7 with TrimThreadJob

use of org.thoughtcrime.securesms.jobs.TrimThreadJob in project Signal-Android by WhisperSystems.

the class MmsDatabase method markIncomingNotificationReceived.

public void markIncomingNotificationReceived(long threadId) {
    notifyConversationListeners(threadId);
    DatabaseFactory.getThreadDatabase(context).update(threadId, true);
    if (org.thoughtcrime.securesms.util.Util.isDefaultSmsProvider(context)) {
        DatabaseFactory.getThreadDatabase(context).setUnread(threadId);
    }
    jobManager.add(new TrimThreadJob(context, threadId));
}
Also used : TrimThreadJob(org.thoughtcrime.securesms.jobs.TrimThreadJob)

Aggregations

TrimThreadJob (org.thoughtcrime.securesms.jobs.TrimThreadJob)7 ContentValues (android.content.ContentValues)6 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)4 Pair (android.util.Pair)2 Recipients (org.thoughtcrime.securesms.recipients.Recipients)2 InvalidNumberException (org.whispersystems.signalservice.api.util.InvalidNumberException)2 NonNull (android.support.annotation.NonNull)1 SmsMessageRecord (org.thoughtcrime.securesms.database.model.SmsMessageRecord)1 OutgoingGroupMediaMessage (org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage)1 RecipientFormattingException (org.thoughtcrime.securesms.recipients.RecipientFormattingException)1 IncomingGroupMessage (org.thoughtcrime.securesms.sms.IncomingGroupMessage)1 MmsException (ws.com.google.android.mms.MmsException)1