From 12a6bc724d40e7e86c37fbda933a41b3f6c08f38 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Wed, 12 Aug 2020 14:06:18 +1000 Subject: [PATCH] Don't send read receipts in groups --- .../conversation/ConversationActivity.java | 20 ++++++++++++++++--- .../notifications/DefaultMessageNotifier.java | 4 ++-- .../notifications/MarkReadReceiver.java | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java index 7dd3365317..674cc18662 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -1168,9 +1168,16 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity builder.setMessage(getString(R.string.ConversationActivity_are_you_sure_you_want_to_leave_this_group)); builder.setPositiveButton(R.string.yes, (dialog, which) -> { Recipient groupRecipient = getRecipient(); + String groupPublicKey; + boolean isSSKBasedClosedGroup; + try { + groupPublicKey = HexEncodingKt.toHexString(GroupUtil.getDecodedId(GroupUtil.getDecodedStringId(groupRecipient.getAddress().toString()))); + isSSKBasedClosedGroup = DatabaseFactory.getSSKDatabase(this).isSSKBasedClosedGroup(groupPublicKey); + } catch (IOException e) { + groupPublicKey = null; + isSSKBasedClosedGroup = false; + } try { - String groupPublicKey = HexEncodingKt.toHexString(GroupUtil.getDecodedId(GroupUtil.getDecodedStringId(groupRecipient.getAddress().toString()))); - boolean isSSKBasedClosedGroup = DatabaseFactory.getSSKDatabase(this).isSSKBasedClosedGroup(groupPublicKey); if (isSSKBasedClosedGroup) { ClosedGroupsProtocol.leave(this, groupPublicKey); initializeEnabledCheck(); @@ -2238,13 +2245,20 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity } private void markThreadAsRead() { + Recipient recipient = this.recipient; new AsyncTask() { @Override protected Void doInBackground(Long... params) { Context context = ConversationActivity.this; List messageIds = DatabaseFactory.getThreadDatabase(context).setRead(params[0], false); - MarkReadReceiver.process(context, messageIds); + if (!org.thoughtcrime.securesms.loki.protocol.SessionMetaProtocol.shouldSendReadReceipt(recipient.getAddress())) { + for (MarkedMessageInfo messageInfo : messageIds) { + MarkReadReceiver.scheduleDeletion(context, messageInfo.getExpirationInfo()); + } + } else { + MarkReadReceiver.process(context, messageIds); + } return null; } diff --git a/src/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java b/src/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java index 660e1a4ecd..0183fdf108 100644 --- a/src/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java +++ b/src/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java @@ -213,7 +213,7 @@ public class DefaultMessageNotifier implements MessageNotifier { } @Override - public void updateNotification(@NonNull Context context, long threadId, boolean signal) + public void updateNotification(@NonNull Context context, long threadId, boolean signal) { boolean isVisible = visibleThread == threadId; @@ -221,7 +221,7 @@ public class DefaultMessageNotifier implements MessageNotifier { Recipient recipients = DatabaseFactory.getThreadDatabase(context) .getRecipientForThreadId(threadId); - if (isVisible) { + if (isVisible && recipients != null && SessionMetaProtocol.shouldSendReadReceipt(recipients.getAddress())) { List messageIds = threads.setRead(threadId, false); MarkReadReceiver.process(context, messageIds); } diff --git a/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java b/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java index ca8271a3f9..8f556026e1 100644 --- a/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java +++ b/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java @@ -105,7 +105,7 @@ public class MarkReadReceiver extends BroadcastReceiver { } } - private static void scheduleDeletion(Context context, ExpirationInfo expirationInfo) { + public static void scheduleDeletion(Context context, ExpirationInfo expirationInfo) { if (expirationInfo.getExpiresIn() > 0 && expirationInfo.getExpireStarted() <= 0) { ExpiringMessageManager expirationManager = ApplicationContext.getInstance(context).getExpiringMessageManager();