Search in sources :

Example 56 with MessageId

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

the class MmsDatabase method markAsRateLimited.

@Override
public void markAsRateLimited(long messageId) {
    long threadId = getThreadIdForMessage(messageId);
    updateMailboxBitmask(messageId, 0, Types.MESSAGE_RATE_LIMITED_BIT, Optional.of(threadId));
    ApplicationDependencies.getDatabaseObserver().notifyMessageUpdateObservers(new MessageId(messageId, true));
}
Also used : MessageId(org.thoughtcrime.securesms.database.model.MessageId)

Example 57 with MessageId

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

the class MmsDatabase method markAsSent.

@Override
public void markAsSent(long messageId, boolean secure) {
    long threadId = getThreadIdForMessage(messageId);
    updateMailboxBitmask(messageId, Types.BASE_TYPE_MASK, Types.BASE_SENT_TYPE | (secure ? Types.PUSH_MESSAGE_BIT | Types.SECURE_MESSAGE_BIT : 0), Optional.of(threadId));
    ApplicationDependencies.getDatabaseObserver().notifyMessageUpdateObservers(new MessageId(messageId, true));
    ApplicationDependencies.getDatabaseObserver().notifyConversationListListeners();
}
Also used : MessageId(org.thoughtcrime.securesms.database.model.MessageId)

Example 58 with MessageId

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

the class MmsDatabase method markAsSentFailed.

@Override
public void markAsSentFailed(long messageId) {
    long threadId = getThreadIdForMessage(messageId);
    updateMailboxBitmask(messageId, Types.BASE_TYPE_MASK, Types.BASE_SENT_FAILED_TYPE, Optional.of(threadId));
    ApplicationDependencies.getDatabaseObserver().notifyMessageUpdateObservers(new MessageId(messageId, true));
    ApplicationDependencies.getDatabaseObserver().notifyConversationListListeners();
}
Also used : MessageId(org.thoughtcrime.securesms.database.model.MessageId)

Example 59 with MessageId

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

the class MmsDatabase method setIncomingMessagesViewed.

@Override
@NonNull
public List<MarkedMessageInfo> setIncomingMessagesViewed(@NonNull List<Long> messageIds) {
    if (messageIds.isEmpty()) {
        return Collections.emptyList();
    }
    SQLiteDatabase database = databaseHelper.getSignalWritableDatabase();
    String[] columns = new String[] { ID, RECIPIENT_ID, DATE_SENT, MESSAGE_BOX, THREAD_ID };
    String where = ID + " IN (" + Util.join(messageIds, ",") + ") AND " + VIEWED_RECEIPT_COUNT + " = 0";
    List<MarkedMessageInfo> results = new LinkedList<>();
    database.beginTransaction();
    try (Cursor cursor = database.query(TABLE_NAME, columns, where, null, null, null, null)) {
        while (cursor != null && cursor.moveToNext()) {
            long type = CursorUtil.requireLong(cursor, MESSAGE_BOX);
            if (Types.isSecureType(type) && Types.isInboxType(type)) {
                long messageId = CursorUtil.requireLong(cursor, ID);
                long threadId = CursorUtil.requireLong(cursor, THREAD_ID);
                RecipientId recipientId = RecipientId.from(CursorUtil.requireLong(cursor, RECIPIENT_ID));
                long dateSent = CursorUtil.requireLong(cursor, DATE_SENT);
                SyncMessageId syncMessageId = new SyncMessageId(recipientId, dateSent);
                results.add(new MarkedMessageInfo(threadId, syncMessageId, new MessageId(messageId, true), null));
                ContentValues contentValues = new ContentValues();
                contentValues.put(VIEWED_RECEIPT_COUNT, 1);
                database.update(TABLE_NAME, contentValues, ID_WHERE, SqlUtil.buildArgs(CursorUtil.requireLong(cursor, ID)));
            }
        }
        database.setTransactionSuccessful();
    } finally {
        database.endTransaction();
    }
    Set<Long> threadsUpdated = Stream.of(results).map(MarkedMessageInfo::getThreadId).collect(Collectors.toSet());
    notifyConversationListeners(threadsUpdated);
    return results;
}
Also used : ContentValues(android.content.ContentValues) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Cursor(android.database.Cursor) LinkedList(java.util.LinkedList) MessageId(org.thoughtcrime.securesms.database.model.MessageId) NonNull(androidx.annotation.NonNull)

Example 60 with MessageId

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

the class MmsDatabase method incrementReceiptCount.

@Override
public Set<MessageUpdate> incrementReceiptCount(SyncMessageId messageId, long timestamp, @NonNull ReceiptType receiptType) {
    SQLiteDatabase database = databaseHelper.getSignalWritableDatabase();
    Set<MessageUpdate> messageUpdates = new HashSet<>();
    try (Cursor cursor = database.query(TABLE_NAME, new String[] { ID, THREAD_ID, MESSAGE_BOX, RECIPIENT_ID, receiptType.getColumnName(), RECEIPT_TIMESTAMP }, DATE_SENT + " = ?", new String[] { String.valueOf(messageId.getTimetamp()) }, null, null, null, null)) {
        while (cursor.moveToNext()) {
            if (Types.isOutgoingMessageType(CursorUtil.requireLong(cursor, MESSAGE_BOX))) {
                RecipientId theirRecipientId = RecipientId.from(CursorUtil.requireLong(cursor, RECIPIENT_ID));
                RecipientId ourRecipientId = messageId.getRecipientId();
                String columnName = receiptType.getColumnName();
                if (ourRecipientId.equals(theirRecipientId) || Recipient.resolved(theirRecipientId).isGroup()) {
                    long id = CursorUtil.requireLong(cursor, ID);
                    long threadId = CursorUtil.requireLong(cursor, THREAD_ID);
                    int status = receiptType.getGroupStatus();
                    boolean isFirstIncrement = CursorUtil.requireLong(cursor, columnName) == 0;
                    long savedTimestamp = CursorUtil.requireLong(cursor, RECEIPT_TIMESTAMP);
                    long updatedTimestamp = isFirstIncrement ? Math.max(savedTimestamp, timestamp) : savedTimestamp;
                    database.execSQL("UPDATE " + TABLE_NAME + " SET " + columnName + " = " + columnName + " + 1, " + RECEIPT_TIMESTAMP + " = ? WHERE " + ID + " = ?", SqlUtil.buildArgs(updatedTimestamp, id));
                    SignalDatabase.groupReceipts().update(ourRecipientId, id, status, timestamp);
                    messageUpdates.add(new MessageUpdate(threadId, new MessageId(id, true)));
                }
            }
        }
        if (messageUpdates.size() > 0 && receiptType == ReceiptType.DELIVERY) {
            earlyDeliveryReceiptCache.increment(messageId.getTimetamp(), messageId.getRecipientId(), timestamp);
        }
        return messageUpdates;
    }
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Cursor(android.database.Cursor) HashSet(java.util.HashSet) MessageId(org.thoughtcrime.securesms.database.model.MessageId)

Aggregations

MessageId (org.thoughtcrime.securesms.database.model.MessageId)90 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)40 NonNull (androidx.annotation.NonNull)30 Recipient (org.thoughtcrime.securesms.recipients.Recipient)30 Nullable (androidx.annotation.Nullable)28 LinkedList (java.util.LinkedList)24 List (java.util.List)24 SyncMessageId (org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId)24 Context (android.content.Context)22 IOException (java.io.IOException)22 Log (org.signal.core.util.logging.Log)22 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)22 SignalServiceDataMessage (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage)22 ContentValues (android.content.ContentValues)20 Collections (java.util.Collections)20 Attachment (org.thoughtcrime.securesms.attachments.Attachment)20 MessageDatabase (org.thoughtcrime.securesms.database.MessageDatabase)20 Cursor (android.database.Cursor)18 ArrayList (java.util.ArrayList)18 TextSecurePreferences (org.thoughtcrime.securesms.util.TextSecurePreferences)18