Search in sources :

Example 6 with MarkedMessageInfo

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

the class ThreadDatabase method setReadSince.

public List<MarkedMessageInfo> setReadSince(Map<Long, Long> threadIdToSinceTimestamp, boolean lastSeen) {
    SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
    List<MarkedMessageInfo> smsRecords = new LinkedList<>();
    List<MarkedMessageInfo> mmsRecords = new LinkedList<>();
    boolean needsSync = false;
    db.beginTransaction();
    try {
        ContentValues contentValues = new ContentValues(2);
        contentValues.put(READ, ReadStatus.READ.serialize());
        for (Map.Entry<Long, Long> entry : threadIdToSinceTimestamp.entrySet()) {
            long threadId = entry.getKey();
            long sinceTimestamp = entry.getValue();
            if (lastSeen) {
                contentValues.put(LAST_SEEN, sinceTimestamp == -1 ? System.currentTimeMillis() : sinceTimestamp);
            }
            ThreadRecord previous = getThreadRecord(threadId);
            smsRecords.addAll(SignalDatabase.sms().setMessagesReadSince(threadId, sinceTimestamp));
            mmsRecords.addAll(SignalDatabase.mms().setMessagesReadSince(threadId, sinceTimestamp));
            SignalDatabase.sms().setReactionsSeen(threadId, sinceTimestamp);
            SignalDatabase.mms().setReactionsSeen(threadId, sinceTimestamp);
            int unreadCount = SignalDatabase.mmsSms().getUnreadCount(threadId);
            contentValues.put(UNREAD_COUNT, unreadCount);
            db.update(TABLE_NAME, contentValues, ID_WHERE, SqlUtil.buildArgs(threadId));
            if (previous != null && previous.isForcedUnread()) {
                SignalDatabase.recipients().markNeedsSync(previous.getRecipient().getId());
                needsSync = true;
            }
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    notifyVerboseConversationListeners(threadIdToSinceTimestamp.keySet());
    notifyConversationListListeners();
    if (needsSync) {
        StorageSyncHelper.scheduleSyncForDataChange();
    }
    return Util.concatenatedList(smsRecords, mmsRecords);
}
Also used : ContentValues(android.content.ContentValues) ThreadRecord(org.thoughtcrime.securesms.database.model.ThreadRecord) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo) Map(java.util.Map) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList)

Example 7 with MarkedMessageInfo

use of org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo 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)

Example 8 with MarkedMessageInfo

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

the class ConversationListFragment method handleMarkAllRead.

private void handleMarkAllRead() {
    Context context = requireContext();
    SignalExecutors.BOUNDED.execute(() -> {
        List<MarkedMessageInfo> messageIds = SignalDatabase.threads().setAllThreadsRead();
        ApplicationDependencies.getMessageNotifier().updateNotification(context);
        MarkReadReceiver.process(context, messageIds);
    });
}
Also used : Context(android.content.Context) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo)

Example 9 with MarkedMessageInfo

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

the class ConversationListFragment method handleMarkAsRead.

private void handleMarkAsRead(@NonNull Collection<Long> ids) {
    Context context = requireContext();
    SimpleTask.run(getViewLifecycleOwner().getLifecycle(), () -> {
        List<MarkedMessageInfo> messageIds = SignalDatabase.threads().setRead(ids, false);
        ApplicationDependencies.getMessageNotifier().updateNotification(context);
        MarkReadReceiver.process(context, messageIds);
        return null;
    }, none -> {
        endActionModeIfActive();
    });
}
Also used : Context(android.content.Context) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo)

Example 10 with MarkedMessageInfo

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

the class ThreadDatabase method setReadSince.

public List<MarkedMessageInfo> setReadSince(Map<Long, Long> threadIdToSinceTimestamp, boolean lastSeen) {
    SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
    List<MarkedMessageInfo> smsRecords = new LinkedList<>();
    List<MarkedMessageInfo> mmsRecords = new LinkedList<>();
    boolean needsSync = false;
    db.beginTransaction();
    try {
        ContentValues contentValues = new ContentValues(2);
        contentValues.put(READ, ReadStatus.READ.serialize());
        for (Map.Entry<Long, Long> entry : threadIdToSinceTimestamp.entrySet()) {
            long threadId = entry.getKey();
            long sinceTimestamp = entry.getValue();
            if (lastSeen) {
                contentValues.put(LAST_SEEN, sinceTimestamp == -1 ? System.currentTimeMillis() : sinceTimestamp);
            }
            ThreadRecord previous = getThreadRecord(threadId);
            smsRecords.addAll(SignalDatabase.sms().setMessagesReadSince(threadId, sinceTimestamp));
            mmsRecords.addAll(SignalDatabase.mms().setMessagesReadSince(threadId, sinceTimestamp));
            SignalDatabase.sms().setReactionsSeen(threadId, sinceTimestamp);
            SignalDatabase.mms().setReactionsSeen(threadId, sinceTimestamp);
            int unreadCount = SignalDatabase.mmsSms().getUnreadCount(threadId);
            contentValues.put(UNREAD_COUNT, unreadCount);
            db.update(TABLE_NAME, contentValues, ID_WHERE, SqlUtil.buildArgs(threadId));
            if (previous != null && previous.isForcedUnread()) {
                SignalDatabase.recipients().markNeedsSync(previous.getRecipient().getId());
                needsSync = true;
            }
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    notifyVerboseConversationListeners(threadIdToSinceTimestamp.keySet());
    notifyConversationListListeners();
    if (needsSync) {
        StorageSyncHelper.scheduleSyncForDataChange();
    }
    return Util.concatenatedList(smsRecords, mmsRecords);
}
Also used : ContentValues(android.content.ContentValues) ThreadRecord(org.thoughtcrime.securesms.database.model.ThreadRecord) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo) Map(java.util.Map) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList)

Aggregations

MarkedMessageInfo (org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo)16 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)8 Context (android.content.Context)6 NonNull (androidx.annotation.NonNull)6 LinkedList (java.util.LinkedList)6 List (java.util.List)6 Log (org.signal.core.util.logging.Log)6 SignalDatabase (org.thoughtcrime.securesms.database.SignalDatabase)6 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)6 Recipient (org.thoughtcrime.securesms.recipients.Recipient)6 SuppressLint (android.annotation.SuppressLint)4 Application (android.app.Application)4 ContentValues (android.content.ContentValues)4 IOException (java.io.IOException)4 Collections (java.util.Collections)4 Map (java.util.Map)4 TimeUnit (java.util.concurrent.TimeUnit)4 Collectors (java.util.stream.Collectors)4 UnidentifiedAccessUtil (org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil)4 MessageId (org.thoughtcrime.securesms.database.model.MessageId)4