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));
}
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();
}
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();
}
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;
}
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;
}
}
Aggregations