Search in sources :

Example 71 with MessageDatabase

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

the class MessageContentProcessor method handleRemoteDelete.

@Nullable
private MessageId handleRemoteDelete(@NonNull SignalServiceContent content, @NonNull SignalServiceDataMessage message, @NonNull Recipient senderRecipient) {
    log(content.getTimestamp(), "Remote delete for message " + message.getRemoteDelete().get().getTargetSentTimestamp());
    SignalServiceDataMessage.RemoteDelete delete = message.getRemoteDelete().get();
    MessageRecord targetMessage = SignalDatabase.mmsSms().getMessageFor(delete.getTargetSentTimestamp(), senderRecipient.getId());
    if (targetMessage != null && RemoteDeleteUtil.isValidReceive(targetMessage, senderRecipient, content.getServerReceivedTimestamp())) {
        MessageDatabase db = targetMessage.isMms() ? SignalDatabase.mms() : SignalDatabase.sms();
        db.markAsRemoteDelete(targetMessage.getId());
        ApplicationDependencies.getMessageNotifier().updateNotification(context, targetMessage.getThreadId(), false);
        return new MessageId(targetMessage.getId(), targetMessage.isMms());
    } else if (targetMessage == null) {
        warn(String.valueOf(content.getTimestamp()), "[handleRemoteDelete] Could not find matching message! timestamp: " + delete.getTargetSentTimestamp() + "  author: " + senderRecipient.getId());
        ApplicationDependencies.getEarlyMessageCache().store(senderRecipient.getId(), delete.getTargetSentTimestamp(), content);
        return null;
    } else {
        warn(String.valueOf(content.getTimestamp()), String.format(Locale.ENGLISH, "[handleRemoteDelete] Invalid remote delete! deleteTime: %d, targetTime: %d, deleteAuthor: %s, targetAuthor: %s", content.getServerReceivedTimestamp(), targetMessage.getServerTimestamp(), senderRecipient.getId(), targetMessage.getRecipient().getId()));
        return null;
    }
}
Also used : SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) MessageId(org.thoughtcrime.securesms.database.model.MessageId) SyncMessageId(org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId) Nullable(androidx.annotation.Nullable)

Example 72 with MessageDatabase

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

the class MessageContentProcessor method handleLegacyMessage.

private void handleLegacyMessage(@NonNull String sender, int senderDevice, long timestamp, @NonNull Optional<Long> smsMessageId) {
    log(timestamp, "Legacy message.");
    MessageDatabase smsDatabase = SignalDatabase.sms();
    if (!smsMessageId.isPresent()) {
        Optional<InsertResult> insertResult = insertPlaceholder(sender, senderDevice, timestamp);
        if (insertResult.isPresent()) {
            smsDatabase.markAsLegacyVersion(insertResult.get().getMessageId());
            ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId());
        }
    } else {
        smsDatabase.markAsLegacyVersion(smsMessageId.get());
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessageDatabase.InsertResult) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase)

Example 73 with MessageDatabase

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

the class MessageContentProcessor method insertPlaceholder.

private Optional<InsertResult> insertPlaceholder(@NonNull String sender, int senderDevice, long timestamp, Optional<GroupId> groupId) {
    MessageDatabase database = SignalDatabase.sms();
    IncomingTextMessage textMessage = new IncomingTextMessage(Recipient.external(context, sender).getId(), senderDevice, timestamp, -1, System.currentTimeMillis(), "", groupId, 0, false, null);
    textMessage = new IncomingEncryptedMessage(textMessage, "");
    return database.insertMessageInbox(textMessage);
}
Also used : IncomingEncryptedMessage(org.thoughtcrime.securesms.sms.IncomingEncryptedMessage) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage)

Example 74 with MessageDatabase

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

the class IdentityUtil method markIdentityUpdate.

public static void markIdentityUpdate(@NonNull Context context, @NonNull RecipientId recipientId) {
    long time = System.currentTimeMillis();
    MessageDatabase smsDatabase = SignalDatabase.sms();
    GroupDatabase groupDatabase = SignalDatabase.groups();
    try (GroupDatabase.Reader reader = groupDatabase.getGroups()) {
        GroupDatabase.GroupRecord groupRecord;
        while ((groupRecord = reader.getNext()) != null) {
            if (groupRecord.getMembers().contains(recipientId) && groupRecord.isActive()) {
                IncomingTextMessage incoming = new IncomingTextMessage(recipientId, 1, time, time, time, null, Optional.of(groupRecord.getId()), 0, false, null);
                IncomingIdentityUpdateMessage groupUpdate = new IncomingIdentityUpdateMessage(incoming);
                smsDatabase.insertMessageInbox(groupUpdate);
            }
        }
    }
    IncomingTextMessage incoming = new IncomingTextMessage(recipientId, 1, time, -1, time, null, Optional.absent(), 0, false, null);
    IncomingIdentityUpdateMessage individualUpdate = new IncomingIdentityUpdateMessage(incoming);
    Optional<InsertResult> insertResult = smsDatabase.insertMessageInbox(individualUpdate);
    if (insertResult.isPresent()) {
        ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId());
    }
}
Also used : IncomingIdentityUpdateMessage(org.thoughtcrime.securesms.sms.IncomingIdentityUpdateMessage) InsertResult(org.thoughtcrime.securesms.database.MessageDatabase.InsertResult) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase)

Example 75 with MessageDatabase

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

the class SmsSendJob method onSend.

@Override
public void onSend() throws NoSuchMessageException, TooManyRetriesException, UndeliverableMessageException {
    if (runAttempt >= MAX_ATTEMPTS) {
        warn(TAG, "Hit the retry limit. Failing.");
        throw new TooManyRetriesException();
    }
    MessageDatabase database = SignalDatabase.sms();
    SmsMessageRecord record = database.getSmsMessage(messageId);
    if (!record.isPending() && !record.isFailed()) {
        warn(TAG, "Message " + messageId + " was already sent. Ignoring.");
        return;
    }
    if (!record.getRecipient().hasSmsAddress()) {
        throw new UndeliverableMessageException("Recipient didn't have an SMS address! " + record.getRecipient().getId());
    }
    try {
        log(TAG, String.valueOf(record.getDateSent()), "Sending message: " + messageId + " (attempt " + runAttempt + ")");
        deliver(record);
        log(TAG, String.valueOf(record.getDateSent()), "Sent message: " + messageId);
    } catch (UndeliverableMessageException ude) {
        warn(TAG, ude);
        SignalDatabase.sms().markAsSentFailed(record.getId());
        ApplicationDependencies.getMessageNotifier().notifyMessageDeliveryFailed(context, record.getRecipient(), record.getThreadId());
    }
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException)

Aggregations

MessageDatabase (org.thoughtcrime.securesms.database.MessageDatabase)94 Recipient (org.thoughtcrime.securesms.recipients.Recipient)36 InsertResult (org.thoughtcrime.securesms.database.MessageDatabase.InsertResult)28 SyncMessageId (org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId)26 MmsException (org.thoughtcrime.securesms.mms.MmsException)26 Nullable (androidx.annotation.Nullable)22 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)22 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)22 MessageId (org.thoughtcrime.securesms.database.model.MessageId)20 NoSuchMessageException (org.thoughtcrime.securesms.database.NoSuchMessageException)18 Attachment (org.thoughtcrime.securesms.attachments.Attachment)16 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)16 IncomingTextMessage (org.thoughtcrime.securesms.sms.IncomingTextMessage)16 WorkerThread (androidx.annotation.WorkerThread)14 IOException (java.io.IOException)14 List (java.util.List)14 MessageRecord (org.thoughtcrime.securesms.database.model.MessageRecord)14 SmsMessageRecord (org.thoughtcrime.securesms.database.model.SmsMessageRecord)14 ArrayList (java.util.ArrayList)12 LinkedList (java.util.LinkedList)12