Search in sources :

Example 1 with MessageUpdate

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

the class MmsSmsDatabase method incrementReceiptCounts.

/**
 * Wraps multiple receipt updates in a transaction and triggers the proper updates.
 *
 * @return All of the messages that didn't result in updates.
 */
@NonNull
private Collection<SyncMessageId> incrementReceiptCounts(@NonNull List<SyncMessageId> syncMessageIds, long timestamp, @NonNull MessageDatabase.ReceiptType receiptType) {
    SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
    ThreadDatabase threadDatabase = SignalDatabase.threads();
    Set<MessageUpdate> messageUpdates = new HashSet<>();
    Collection<SyncMessageId> unhandled = new HashSet<>();
    db.beginTransaction();
    try {
        for (SyncMessageId id : syncMessageIds) {
            Set<MessageUpdate> updates = incrementReceiptCountInternal(id, timestamp, receiptType);
            if (updates.size() > 0) {
                messageUpdates.addAll(updates);
            } else {
                unhandled.add(id);
            }
        }
        for (MessageUpdate update : messageUpdates) {
            threadDatabase.updateSilently(update.getThreadId(), false);
            ApplicationDependencies.getDatabaseObserver().notifyMessageUpdateObservers(update.getMessageId());
            ApplicationDependencies.getDatabaseObserver().notifyVerboseConversationListeners(Collections.singleton(update.getThreadId()));
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
        if (messageUpdates.size() > 0) {
            notifyConversationListListeners();
        }
    }
    return unhandled;
}
Also used : MessageUpdate(org.thoughtcrime.securesms.database.MessageDatabase.MessageUpdate) SyncMessageId(org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId) HashSet(java.util.HashSet) NonNull(androidx.annotation.NonNull)

Example 2 with MessageUpdate

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

the class MmsSmsDatabase method incrementReceiptCounts.

/**
 * Wraps multiple receipt updates in a transaction and triggers the proper updates.
 *
 * @return All of the messages that didn't result in updates.
 */
@NonNull
private Collection<SyncMessageId> incrementReceiptCounts(@NonNull List<SyncMessageId> syncMessageIds, long timestamp, @NonNull MessageDatabase.ReceiptType receiptType) {
    SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
    ThreadDatabase threadDatabase = SignalDatabase.threads();
    Set<MessageUpdate> messageUpdates = new HashSet<>();
    Collection<SyncMessageId> unhandled = new HashSet<>();
    db.beginTransaction();
    try {
        for (SyncMessageId id : syncMessageIds) {
            Set<MessageUpdate> updates = incrementReceiptCountInternal(id, timestamp, receiptType);
            if (updates.size() > 0) {
                messageUpdates.addAll(updates);
            } else {
                unhandled.add(id);
            }
        }
        for (MessageUpdate update : messageUpdates) {
            threadDatabase.updateSilently(update.getThreadId(), false);
            ApplicationDependencies.getDatabaseObserver().notifyMessageUpdateObservers(update.getMessageId());
            ApplicationDependencies.getDatabaseObserver().notifyVerboseConversationListeners(Collections.singleton(update.getThreadId()));
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
        if (messageUpdates.size() > 0) {
            notifyConversationListListeners();
        }
    }
    return unhandled;
}
Also used : MessageUpdate(org.thoughtcrime.securesms.database.MessageDatabase.MessageUpdate) SyncMessageId(org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId) HashSet(java.util.HashSet) NonNull(androidx.annotation.NonNull)

Example 3 with MessageUpdate

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

the class MmsSmsDatabase method incrementReceiptCount.

/**
 * Wraps a single receipt update in a transaction and triggers the proper updates.
 *
 * @return Whether or not some thread was updated.
 */
private boolean incrementReceiptCount(SyncMessageId syncMessageId, long timestamp, @NonNull MessageDatabase.ReceiptType receiptType) {
    SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
    ThreadDatabase threadDatabase = SignalDatabase.threads();
    Set<MessageUpdate> messageUpdates = new HashSet<>();
    db.beginTransaction();
    try {
        messageUpdates = incrementReceiptCountInternal(syncMessageId, timestamp, receiptType);
        for (MessageUpdate messageUpdate : messageUpdates) {
            threadDatabase.update(messageUpdate.getThreadId(), false);
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
        for (MessageUpdate threadUpdate : messageUpdates) {
            ApplicationDependencies.getDatabaseObserver().notifyMessageUpdateObservers(threadUpdate.getMessageId());
        }
    }
    return messageUpdates.size() > 0;
}
Also used : MessageUpdate(org.thoughtcrime.securesms.database.MessageDatabase.MessageUpdate) HashSet(java.util.HashSet)

Example 4 with MessageUpdate

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

the class MmsSmsDatabase method incrementReceiptCount.

/**
 * Wraps a single receipt update in a transaction and triggers the proper updates.
 *
 * @return Whether or not some thread was updated.
 */
private boolean incrementReceiptCount(SyncMessageId syncMessageId, long timestamp, @NonNull MessageDatabase.ReceiptType receiptType) {
    SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
    ThreadDatabase threadDatabase = SignalDatabase.threads();
    Set<MessageUpdate> messageUpdates = new HashSet<>();
    db.beginTransaction();
    try {
        messageUpdates = incrementReceiptCountInternal(syncMessageId, timestamp, receiptType);
        for (MessageUpdate messageUpdate : messageUpdates) {
            threadDatabase.update(messageUpdate.getThreadId(), false);
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
        for (MessageUpdate threadUpdate : messageUpdates) {
            ApplicationDependencies.getDatabaseObserver().notifyMessageUpdateObservers(threadUpdate.getMessageId());
        }
    }
    return messageUpdates.size() > 0;
}
Also used : MessageUpdate(org.thoughtcrime.securesms.database.MessageDatabase.MessageUpdate) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)4 MessageUpdate (org.thoughtcrime.securesms.database.MessageDatabase.MessageUpdate)4 NonNull (androidx.annotation.NonNull)2 SyncMessageId (org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId)2