use of org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo in project Signal-Android by signalapp.
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);
});
}
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);
}
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 = ListUtil.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));
}
}
use of org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo in project Signal-Android by signalapp.
the class MarkReadReceiver method onReceive.
@SuppressLint("StaticFieldLeak")
@Override
public void onReceive(final Context context, Intent intent) {
if (!CLEAR_ACTION.equals(intent.getAction()))
return;
final ArrayList<ConversationId> threads = intent.getParcelableArrayListExtra(THREADS_EXTRA);
if (threads != null) {
MessageNotifier notifier = ApplicationDependencies.getMessageNotifier();
for (ConversationId thread : threads) {
notifier.removeStickyThread(thread);
}
NotificationCancellationHelper.cancelLegacy(context, intent.getIntExtra(NOTIFICATION_ID_EXTRA, -1));
PendingResult finisher = goAsync();
SignalExecutors.BOUNDED.execute(() -> {
List<MarkedMessageInfo> messageIdsCollection = new LinkedList<>();
for (ConversationId thread : threads) {
Log.i(TAG, "Marking as read: " + thread);
List<MarkedMessageInfo> messageIds = SignalDatabase.threads().setRead(thread, true);
messageIdsCollection.addAll(messageIds);
}
process(context, messageIdsCollection);
ApplicationDependencies.getMessageNotifier().updateNotification(context);
finisher.finish();
});
}
}
use of org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo in project Signal-Android by WhisperSystems.
the class RemoteReplyReceiver method onReceive.
@SuppressLint("StaticFieldLeak")
@Override
public void onReceive(final Context context, Intent intent) {
if (!REPLY_ACTION.equals(intent.getAction()))
return;
Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
if (remoteInput == null)
return;
final RecipientId recipientId = intent.getParcelableExtra(RECIPIENT_EXTRA);
final ReplyMethod replyMethod = (ReplyMethod) intent.getSerializableExtra(REPLY_METHOD);
final CharSequence responseText = remoteInput.getCharSequence(MessageNotifierV2.EXTRA_REMOTE_REPLY);
final long groupStoryId = intent.getLongExtra(GROUP_STORY_ID_EXTRA, Long.MIN_VALUE);
if (recipientId == null)
throw new AssertionError("No recipientId specified");
if (replyMethod == null)
throw new AssertionError("No reply method specified");
if (responseText != null) {
SignalExecutors.BOUNDED.execute(() -> {
long threadId;
Recipient recipient = Recipient.resolved(recipientId);
int subscriptionId = recipient.getDefaultSubscriptionId().orElse(-1);
long expiresIn = TimeUnit.SECONDS.toMillis(recipient.getExpiresInSeconds());
ParentStoryId parentStoryId = groupStoryId != Long.MIN_VALUE ? ParentStoryId.deserialize(groupStoryId) : null;
switch(replyMethod) {
case GroupMessage:
{
OutgoingMediaMessage reply = new OutgoingMediaMessage(recipient, responseText.toString(), new LinkedList<>(), System.currentTimeMillis(), subscriptionId, expiresIn, false, 0, StoryType.NONE, parentStoryId, false, null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptySet(), Collections.emptySet(), null);
threadId = MessageSender.send(context, reply, -1, false, null, null);
break;
}
case SecureMessage:
{
OutgoingEncryptedMessage reply = new OutgoingEncryptedMessage(recipient, responseText.toString(), expiresIn);
threadId = MessageSender.send(context, reply, -1, false, null, null);
break;
}
case UnsecuredSmsMessage:
{
OutgoingTextMessage reply = new OutgoingTextMessage(recipient, responseText.toString(), expiresIn, subscriptionId);
threadId = MessageSender.send(context, reply, -1, true, null, null);
break;
}
default:
throw new AssertionError("Unknown Reply method");
}
ApplicationDependencies.getMessageNotifier().addStickyThread(new ConversationId(threadId, groupStoryId != Long.MIN_VALUE ? groupStoryId : null), intent.getLongExtra(EARLIEST_TIMESTAMP, System.currentTimeMillis()));
List<MarkedMessageInfo> messageIds = SignalDatabase.threads().setRead(threadId, true);
ApplicationDependencies.getMessageNotifier().updateNotification(context);
MarkReadReceiver.process(context, messageIds);
});
}
}
Aggregations