Search in sources :

Example 61 with MessageId

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));
}
Also used : ContentValues(android.content.ContentValues) MessageId(org.thoughtcrime.securesms.database.model.MessageId)

Example 62 with MessageId

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;
}
Also used : ContentValues(android.content.ContentValues) ViewOnceExpirationInfo(org.thoughtcrime.securesms.revealable.ViewOnceExpirationInfo) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Cursor(android.database.Cursor) LinkedList(java.util.LinkedList) MessageId(org.thoughtcrime.securesms.database.model.MessageId)

Example 63 with MessageId

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);
}
Also used : ContentValues(android.content.ContentValues) MessageId(org.thoughtcrime.securesms.database.model.MessageId)

Example 64 with MessageId

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();
}
Also used : MessageId(org.thoughtcrime.securesms.database.model.MessageId)

Example 65 with MessageId

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;
    }
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Cursor(android.database.Cursor) HashSet(java.util.HashSet) MessageId(org.thoughtcrime.securesms.database.model.MessageId) NonNull(androidx.annotation.NonNull)

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