From c35c08340d8f92d85c585ce9f9970888aa7e858a Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Wed, 19 Aug 2020 13:39:02 +1000 Subject: [PATCH] Fix delivery receipts --- src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java | 9 +++++---- .../securesms/jobs/SendDeliveryReceiptJob.java | 4 +--- .../securesms/loki/protocol/SessionMetaProtocol.kt | 8 ++++++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index 4ce544efb2..52bfb5541f 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -5,12 +5,13 @@ import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.os.Build; +import android.text.TextUtils; +import android.util.Pair; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationManagerCompat; -import android.text.TextUtils; -import android.util.Pair; import com.annimon.stream.Collectors; import com.annimon.stream.Stream; @@ -66,10 +67,10 @@ import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.loki.activities.HomeActivity; import org.thoughtcrime.securesms.loki.database.LokiMessageDatabase; import org.thoughtcrime.securesms.loki.protocol.ClosedGroupsProtocol; -import org.thoughtcrime.securesms.loki.protocol.shelved.MultiDeviceProtocol; import org.thoughtcrime.securesms.loki.protocol.SessionManagementProtocol; import org.thoughtcrime.securesms.loki.protocol.SessionMetaProtocol; import org.thoughtcrime.securesms.loki.protocol.SessionResetImplementation; +import org.thoughtcrime.securesms.loki.protocol.shelved.MultiDeviceProtocol; import org.thoughtcrime.securesms.loki.protocol.shelved.SyncMessagesProtocol; import org.thoughtcrime.securesms.loki.utilities.MentionManagerUtilities; import org.thoughtcrime.securesms.loki.utilities.PromiseUtilities; @@ -303,7 +304,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { SessionMetaProtocol.handleProfileKeyUpdate(context, content); } - if (content.isNeedsReceipt() && SessionMetaProtocol.shouldSendDeliveryReceipt(Address.fromSerialized(content.getSender()))) { + if (SessionMetaProtocol.shouldSendDeliveryReceipt(message, Address.fromSerialized(content.getSender()))) { handleNeedsDeliveryReceipt(content, message); } } diff --git a/src/org/thoughtcrime/securesms/jobs/SendDeliveryReceiptJob.java b/src/org/thoughtcrime/securesms/jobs/SendDeliveryReceiptJob.java index dead5266cd..b19fbba85c 100644 --- a/src/org/thoughtcrime/securesms/jobs/SendDeliveryReceiptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/SendDeliveryReceiptJob.java @@ -10,7 +10,6 @@ import org.thoughtcrime.securesms.jobmanager.Data; import org.thoughtcrime.securesms.jobmanager.Job; import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint; import org.thoughtcrime.securesms.logging.Log; -import org.thoughtcrime.securesms.loki.protocol.SessionMetaProtocol; import org.thoughtcrime.securesms.recipients.Recipient; import org.whispersystems.signalservice.api.SignalServiceMessageSender; import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException; @@ -79,13 +78,12 @@ public class SendDeliveryReceiptJob extends BaseJob implements InjectableType { @Override public void onRun() throws IOException, UntrustedIdentityException { + Log.d("Loki", "Sending delivery receipt."); SignalServiceAddress remoteAddress = new SignalServiceAddress(address); SignalServiceReceiptMessage receiptMessage = new SignalServiceReceiptMessage(SignalServiceReceiptMessage.Type.DELIVERY, Collections.singletonList(messageId), timestamp); - if (!SessionMetaProtocol.shouldSendDeliveryReceipt(Address.fromSerialized(address))) { return; } - messageSender.sendReceipt(remoteAddress, UnidentifiedAccessUtil.getAccessFor(context, Recipient.from(context, Address.fromSerialized(address), false)), receiptMessage); diff --git a/src/org/thoughtcrime/securesms/loki/protocol/SessionMetaProtocol.kt b/src/org/thoughtcrime/securesms/loki/protocol/SessionMetaProtocol.kt index 1aacde4196..2327cbe3bb 100644 --- a/src/org/thoughtcrime/securesms/loki/protocol/SessionMetaProtocol.kt +++ b/src/org/thoughtcrime/securesms/loki/protocol/SessionMetaProtocol.kt @@ -79,8 +79,12 @@ object SessionMetaProtocol { } @JvmStatic - fun shouldSendDeliveryReceipt(address: Address): Boolean { - return !address.isGroup + fun shouldSendDeliveryReceipt(message: SignalServiceDataMessage, address: Address): Boolean { + if (address.isGroup) { return false } + val hasBody = message.body.isPresent && message.body.get().isNotEmpty() + val hasAttachment = message.attachments.isPresent && message.attachments.get().isNotEmpty() + val hasLinkPreview = message.previews.isPresent && message.previews.get().isNotEmpty() + return hasBody || hasAttachment || hasLinkPreview } /**