From 75a8123d1e0e7016341065460def705ce9813f2b Mon Sep 17 00:00:00 2001 From: Mikunj Date: Thu, 6 Jun 2019 10:39:24 +1000 Subject: [PATCH] Send friend request accept message back to the user. --- .../SignalCommunicationModule.java | 4 +++- .../securesms/jobs/PushDecryptJob.java | 24 +++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java b/src/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java index dbe71d9c16..fadae1def2 100644 --- a/src/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java +++ b/src/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java @@ -5,6 +5,7 @@ import android.content.Context; import org.thoughtcrime.securesms.gcm.FcmService; import org.thoughtcrime.securesms.jobs.AttachmentUploadJob; import org.thoughtcrime.securesms.jobs.MultiDeviceConfigurationUpdateJob; +import org.thoughtcrime.securesms.jobs.PushDecryptJob; import org.thoughtcrime.securesms.jobs.RefreshUnidentifiedDeliveryAbilityJob; import org.thoughtcrime.securesms.jobs.RotateProfileKeyJob; import org.thoughtcrime.securesms.jobs.TypingSendJob; @@ -96,7 +97,8 @@ import dagger.Provides; MultiDeviceConfigurationUpdateJob.class, RefreshUnidentifiedDeliveryAbilityJob.class, TypingSendJob.class, - AttachmentUploadJob.class}) + AttachmentUploadJob.class, + PushDecryptJob.class}) public class SignalCommunicationModule { private static final String TAG = SignalCommunicationModule.class.getSimpleName(); diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index c62c2635b5..8434e00524 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -54,6 +54,7 @@ import org.thoughtcrime.securesms.database.SmsDatabase; import org.thoughtcrime.securesms.database.ThreadDatabase; import org.thoughtcrime.securesms.database.model.MessageRecord; import org.thoughtcrime.securesms.database.model.MmsMessageRecord; +import org.thoughtcrime.securesms.dependencies.InjectableType; import org.thoughtcrime.securesms.groups.GroupMessageProcessor; import org.thoughtcrime.securesms.jobmanager.Data; import org.thoughtcrime.securesms.jobmanager.Job; @@ -86,6 +87,8 @@ import org.whispersystems.libsignal.state.PreKeyBundle; import org.whispersystems.libsignal.state.SessionStore; import org.whispersystems.libsignal.state.SignalProtocolStore; import org.whispersystems.libsignal.util.guava.Optional; +import org.whispersystems.signalservice.api.SignalServiceMessageSender; +import org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair; import org.whispersystems.signalservice.api.messages.SignalServiceContent; import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage; import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage.Preview; @@ -115,7 +118,9 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; -public class PushDecryptJob extends BaseJob { +import javax.inject.Inject; + +public class PushDecryptJob extends BaseJob implements InjectableType { public static final String KEY = "PushDecryptJob"; @@ -127,6 +132,8 @@ public class PushDecryptJob extends BaseJob { private long messageId; private long smsMessageId; + @Inject SignalServiceMessageSender messageSender; + public PushDecryptJob(Context context) { this(context, -1); } @@ -834,7 +841,8 @@ public class PushDecryptJob extends BaseJob { // we can end up in a deadlock where both users' threads' friend request statuses are // `REQUEST_SENT`. database.setFriendRequestStatus(threadId, ThreadDatabase.LokiFriendRequestStatus.FRIENDS); - // TODO: Send empty message here + // Accept the friend request + sendEmptyMessageTo(envelope.getSource()); } else if (friendRequestStatus != ThreadDatabase.LokiFriendRequestStatus.FRIENDS) { // Checking that the sender of the message isn't already a friend is necessary because otherwise // the following situation can occur: Alice and Bob are friends. Bob loses his database and his @@ -851,6 +859,18 @@ public class PushDecryptJob extends BaseJob { } } + private void sendEmptyMessageTo(String pubKey) { + try { + SignalServiceAddress address = new SignalServiceAddress(pubKey); + SignalServiceDataMessage message = new SignalServiceDataMessage(System.currentTimeMillis(), ""); + Optional access = Optional.absent(); + + messageSender.sendMessage(address, access, message); + } catch (Exception e) { + Log.w(TAG, "Failed to send empty message to " + pubKey); + } + } + private long handleSynchronizeSentTextMessage(@NonNull SentTranscriptMessage message) throws MmsException {