Search in sources :

Example 11 with MessageId

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

the class MmsDatabase method markAsSending.

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

Example 12 with MessageId

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

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 13 with MessageId

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

the class MmsDatabase method getViewedIncomingMessages.

@Override
@NonNull
public List<MarkedMessageInfo> getViewedIncomingMessages(long threadId) {
    SQLiteDatabase db = databaseHelper.getSignalReadableDatabase();
    String[] columns = new String[] { ID, RECIPIENT_ID, DATE_SENT, MESSAGE_BOX, THREAD_ID };
    String where = THREAD_ID + " = ? AND " + VIEWED_RECEIPT_COUNT + " > 0 AND " + MESSAGE_BOX + " & " + Types.BASE_INBOX_TYPE + " = " + Types.BASE_INBOX_TYPE;
    String[] args = SqlUtil.buildArgs(threadId);
    try (Cursor cursor = db.query(getTableName(), columns, where, args, null, null, null, null)) {
        if (cursor == null) {
            return Collections.emptyList();
        }
        List<MarkedMessageInfo> results = new ArrayList<>(cursor.getCount());
        while (cursor.moveToNext()) {
            long messageId = CursorUtil.requireLong(cursor, 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));
        }
        return results;
    }
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) MessageId(org.thoughtcrime.securesms.database.model.MessageId) NonNull(androidx.annotation.NonNull)

Example 14 with MessageId

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

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 15 with MessageId

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

the class SendViewedReceiptJob method enqueue.

/**
 * Enqueues all the necessary jobs for viewed receipts, ensuring that they're all within the
 * maximum size.
 */
public static void enqueue(long threadId, @NonNull RecipientId recipientId, List<MarkedMessageInfo> markedMessageInfos) {
    JobManager jobManager = ApplicationDependencies.getJobManager();
    List<List<MarkedMessageInfo>> messageIdChunks = Util.chunk(markedMessageInfos, MAX_TIMESTAMPS);
    if (messageIdChunks.size() > 1) {
        Log.w(TAG, "Large receipt count! Had to break into multiple chunks. Total count: " + markedMessageInfos.size());
    }
    for (List<MarkedMessageInfo> chunk : messageIdChunks) {
        List<Long> sentTimestamps = chunk.stream().map(info -> info.getSyncMessageId().getTimetamp()).collect(Collectors.toList());
        List<MessageId> messageIds = chunk.stream().map(MarkedMessageInfo::getMessageId).collect(Collectors.toList());
        jobManager.add(new SendViewedReceiptJob(threadId, recipientId, sentTimestamps, messageIds));
    }
}
Also used : MarkedMessageInfo(org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo) ServerRejectedException(org.whispersystems.signalservice.api.push.exceptions.ServerRejectedException) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) ContentHint(org.whispersystems.signalservice.api.crypto.ContentHint) MAX_TIMESTAMPS(org.thoughtcrime.securesms.jobs.SendReadReceiptJob.MAX_TIMESTAMPS) Util(org.thoughtcrime.securesms.util.Util) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult) NonNull(androidx.annotation.NonNull) Data(org.thoughtcrime.securesms.jobmanager.Data) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) RecipientUtil(org.thoughtcrime.securesms.recipients.RecipientUtil) NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) MessageId(org.thoughtcrime.securesms.database.model.MessageId) PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) NetworkConstraint(org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint) IOException(java.io.IOException) UnidentifiedAccessUtil(org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) Log(org.signal.core.util.logging.Log) List(java.util.List) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) Application(android.app.Application) Job(org.thoughtcrime.securesms.jobmanager.Job) SignalServiceReceiptMessage(org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage) Collections(java.util.Collections) List(java.util.List) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo) 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