From 851f4c5cf7771f351bbdecf52ab8bfdd42c0be28 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Fri, 25 Jun 2021 10:18:04 +1000 Subject: [PATCH] Send read receipts --- .../conversation/v2/ConversationActivityV2.kt | 21 +++++++++++++++---- .../notifications/MarkReadReceiver.java | 1 - .../sskenvironment/ReadReceiptManager.kt | 1 + 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt index 7847ef8fac..e12db6dd81 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt @@ -2,12 +2,13 @@ package org.thoughtcrime.securesms.conversation.v2 import android.animation.FloatEvaluator import android.animation.ValueAnimator +import android.content.Context import android.content.res.Resources import android.database.Cursor import android.graphics.Rect import android.graphics.Typeface +import android.os.AsyncTask import android.os.Bundle -import android.util.Log import android.util.TypedValue import android.view.* import android.widget.RelativeLayout @@ -30,6 +31,7 @@ import org.session.libsession.messaging.contacts.Contact import org.session.libsession.messaging.mentions.MentionsManager import org.session.libsession.messaging.open_groups.OpenGroupAPIV2 import org.session.libsession.utilities.TextSecurePreferences +import org.session.libsession.utilities.recipients.Recipient import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity import org.thoughtcrime.securesms.conversation.v2.dialogs.* @@ -47,8 +49,10 @@ import org.thoughtcrime.securesms.database.model.MessageRecord import org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel.LinkPreviewState +import org.thoughtcrime.securesms.loki.protocol.SessionMetaProtocol.shouldSendReadReceipt import org.thoughtcrime.securesms.loki.utilities.toPx import org.thoughtcrime.securesms.mms.GlideApp +import org.thoughtcrime.securesms.notifications.MarkReadReceiver import org.thoughtcrime.securesms.util.DateUtils import java.util.* import kotlin.math.* @@ -130,7 +134,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe getLatestOpenGroupInfoIfNeeded() setUpBlockedBanner() setUpLinkPreviewObserver() - scrollToFirstUnreadMessage() + scrollToFirstUnreadMessageIfNeeded() markAllAsRead() } @@ -244,9 +248,10 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe }) } - private fun scrollToFirstUnreadMessage() { + private fun scrollToFirstUnreadMessageIfNeeded() { val lastSeenTimestamp = DatabaseFactory.getThreadDatabase(this).getLastSeenAndHasSent(threadID).first() val lastSeenItemPosition = adapter.findLastSeenItemPosition(lastSeenTimestamp) ?: return + if (lastSeenItemPosition <= 3) { return } conversationRecyclerView.scrollToPosition(lastSeenItemPosition) } @@ -264,7 +269,15 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe // region Updating & Animation private fun markAllAsRead() { - DatabaseFactory.getThreadDatabase(this).setRead(threadID, true) + val messages = DatabaseFactory.getThreadDatabase(this).setRead(threadID, true) + if (thread.isGroupRecipient) { + for (message in messages) { + MarkReadReceiver.scheduleDeletion(this, message.expirationInfo) + } + } else { + MarkReadReceiver.process(this, messages) + } + ApplicationContext.getInstance(this).messageNotifier.updateNotification(this) } override fun inputBarHeightChanged(newValue: Int) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java index 3df423a6de..c12a3f196b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java @@ -81,7 +81,6 @@ public class MarkReadReceiver extends BroadcastReceiver { for (Address address : addressMap.keySet()) { List timestamps = Stream.of(addressMap.get(address)).map(SyncMessageId::getTimetamp).toList(); - // Loki - Check whether we want to send a read receipt to this user if (!SessionMetaProtocol.shouldSendReadReceipt(address)) { continue; } ReadReceipt readReceipt = new ReadReceipt(timestamps); readReceipt.setSentTimestamp(System.currentTimeMillis()); diff --git a/app/src/main/java/org/thoughtcrime/securesms/sskenvironment/ReadReceiptManager.kt b/app/src/main/java/org/thoughtcrime/securesms/sskenvironment/ReadReceiptManager.kt index 2fc8c1cbaf..62002c88b5 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/sskenvironment/ReadReceiptManager.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/sskenvironment/ReadReceiptManager.kt @@ -9,6 +9,7 @@ import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.database.MessagingDatabase.SyncMessageId class ReadReceiptManager: SSKEnvironment.ReadReceiptManagerProtocol { + override fun processReadReceipts(context: Context, fromRecipientId: String, sentTimestamps: List, readTimestamp: Long) { if (TextSecurePreferences.isReadReceiptsEnabled(context)) {