use of org.thoughtcrime.securesms.database.model.MessageId in project Signal-Android by WhisperSystems.
the class MmsDatabase method markDownloadState.
@Override
public void markDownloadState(long messageId, long state) {
SQLiteDatabase database = databaseHelper.getSignalWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(STATUS, state);
database.update(TABLE_NAME, contentValues, ID_WHERE, new String[] { messageId + "" });
ApplicationDependencies.getDatabaseObserver().notifyMessageUpdateObservers(new MessageId(messageId, true));
}
use of org.thoughtcrime.securesms.database.model.MessageId in project Signal-Android by WhisperSystems.
the class SmsDatabase method setMessagesRead.
private List<MarkedMessageInfo> setMessagesRead(String where, String[] arguments) {
SQLiteDatabase database = databaseHelper.getSignalWritableDatabase();
List<MarkedMessageInfo> results = new LinkedList<>();
Cursor cursor = null;
RecipientId releaseChannelId = SignalStore.releaseChannelValues().getReleaseChannelRecipientId();
database.beginTransaction();
try {
cursor = database.query(TABLE_NAME, new String[] { ID, RECIPIENT_ID, DATE_SENT, TYPE, EXPIRES_IN, EXPIRE_STARTED, THREAD_ID }, where, arguments, null, null, null);
while (cursor != null && cursor.moveToNext()) {
if (Types.isSecureType(CursorUtil.requireLong(cursor, TYPE))) {
long threadId = CursorUtil.requireLong(cursor, THREAD_ID);
RecipientId recipientId = RecipientId.from(CursorUtil.requireLong(cursor, RECIPIENT_ID));
long dateSent = CursorUtil.requireLong(cursor, DATE_SENT);
long messageId = CursorUtil.requireLong(cursor, ID);
long expiresIn = CursorUtil.requireLong(cursor, EXPIRES_IN);
long expireStarted = CursorUtil.requireLong(cursor, EXPIRE_STARTED);
SyncMessageId syncMessageId = new SyncMessageId(recipientId, dateSent);
ExpirationInfo expirationInfo = new ExpirationInfo(messageId, expiresIn, expireStarted, false);
if (!recipientId.equals(releaseChannelId)) {
results.add(new MarkedMessageInfo(threadId, syncMessageId, new MessageId(messageId, false), expirationInfo));
}
}
}
ContentValues contentValues = new ContentValues();
contentValues.put(READ, 1);
contentValues.put(REACTIONS_UNREAD, 0);
contentValues.put(REACTIONS_LAST_SEEN, System.currentTimeMillis());
database.update(TABLE_NAME, contentValues, where, arguments);
database.setTransactionSuccessful();
} finally {
if (cursor != null)
cursor.close();
database.endTransaction();
}
return results;
}
use of org.thoughtcrime.securesms.database.model.MessageId in project Signal-Android by WhisperSystems.
the class SmsDatabase method markAsRemoteDelete.
@Override
public void markAsRemoteDelete(long id) {
SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
long threadId;
db.beginTransaction();
try {
ContentValues values = new ContentValues();
values.put(REMOTE_DELETED, 1);
values.putNull(BODY);
db.update(TABLE_NAME, values, ID_WHERE, new String[] { String.valueOf(id) });
threadId = getThreadIdForMessage(id);
SignalDatabase.reactions().deleteReactions(new MessageId(id, false));
SignalDatabase.threads().update(threadId, false);
SignalDatabase.messageLog().deleteAllRelatedToMessage(id, false);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
notifyConversationListeners(threadId);
}
use of org.thoughtcrime.securesms.database.model.MessageId in project Signal-Android by WhisperSystems.
the class SmsDatabase method updateTypeBitmask.
private void updateTypeBitmask(long id, long maskOff, long maskOn) {
SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
long threadId;
db.beginTransaction();
try {
db.execSQL("UPDATE " + TABLE_NAME + " SET " + TYPE + " = (" + TYPE + " & " + (Types.TOTAL_MASK - maskOff) + " | " + maskOn + " )" + " WHERE " + ID + " = ?", SqlUtil.buildArgs(id));
threadId = getThreadIdForMessage(id);
SignalDatabase.threads().updateSnippetTypeSilently(threadId);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
ApplicationDependencies.getDatabaseObserver().notifyMessageUpdateObservers(new MessageId(id, false));
ApplicationDependencies.getDatabaseObserver().notifyConversationListListeners();
}
use of org.thoughtcrime.securesms.database.model.MessageId in project Signal-Android by WhisperSystems.
the class SmsDatabase method incrementReceiptCount.
@Override
@NonNull
public Set<MessageUpdate> incrementReceiptCount(SyncMessageId messageId, long timestamp, @NonNull ReceiptType receiptType) {
if (receiptType == ReceiptType.VIEWED) {
return Collections.emptySet();
}
SQLiteDatabase database = databaseHelper.getSignalWritableDatabase();
Set<MessageUpdate> messageUpdates = new HashSet<>();
try (Cursor cursor = database.query(TABLE_NAME, new String[] { ID, THREAD_ID, RECIPIENT_ID, TYPE, DELIVERY_RECEIPT_COUNT, READ_RECEIPT_COUNT, RECEIPT_TIMESTAMP }, DATE_SENT + " = ?", new String[] { String.valueOf(messageId.getTimetamp()) }, null, null, null, null)) {
while (cursor.moveToNext()) {
if (Types.isOutgoingMessageType(CursorUtil.requireLong(cursor, TYPE))) {
RecipientId theirRecipientId = messageId.getRecipientId();
RecipientId outRecipientId = RecipientId.from(CursorUtil.requireLong(cursor, RECIPIENT_ID));
if (outRecipientId.equals(theirRecipientId)) {
long id = CursorUtil.requireLong(cursor, ID);
long threadId = CursorUtil.requireLong(cursor, THREAD_ID);
String columnName = receiptType.getColumnName();
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));
messageUpdates.add(new MessageUpdate(threadId, new MessageId(id, false)));
}
}
}
if (messageUpdates.isEmpty() && receiptType == ReceiptType.DELIVERY) {
earlyDeliveryReceiptCache.increment(messageId.getTimetamp(), messageId.getRecipientId(), timestamp);
}
return messageUpdates;
}
}
Aggregations