Search in sources :

Example 1 with MessagingDatabase

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

the class PushDecryptJob method handleSynchronizeSentTextMessage.

private long handleSynchronizeSentTextMessage(@NonNull SentTranscriptMessage message) throws MmsException {
    Recipient recipient = getSyncMessageDestination(message);
    String body = message.getMessage().getBody().or("");
    long expiresInMillis = message.getMessage().getExpiresInSeconds() * 1000L;
    if (recipient.getExpireMessages() != message.getMessage().getExpiresInSeconds()) {
        handleSynchronizeSentExpirationUpdate(message);
    }
    long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient);
    MessagingDatabase database;
    long messageId;
    if (recipient.getAddress().isGroup()) {
        OutgoingMediaMessage outgoingMediaMessage = new OutgoingMediaMessage(recipient, new SlideDeck(), body, message.getTimestamp(), -1, expiresInMillis, ThreadDatabase.DistributionTypes.DEFAULT);
        outgoingMediaMessage = new OutgoingSecureMediaMessage(outgoingMediaMessage);
        messageId = DatabaseFactory.getMmsDatabase(context).insertMessageOutbox(outgoingMediaMessage, threadId, false, null);
        database = DatabaseFactory.getMmsDatabase(context);
    } else {
        OutgoingTextMessage outgoingTextMessage = new OutgoingEncryptedMessage(recipient, body, expiresInMillis);
        messageId = DatabaseFactory.getSmsDatabase(context).insertMessageOutbox(threadId, outgoingTextMessage, false, message.getTimestamp(), null);
        database = DatabaseFactory.getSmsDatabase(context);
    }
    database.markAsSent(messageId, true);
    if (expiresInMillis > 0) {
        database.markExpireStarted(messageId, message.getExpirationStartTimestamp());
        ApplicationContext.getInstance(context).getExpiringMessageManager().scheduleDeletion(messageId, false, message.getExpirationStartTimestamp(), expiresInMillis);
    }
    return threadId;
}
Also used : OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) MessagingDatabase(org.thoughtcrime.securesms.database.MessagingDatabase) OutgoingSecureMediaMessage(org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage) OutgoingEncryptedMessage(org.thoughtcrime.securesms.sms.OutgoingEncryptedMessage) Recipient(org.thoughtcrime.securesms.recipients.Recipient) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck)

Aggregations

MessagingDatabase (org.thoughtcrime.securesms.database.MessagingDatabase)1 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)1 OutgoingSecureMediaMessage (org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage)1 SlideDeck (org.thoughtcrime.securesms.mms.SlideDeck)1 Recipient (org.thoughtcrime.securesms.recipients.Recipient)1 OutgoingEncryptedMessage (org.thoughtcrime.securesms.sms.OutgoingEncryptedMessage)1 OutgoingTextMessage (org.thoughtcrime.securesms.sms.OutgoingTextMessage)1