2014-11-03 15:16:04 -08:00
|
|
|
package org.thoughtcrime.securesms.jobs;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2016-11-09 09:37:40 -08:00
|
|
|
import android.content.Intent;
|
2015-07-06 17:36:49 -07:00
|
|
|
import android.support.annotation.NonNull;
|
2014-11-03 15:16:04 -08:00
|
|
|
import android.util.Log;
|
|
|
|
import android.util.Pair;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.ApplicationContext;
|
2015-10-12 18:25:05 -07:00
|
|
|
import org.thoughtcrime.securesms.attachments.DatabaseAttachment;
|
|
|
|
import org.thoughtcrime.securesms.attachments.PointerAttachment;
|
2015-07-06 17:36:49 -07:00
|
|
|
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
2014-11-03 15:16:04 -08:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
2015-07-06 17:36:49 -07:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecretUnion;
|
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
2014-11-04 15:01:32 -08:00
|
|
|
import org.thoughtcrime.securesms.crypto.SecurityEvent;
|
2016-03-23 10:34:41 -07:00
|
|
|
import org.thoughtcrime.securesms.crypto.storage.SignalProtocolStoreImpl;
|
2014-11-03 15:16:04 -08:00
|
|
|
import org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore;
|
2017-07-26 09:59:15 -07:00
|
|
|
import org.thoughtcrime.securesms.database.Address;
|
2014-11-03 15:16:04 -08:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|
|
|
import org.thoughtcrime.securesms.database.EncryptingSmsDatabase;
|
2016-11-20 14:50:41 -08:00
|
|
|
import org.thoughtcrime.securesms.database.GroupDatabase;
|
2017-01-22 13:52:36 -08:00
|
|
|
import org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult;
|
2016-02-19 17:07:41 -08:00
|
|
|
import org.thoughtcrime.securesms.database.MessagingDatabase.SyncMessageId;
|
2014-11-03 15:16:04 -08:00
|
|
|
import org.thoughtcrime.securesms.database.MmsDatabase;
|
2014-11-08 11:35:58 -08:00
|
|
|
import org.thoughtcrime.securesms.database.NoSuchMessageException;
|
2014-11-03 15:16:04 -08:00
|
|
|
import org.thoughtcrime.securesms.database.PushDatabase;
|
2017-08-21 18:37:39 -07:00
|
|
|
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
2016-11-09 09:37:40 -08:00
|
|
|
import org.thoughtcrime.securesms.database.SmsDatabase;
|
2015-10-12 18:25:05 -07:00
|
|
|
import org.thoughtcrime.securesms.database.ThreadDatabase;
|
2014-11-03 15:16:04 -08:00
|
|
|
import org.thoughtcrime.securesms.groups.GroupMessageProcessor;
|
|
|
|
import org.thoughtcrime.securesms.mms.IncomingMediaMessage;
|
2017-06-06 18:03:09 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.MmsException;
|
2016-08-15 20:23:56 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.OutgoingExpirationUpdateMessage;
|
2015-05-18 15:16:27 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.OutgoingMediaMessage;
|
|
|
|
import org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage;
|
2014-11-03 15:16:04 -08:00
|
|
|
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
2017-08-01 08:56:00 -07:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2014-11-03 15:16:04 -08:00
|
|
|
import org.thoughtcrime.securesms.service.KeyCachingService;
|
2016-11-09 09:37:40 -08:00
|
|
|
import org.thoughtcrime.securesms.service.WebRtcCallService;
|
2014-11-03 15:16:04 -08:00
|
|
|
import org.thoughtcrime.securesms.sms.IncomingEncryptedMessage;
|
|
|
|
import org.thoughtcrime.securesms.sms.IncomingEndSessionMessage;
|
|
|
|
import org.thoughtcrime.securesms.sms.IncomingPreKeyBundleMessage;
|
|
|
|
import org.thoughtcrime.securesms.sms.IncomingTextMessage;
|
2016-02-04 23:02:26 +01:00
|
|
|
import org.thoughtcrime.securesms.sms.OutgoingEndSessionMessage;
|
2015-05-18 15:16:27 -07:00
|
|
|
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
|
2014-11-12 11:15:05 -08:00
|
|
|
import org.thoughtcrime.securesms.util.Base64;
|
2015-05-18 15:16:27 -07:00
|
|
|
import org.thoughtcrime.securesms.util.GroupUtil;
|
2017-06-06 18:03:09 -07:00
|
|
|
import org.thoughtcrime.securesms.util.IdentityUtil;
|
2014-11-03 15:16:04 -08:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
|
|
import org.whispersystems.jobqueue.JobParameters;
|
2016-03-23 10:34:41 -07:00
|
|
|
import org.whispersystems.libsignal.DuplicateMessageException;
|
|
|
|
import org.whispersystems.libsignal.IdentityKey;
|
|
|
|
import org.whispersystems.libsignal.InvalidKeyException;
|
|
|
|
import org.whispersystems.libsignal.InvalidKeyIdException;
|
|
|
|
import org.whispersystems.libsignal.InvalidMessageException;
|
|
|
|
import org.whispersystems.libsignal.InvalidVersionException;
|
|
|
|
import org.whispersystems.libsignal.LegacyMessageException;
|
|
|
|
import org.whispersystems.libsignal.NoSessionException;
|
|
|
|
import org.whispersystems.libsignal.UntrustedIdentityException;
|
|
|
|
import org.whispersystems.libsignal.protocol.PreKeySignalMessage;
|
|
|
|
import org.whispersystems.libsignal.state.SessionStore;
|
2016-08-15 20:23:56 -07:00
|
|
|
import org.whispersystems.libsignal.state.SignalProtocolStore;
|
2016-03-23 10:34:41 -07:00
|
|
|
import org.whispersystems.libsignal.util.guava.Optional;
|
|
|
|
import org.whispersystems.signalservice.api.crypto.SignalServiceCipher;
|
2016-08-15 20:23:56 -07:00
|
|
|
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
2016-03-23 10:34:41 -07:00
|
|
|
import org.whispersystems.signalservice.api.messages.SignalServiceContent;
|
|
|
|
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
|
|
|
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
|
|
|
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
|
2017-09-15 22:38:53 -07:00
|
|
|
import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
|
2016-11-09 09:37:40 -08:00
|
|
|
import org.whispersystems.signalservice.api.messages.calls.AnswerMessage;
|
2017-06-01 13:11:48 -07:00
|
|
|
import org.whispersystems.signalservice.api.messages.calls.BusyMessage;
|
2016-11-09 09:37:40 -08:00
|
|
|
import org.whispersystems.signalservice.api.messages.calls.HangupMessage;
|
|
|
|
import org.whispersystems.signalservice.api.messages.calls.IceUpdateMessage;
|
|
|
|
import org.whispersystems.signalservice.api.messages.calls.OfferMessage;
|
|
|
|
import org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage;
|
2016-03-23 10:34:41 -07:00
|
|
|
import org.whispersystems.signalservice.api.messages.multidevice.ReadMessage;
|
|
|
|
import org.whispersystems.signalservice.api.messages.multidevice.RequestMessage;
|
|
|
|
import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage;
|
|
|
|
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
|
2017-06-06 18:03:09 -07:00
|
|
|
import org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage;
|
2016-03-23 10:34:41 -07:00
|
|
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
2014-11-03 15:16:04 -08:00
|
|
|
|
2017-08-14 18:11:13 -07:00
|
|
|
import java.security.MessageDigest;
|
2015-08-24 15:24:31 -07:00
|
|
|
import java.util.List;
|
2015-03-18 14:25:27 -07:00
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
2015-07-06 17:36:49 -07:00
|
|
|
public class PushDecryptJob extends ContextJob {
|
2014-11-03 15:16:04 -08:00
|
|
|
|
2015-07-06 17:36:49 -07:00
|
|
|
private static final long serialVersionUID = 2L;
|
2015-06-24 18:26:51 -07:00
|
|
|
|
2014-11-03 15:16:04 -08:00
|
|
|
public static final String TAG = PushDecryptJob.class.getSimpleName();
|
|
|
|
|
|
|
|
private final long messageId;
|
2015-01-15 13:35:35 -08:00
|
|
|
private final long smsMessageId;
|
|
|
|
|
2017-07-26 09:59:15 -07:00
|
|
|
public PushDecryptJob(Context context, long pushMessageId) {
|
|
|
|
this(context, pushMessageId, -1);
|
2015-01-15 13:35:35 -08:00
|
|
|
}
|
2014-11-03 15:16:04 -08:00
|
|
|
|
2017-07-26 09:59:15 -07:00
|
|
|
public PushDecryptJob(Context context, long pushMessageId, long smsMessageId) {
|
2014-11-03 15:16:04 -08:00
|
|
|
super(context, JobParameters.newBuilder()
|
|
|
|
.withPersistence()
|
2015-10-16 10:07:50 -07:00
|
|
|
.withGroupId("__PUSH_DECRYPT_JOB__")
|
2015-03-18 14:25:27 -07:00
|
|
|
.withWakeLock(true, 5, TimeUnit.SECONDS)
|
2014-11-03 15:16:04 -08:00
|
|
|
.create());
|
2015-01-15 13:35:35 -08:00
|
|
|
this.messageId = pushMessageId;
|
|
|
|
this.smsMessageId = smsMessageId;
|
2014-11-03 15:16:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-07-20 18:00:48 -07:00
|
|
|
public void onAdded() {}
|
2014-11-03 15:16:04 -08:00
|
|
|
|
|
|
|
@Override
|
2015-07-06 17:36:49 -07:00
|
|
|
public void onRun() throws NoSuchMessageException {
|
2015-10-16 10:07:50 -07:00
|
|
|
|
2015-07-06 17:36:49 -07:00
|
|
|
if (!IdentityKeyUtil.hasIdentityKey(context)) {
|
|
|
|
Log.w(TAG, "Skipping job, waiting for migration...");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-23 10:34:41 -07:00
|
|
|
MasterSecret masterSecret = KeyCachingService.getMasterSecret(context);
|
|
|
|
PushDatabase database = DatabaseFactory.getPushDatabase(context);
|
|
|
|
SignalServiceEnvelope envelope = database.get(messageId);
|
|
|
|
Optional<Long> optionalSmsMessageId = smsMessageId > 0 ? Optional.of(smsMessageId) :
|
2015-05-18 15:16:27 -07:00
|
|
|
Optional.<Long>absent();
|
2014-11-03 15:16:04 -08:00
|
|
|
|
2015-07-06 17:36:49 -07:00
|
|
|
MasterSecretUnion masterSecretUnion;
|
|
|
|
|
|
|
|
if (masterSecret == null) masterSecretUnion = new MasterSecretUnion(MasterSecretUtil.getAsymmetricMasterSecret(context, null));
|
|
|
|
else masterSecretUnion = new MasterSecretUnion(masterSecret);
|
|
|
|
|
|
|
|
handleMessage(masterSecretUnion, envelope, optionalSmsMessageId);
|
2014-11-08 11:35:58 -08:00
|
|
|
database.delete(messageId);
|
2014-11-03 15:16:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-07-06 17:36:49 -07:00
|
|
|
public boolean onShouldRetry(Exception exception) {
|
2014-11-11 19:57:53 -08:00
|
|
|
return false;
|
2014-11-03 15:16:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-11-11 19:57:53 -08:00
|
|
|
public void onCanceled() {
|
|
|
|
|
2014-11-03 15:16:04 -08:00
|
|
|
}
|
|
|
|
|
2016-03-23 10:34:41 -07:00
|
|
|
private void handleMessage(MasterSecretUnion masterSecret, SignalServiceEnvelope envelope, Optional<Long> smsMessageId) {
|
2014-11-03 15:16:04 -08:00
|
|
|
try {
|
2016-11-20 14:50:41 -08:00
|
|
|
GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context);
|
|
|
|
SignalProtocolStore axolotlStore = new SignalProtocolStoreImpl(context);
|
|
|
|
SignalServiceAddress localAddress = new SignalServiceAddress(TextSecurePreferences.getLocalNumber(context));
|
|
|
|
SignalServiceCipher cipher = new SignalServiceCipher(localAddress, axolotlStore);
|
2014-11-04 15:01:32 -08:00
|
|
|
|
2016-03-23 10:34:41 -07:00
|
|
|
SignalServiceContent content = cipher.decrypt(envelope);
|
2014-11-04 15:01:32 -08:00
|
|
|
|
2015-05-29 16:23:47 -07:00
|
|
|
if (content.getDataMessage().isPresent()) {
|
2016-03-23 10:34:41 -07:00
|
|
|
SignalServiceDataMessage message = content.getDataMessage().get();
|
2015-05-29 16:23:47 -07:00
|
|
|
|
|
|
|
if (message.isEndSession()) handleEndSessionMessage(masterSecret, envelope, message, smsMessageId);
|
|
|
|
else if (message.isGroupUpdate()) handleGroupMessage(masterSecret, envelope, message, smsMessageId);
|
2016-08-15 20:23:56 -07:00
|
|
|
else if (message.isExpirationUpdate()) handleExpirationUpdate(masterSecret, envelope, message, smsMessageId);
|
2015-05-29 16:23:47 -07:00
|
|
|
else if (message.getAttachments().isPresent()) handleMediaMessage(masterSecret, envelope, message, smsMessageId);
|
2017-08-27 17:59:06 -07:00
|
|
|
else if (message.getBody().isPresent()) handleTextMessage(masterSecret, envelope, message, smsMessageId);
|
2016-11-20 14:50:41 -08:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
if (message.getGroupInfo().isPresent() && groupDatabase.isUnknownGroup(GroupUtil.getEncodedId(message.getGroupInfo().get().getGroupId(), false))) {
|
2016-11-20 14:50:41 -08:00
|
|
|
handleUnknownGroupMessage(envelope, message.getGroupInfo().get());
|
|
|
|
}
|
2017-08-14 18:11:13 -07:00
|
|
|
|
2017-08-25 12:00:52 -07:00
|
|
|
if (message.getProfileKey().isPresent() && message.getProfileKey().get().length == 32) {
|
2017-08-14 18:11:13 -07:00
|
|
|
handleProfileKey(envelope, message);
|
|
|
|
}
|
2015-05-29 16:23:47 -07:00
|
|
|
} else if (content.getSyncMessage().isPresent()) {
|
2016-03-23 10:34:41 -07:00
|
|
|
SignalServiceSyncMessage syncMessage = content.getSyncMessage().get();
|
2015-05-29 16:23:47 -07:00
|
|
|
|
2017-06-06 18:03:09 -07:00
|
|
|
if (syncMessage.getSent().isPresent()) handleSynchronizeSentMessage(masterSecret, envelope, syncMessage.getSent().get(), smsMessageId);
|
|
|
|
else if (syncMessage.getRequest().isPresent()) handleSynchronizeRequestMessage(masterSecret, syncMessage.getRequest().get());
|
|
|
|
else if (syncMessage.getRead().isPresent()) handleSynchronizeReadMessage(masterSecret, syncMessage.getRead().get(), envelope.getTimestamp());
|
|
|
|
else if (syncMessage.getVerified().isPresent()) handleSynchronizeVerifiedMessage(masterSecret, syncMessage.getVerified().get());
|
2016-02-19 17:07:41 -08:00
|
|
|
else Log.w(TAG, "Contains no known sync types...");
|
2016-11-09 09:37:40 -08:00
|
|
|
} else if (content.getCallMessage().isPresent()) {
|
|
|
|
Log.w(TAG, "Got call message...");
|
|
|
|
SignalServiceCallMessage message = content.getCallMessage().get();
|
|
|
|
|
|
|
|
if (message.getOfferMessage().isPresent()) handleCallOfferMessage(envelope, message.getOfferMessage().get(), smsMessageId);
|
|
|
|
else if (message.getAnswerMessage().isPresent()) handleCallAnswerMessage(envelope, message.getAnswerMessage().get());
|
|
|
|
else if (message.getIceUpdateMessages().isPresent()) handleCallIceUpdateMessage(envelope, message.getIceUpdateMessages().get());
|
|
|
|
else if (message.getHangupMessage().isPresent()) handleCallHangupMessage(envelope, message.getHangupMessage().get(), smsMessageId);
|
2017-06-01 13:11:48 -07:00
|
|
|
else if (message.getBusyMessage().isPresent()) handleCallBusyMessage(envelope, message.getBusyMessage().get());
|
2017-09-15 22:38:53 -07:00
|
|
|
} else if (content.getReceiptMessage().isPresent()) {
|
|
|
|
SignalServiceReceiptMessage message = content.getReceiptMessage().get();
|
|
|
|
|
|
|
|
if (message.isReadReceipt()) handleReadReceipt(envelope, message);
|
|
|
|
else if (message.isDeliveryReceipt()) handleDeliveryReceipt(envelope, message);
|
2016-11-09 09:37:40 -08:00
|
|
|
} else {
|
|
|
|
Log.w(TAG, "Got unrecognized message...");
|
2015-05-29 16:23:47 -07:00
|
|
|
}
|
2014-11-11 20:29:55 -08:00
|
|
|
|
2016-03-23 10:34:41 -07:00
|
|
|
if (envelope.isPreKeySignalMessage()) {
|
2014-11-11 20:29:55 -08:00
|
|
|
ApplicationContext.getInstance(context).getJobManager().add(new RefreshPreKeysJob(context));
|
|
|
|
}
|
2014-11-03 15:16:04 -08:00
|
|
|
} catch (InvalidVersionException e) {
|
|
|
|
Log.w(TAG, e);
|
2015-01-15 13:35:35 -08:00
|
|
|
handleInvalidVersionMessage(masterSecret, envelope, smsMessageId);
|
2015-03-03 11:44:49 -08:00
|
|
|
} catch (InvalidMessageException | InvalidKeyIdException | InvalidKeyException | MmsException e) {
|
2014-11-03 15:16:04 -08:00
|
|
|
Log.w(TAG, e);
|
2015-01-15 13:35:35 -08:00
|
|
|
handleCorruptMessage(masterSecret, envelope, smsMessageId);
|
2014-11-03 15:16:04 -08:00
|
|
|
} catch (NoSessionException e) {
|
|
|
|
Log.w(TAG, e);
|
2015-01-15 13:35:35 -08:00
|
|
|
handleNoSessionMessage(masterSecret, envelope, smsMessageId);
|
2014-11-03 15:16:04 -08:00
|
|
|
} catch (LegacyMessageException e) {
|
|
|
|
Log.w(TAG, e);
|
2015-01-15 13:35:35 -08:00
|
|
|
handleLegacyMessage(masterSecret, envelope, smsMessageId);
|
2014-11-03 15:16:04 -08:00
|
|
|
} catch (DuplicateMessageException e) {
|
|
|
|
Log.w(TAG, e);
|
2015-01-15 13:35:35 -08:00
|
|
|
handleDuplicateMessage(masterSecret, envelope, smsMessageId);
|
2014-11-03 15:16:04 -08:00
|
|
|
} catch (UntrustedIdentityException e) {
|
|
|
|
Log.w(TAG, e);
|
2015-01-15 13:35:35 -08:00
|
|
|
handleUntrustedIdentityMessage(masterSecret, envelope, smsMessageId);
|
2014-11-03 15:16:04 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-09 09:37:40 -08:00
|
|
|
private void handleCallOfferMessage(@NonNull SignalServiceEnvelope envelope,
|
|
|
|
@NonNull OfferMessage message,
|
|
|
|
@NonNull Optional<Long> smsMessageId)
|
|
|
|
{
|
|
|
|
Log.w(TAG, "handleCallOfferMessage...");
|
|
|
|
|
|
|
|
if (smsMessageId.isPresent()) {
|
|
|
|
SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
|
|
|
|
database.markAsMissedCall(smsMessageId.get());
|
|
|
|
} else {
|
|
|
|
Intent intent = new Intent(context, WebRtcCallService.class);
|
|
|
|
intent.setAction(WebRtcCallService.ACTION_INCOMING_CALL);
|
|
|
|
intent.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId());
|
2017-07-26 09:59:15 -07:00
|
|
|
intent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, Address.fromExternal(context, envelope.getSource()));
|
2016-11-09 09:37:40 -08:00
|
|
|
intent.putExtra(WebRtcCallService.EXTRA_REMOTE_DESCRIPTION, message.getDescription());
|
|
|
|
intent.putExtra(WebRtcCallService.EXTRA_TIMESTAMP, envelope.getTimestamp());
|
|
|
|
context.startService(intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleCallAnswerMessage(@NonNull SignalServiceEnvelope envelope,
|
|
|
|
@NonNull AnswerMessage message)
|
|
|
|
{
|
|
|
|
Log.w(TAG, "handleCallAnswerMessage...");
|
|
|
|
Intent intent = new Intent(context, WebRtcCallService.class);
|
|
|
|
intent.setAction(WebRtcCallService.ACTION_RESPONSE_MESSAGE);
|
|
|
|
intent.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId());
|
2017-07-26 09:59:15 -07:00
|
|
|
intent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, Address.fromExternal(context, envelope.getSource()));
|
2016-11-09 09:37:40 -08:00
|
|
|
intent.putExtra(WebRtcCallService.EXTRA_REMOTE_DESCRIPTION, message.getDescription());
|
|
|
|
context.startService(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleCallIceUpdateMessage(@NonNull SignalServiceEnvelope envelope,
|
|
|
|
@NonNull List<IceUpdateMessage> messages)
|
|
|
|
{
|
|
|
|
Log.w(TAG, "handleCallIceUpdateMessage... " + messages.size());
|
|
|
|
for (IceUpdateMessage message : messages) {
|
|
|
|
Intent intent = new Intent(context, WebRtcCallService.class);
|
|
|
|
intent.setAction(WebRtcCallService.ACTION_ICE_MESSAGE);
|
|
|
|
intent.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId());
|
2017-07-26 09:59:15 -07:00
|
|
|
intent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, Address.fromExternal(context, envelope.getSource()));
|
2016-11-09 09:37:40 -08:00
|
|
|
intent.putExtra(WebRtcCallService.EXTRA_ICE_SDP, message.getSdp());
|
|
|
|
intent.putExtra(WebRtcCallService.EXTRA_ICE_SDP_MID, message.getSdpMid());
|
|
|
|
intent.putExtra(WebRtcCallService.EXTRA_ICE_SDP_LINE_INDEX, message.getSdpMLineIndex());
|
|
|
|
context.startService(intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleCallHangupMessage(@NonNull SignalServiceEnvelope envelope,
|
|
|
|
@NonNull HangupMessage message,
|
|
|
|
@NonNull Optional<Long> smsMessageId)
|
|
|
|
{
|
|
|
|
Log.w(TAG, "handleCallHangupMessage");
|
|
|
|
if (smsMessageId.isPresent()) {
|
|
|
|
DatabaseFactory.getSmsDatabase(context).markAsMissedCall(smsMessageId.get());
|
|
|
|
} else {
|
|
|
|
Intent intent = new Intent(context, WebRtcCallService.class);
|
|
|
|
intent.setAction(WebRtcCallService.ACTION_REMOTE_HANGUP);
|
|
|
|
intent.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId());
|
2017-07-26 09:59:15 -07:00
|
|
|
intent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, Address.fromExternal(context, envelope.getSource()));
|
2016-11-09 09:37:40 -08:00
|
|
|
context.startService(intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-01 13:11:48 -07:00
|
|
|
private void handleCallBusyMessage(@NonNull SignalServiceEnvelope envelope,
|
|
|
|
@NonNull BusyMessage message)
|
|
|
|
{
|
|
|
|
Intent intent = new Intent(context, WebRtcCallService.class);
|
|
|
|
intent.setAction(WebRtcCallService.ACTION_REMOTE_BUSY);
|
|
|
|
intent.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId());
|
2017-07-26 09:59:15 -07:00
|
|
|
intent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, Address.fromExternal(context, envelope.getSource()));
|
2017-06-01 13:11:48 -07:00
|
|
|
context.startService(intent);
|
|
|
|
}
|
|
|
|
|
2016-03-23 10:34:41 -07:00
|
|
|
private void handleEndSessionMessage(@NonNull MasterSecretUnion masterSecret,
|
|
|
|
@NonNull SignalServiceEnvelope envelope,
|
|
|
|
@NonNull SignalServiceDataMessage message,
|
|
|
|
@NonNull Optional<Long> smsMessageId)
|
2014-11-04 15:01:32 -08:00
|
|
|
{
|
2015-01-15 13:35:35 -08:00
|
|
|
EncryptingSmsDatabase smsDatabase = DatabaseFactory.getEncryptingSmsDatabase(context);
|
2017-07-26 09:59:15 -07:00
|
|
|
IncomingTextMessage incomingTextMessage = new IncomingTextMessage(Address.fromExternal(context, envelope.getSource()),
|
2015-01-15 13:35:35 -08:00
|
|
|
envelope.getSourceDevice(),
|
|
|
|
message.getTimestamp(),
|
2016-08-15 20:23:56 -07:00
|
|
|
"", Optional.<SignalServiceGroup>absent(), 0);
|
2015-01-15 13:35:35 -08:00
|
|
|
|
2017-01-22 13:52:36 -08:00
|
|
|
Long threadId;
|
2015-01-15 13:35:35 -08:00
|
|
|
|
2015-05-18 15:16:27 -07:00
|
|
|
if (!smsMessageId.isPresent()) {
|
2015-01-15 13:35:35 -08:00
|
|
|
IncomingEndSessionMessage incomingEndSessionMessage = new IncomingEndSessionMessage(incomingTextMessage);
|
2017-01-22 13:52:36 -08:00
|
|
|
Optional<InsertResult> insertResult = smsDatabase.insertMessageInbox(masterSecret, incomingEndSessionMessage);
|
2015-07-06 17:36:49 -07:00
|
|
|
|
2017-01-22 13:52:36 -08:00
|
|
|
if (insertResult.isPresent()) threadId = insertResult.get().getThreadId();
|
|
|
|
else threadId = null;
|
2015-01-15 13:35:35 -08:00
|
|
|
} else {
|
2015-05-18 15:16:27 -07:00
|
|
|
smsDatabase.markAsEndSession(smsMessageId.get());
|
|
|
|
threadId = smsDatabase.getThreadIdForMessage(smsMessageId.get());
|
2015-01-15 13:35:35 -08:00
|
|
|
}
|
2014-11-03 15:16:04 -08:00
|
|
|
|
2017-01-22 13:52:36 -08:00
|
|
|
if (threadId != null) {
|
|
|
|
SessionStore sessionStore = new TextSecureSessionStore(context);
|
|
|
|
sessionStore.deleteAllSessions(envelope.getSource());
|
2014-11-03 15:16:04 -08:00
|
|
|
|
2017-01-22 13:52:36 -08:00
|
|
|
SecurityEvent.broadcastSecurityUpdateEvent(context);
|
|
|
|
MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), threadId);
|
|
|
|
}
|
2014-11-03 15:16:04 -08:00
|
|
|
}
|
|
|
|
|
2016-02-04 23:02:26 +01:00
|
|
|
private long handleSynchronizeSentEndSessionMessage(@NonNull MasterSecretUnion masterSecret,
|
|
|
|
@NonNull SentTranscriptMessage message,
|
|
|
|
@NonNull Optional<Long> smsMessageId)
|
|
|
|
{
|
|
|
|
EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
|
2017-08-01 08:56:00 -07:00
|
|
|
Recipient recipient = getSyncMessageDestination(message);
|
|
|
|
OutgoingTextMessage outgoingTextMessage = new OutgoingTextMessage(recipient, "", -1);
|
2016-02-04 23:02:26 +01:00
|
|
|
OutgoingEndSessionMessage outgoingEndSessionMessage = new OutgoingEndSessionMessage(outgoingTextMessage);
|
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient);
|
2016-02-04 23:02:26 +01:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
if (!recipient.isGroupRecipient()) {
|
2016-02-04 23:02:26 +01:00
|
|
|
SessionStore sessionStore = new TextSecureSessionStore(context);
|
2017-08-01 08:56:00 -07:00
|
|
|
sessionStore.deleteAllSessions(recipient.getAddress().toPhoneString());
|
2016-02-04 23:02:26 +01:00
|
|
|
|
|
|
|
SecurityEvent.broadcastSecurityUpdateEvent(context);
|
|
|
|
|
|
|
|
long messageId = database.insertMessageOutbox(masterSecret, threadId, outgoingEndSessionMessage,
|
2017-04-22 16:29:26 -07:00
|
|
|
false, message.getTimestamp(), null);
|
2017-03-14 15:47:08 -07:00
|
|
|
database.markAsSent(messageId, true);
|
2016-02-04 23:02:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (smsMessageId.isPresent()) {
|
|
|
|
database.deleteMessage(smsMessageId.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
return threadId;
|
|
|
|
}
|
|
|
|
|
2015-07-06 17:36:49 -07:00
|
|
|
private void handleGroupMessage(@NonNull MasterSecretUnion masterSecret,
|
2016-03-23 10:34:41 -07:00
|
|
|
@NonNull SignalServiceEnvelope envelope,
|
|
|
|
@NonNull SignalServiceDataMessage message,
|
2015-07-06 17:36:49 -07:00
|
|
|
@NonNull Optional<Long> smsMessageId)
|
|
|
|
{
|
2015-10-15 17:10:54 -07:00
|
|
|
GroupMessageProcessor.process(context, masterSecret, envelope, message, false);
|
2015-01-15 13:35:35 -08:00
|
|
|
|
2015-05-18 15:16:27 -07:00
|
|
|
if (smsMessageId.isPresent()) {
|
|
|
|
DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get());
|
2015-01-15 13:35:35 -08:00
|
|
|
}
|
2014-11-03 15:16:04 -08:00
|
|
|
}
|
|
|
|
|
2016-11-20 14:50:41 -08:00
|
|
|
private void handleUnknownGroupMessage(@NonNull SignalServiceEnvelope envelope,
|
|
|
|
@NonNull SignalServiceGroup group)
|
|
|
|
{
|
|
|
|
ApplicationContext.getInstance(context)
|
|
|
|
.getJobManager()
|
|
|
|
.add(new RequestGroupInfoJob(context, envelope.getSource(), group.getGroupId()));
|
|
|
|
}
|
|
|
|
|
2016-08-15 20:23:56 -07:00
|
|
|
private void handleExpirationUpdate(@NonNull MasterSecretUnion masterSecret,
|
|
|
|
@NonNull SignalServiceEnvelope envelope,
|
|
|
|
@NonNull SignalServiceDataMessage message,
|
|
|
|
@NonNull Optional<Long> smsMessageId)
|
|
|
|
throws MmsException
|
|
|
|
{
|
|
|
|
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
|
2017-08-01 08:56:00 -07:00
|
|
|
Recipient recipient = getMessageDestination(envelope, message);
|
2017-07-26 09:59:15 -07:00
|
|
|
IncomingMediaMessage mediaMessage = new IncomingMediaMessage(masterSecret,
|
|
|
|
Address.fromExternal(context, envelope.getSource()),
|
|
|
|
message.getTimestamp(), -1,
|
2016-08-15 20:23:56 -07:00
|
|
|
message.getExpiresInSeconds() * 1000, true,
|
|
|
|
Optional.fromNullable(envelope.getRelay()),
|
|
|
|
Optional.<String>absent(), message.getGroupInfo(),
|
|
|
|
Optional.<List<SignalServiceAttachment>>absent());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
database.insertSecureDecryptedMessageInbox(masterSecret, mediaMessage, -1);
|
|
|
|
|
2017-08-21 18:47:37 -07:00
|
|
|
DatabaseFactory.getRecipientDatabase(context).setExpireMessages(recipient, message.getExpiresInSeconds());
|
2016-08-15 20:23:56 -07:00
|
|
|
|
|
|
|
if (smsMessageId.isPresent()) {
|
|
|
|
DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-06 18:03:09 -07:00
|
|
|
private void handleSynchronizeVerifiedMessage(@NonNull MasterSecretUnion masterSecret,
|
2017-06-23 13:57:38 -07:00
|
|
|
@NonNull VerifiedMessage verifiedMessage)
|
2017-06-06 18:03:09 -07:00
|
|
|
{
|
2017-06-23 13:57:38 -07:00
|
|
|
IdentityUtil.processVerifiedMessage(context, masterSecret, verifiedMessage);
|
2017-06-06 18:03:09 -07:00
|
|
|
}
|
|
|
|
|
2015-07-06 17:36:49 -07:00
|
|
|
private void handleSynchronizeSentMessage(@NonNull MasterSecretUnion masterSecret,
|
2016-03-23 10:34:41 -07:00
|
|
|
@NonNull SignalServiceEnvelope envelope,
|
2015-07-06 17:36:49 -07:00
|
|
|
@NonNull SentTranscriptMessage message,
|
|
|
|
@NonNull Optional<Long> smsMessageId)
|
2014-11-03 15:16:04 -08:00
|
|
|
throws MmsException
|
|
|
|
{
|
2016-11-20 14:50:41 -08:00
|
|
|
GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context);
|
|
|
|
|
2015-11-24 16:01:21 -08:00
|
|
|
Long threadId;
|
|
|
|
|
2016-02-04 23:02:26 +01:00
|
|
|
if (message.getMessage().isEndSession()) {
|
|
|
|
threadId = handleSynchronizeSentEndSessionMessage(masterSecret, message, smsMessageId);
|
|
|
|
} else if (message.getMessage().isGroupUpdate()) {
|
2015-11-24 16:01:21 -08:00
|
|
|
threadId = GroupMessageProcessor.process(context, masterSecret, envelope, message.getMessage(), true);
|
2016-08-15 20:23:56 -07:00
|
|
|
} else if (message.getMessage().isExpirationUpdate()) {
|
|
|
|
threadId = handleSynchronizeSentExpirationUpdate(masterSecret, message, smsMessageId);
|
2015-10-15 17:10:54 -07:00
|
|
|
} else if (message.getMessage().getAttachments().isPresent()) {
|
2015-11-24 16:01:21 -08:00
|
|
|
threadId = handleSynchronizeSentMediaMessage(masterSecret, message, smsMessageId);
|
2014-11-03 15:16:04 -08:00
|
|
|
} else {
|
2015-11-24 16:01:21 -08:00
|
|
|
threadId = handleSynchronizeSentTextMessage(masterSecret, message, smsMessageId);
|
|
|
|
}
|
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
if (message.getMessage().getGroupInfo().isPresent() && groupDatabase.isUnknownGroup(GroupUtil.getEncodedId(message.getMessage().getGroupInfo().get().getGroupId(), false))) {
|
2016-11-20 14:50:41 -08:00
|
|
|
handleUnknownGroupMessage(envelope, message.getMessage().getGroupInfo().get());
|
|
|
|
}
|
|
|
|
|
2017-08-28 17:57:07 -07:00
|
|
|
if (message.getMessage().getProfileKey().isPresent()) {
|
|
|
|
Recipient recipient = null;
|
|
|
|
|
|
|
|
if (message.getDestination().isPresent()) recipient = Recipient.from(context, Address.fromExternal(context, message.getDestination().get()), false);
|
|
|
|
else if (message.getMessage().getGroupInfo().isPresent()) recipient = Recipient.from(context, Address.fromSerialized(GroupUtil.getEncodedId(message.getMessage().getGroupInfo().get().getGroupId(), false)), false);
|
|
|
|
|
|
|
|
|
|
|
|
if (recipient != null && !recipient.isSystemContact() && !recipient.isProfileSharing()) {
|
|
|
|
DatabaseFactory.getRecipientDatabase(context).setProfileSharing(recipient, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-24 16:01:21 -08:00
|
|
|
if (threadId != null) {
|
2017-02-22 15:05:35 -08:00
|
|
|
DatabaseFactory.getThreadDatabase(getContext()).setRead(threadId, true);
|
2015-11-24 16:01:21 -08:00
|
|
|
MessageNotifier.updateNotification(getContext(), masterSecret.getMasterSecret().orNull());
|
2014-11-03 15:16:04 -08:00
|
|
|
}
|
2016-11-24 08:09:34 -08:00
|
|
|
|
|
|
|
MessageNotifier.setLastDesktopActivityTimestamp(message.getTimestamp());
|
2015-05-29 16:23:47 -07:00
|
|
|
}
|
|
|
|
|
2015-07-06 17:36:49 -07:00
|
|
|
private void handleSynchronizeRequestMessage(@NonNull MasterSecretUnion masterSecret,
|
|
|
|
@NonNull RequestMessage message)
|
|
|
|
{
|
2015-06-19 22:02:10 -07:00
|
|
|
if (message.isContactsRequest()) {
|
|
|
|
ApplicationContext.getInstance(context)
|
|
|
|
.getJobManager()
|
|
|
|
.add(new MultiDeviceContactUpdateJob(getContext()));
|
|
|
|
}
|
2015-06-22 14:49:04 -07:00
|
|
|
|
|
|
|
if (message.isGroupsRequest()) {
|
|
|
|
ApplicationContext.getInstance(context)
|
|
|
|
.getJobManager()
|
|
|
|
.add(new MultiDeviceGroupUpdateJob(getContext()));
|
|
|
|
}
|
2016-08-26 16:53:23 -07:00
|
|
|
|
|
|
|
if (message.isBlockedListRequest()) {
|
|
|
|
ApplicationContext.getInstance(context)
|
|
|
|
.getJobManager()
|
|
|
|
.add(new MultiDeviceBlockedUpdateJob(getContext()));
|
|
|
|
}
|
2015-06-19 22:02:10 -07:00
|
|
|
}
|
|
|
|
|
2016-02-19 17:07:41 -08:00
|
|
|
private void handleSynchronizeReadMessage(@NonNull MasterSecretUnion masterSecret,
|
2016-10-02 12:08:30 -07:00
|
|
|
@NonNull List<ReadMessage> readMessages,
|
|
|
|
long envelopeTimestamp)
|
2016-02-19 17:07:41 -08:00
|
|
|
{
|
|
|
|
for (ReadMessage readMessage : readMessages) {
|
2017-07-26 09:59:15 -07:00
|
|
|
List<Pair<Long, Long>> expiringText = DatabaseFactory.getSmsDatabase(context).setTimestampRead(new SyncMessageId(Address.fromExternal(context, readMessage.getSender()), readMessage.getTimestamp()), envelopeTimestamp);
|
|
|
|
List<Pair<Long, Long>> expiringMedia = DatabaseFactory.getMmsDatabase(context).setTimestampRead(new SyncMessageId(Address.fromExternal(context, readMessage.getSender()), readMessage.getTimestamp()), envelopeTimestamp);
|
2016-10-02 12:08:30 -07:00
|
|
|
|
|
|
|
for (Pair<Long, Long> expiringMessage : expiringText) {
|
|
|
|
ApplicationContext.getInstance(context)
|
|
|
|
.getExpiringMessageManager()
|
|
|
|
.scheduleDeletion(expiringMessage.first, false, envelopeTimestamp, expiringMessage.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Pair<Long, Long> expiringMessage : expiringMedia) {
|
|
|
|
ApplicationContext.getInstance(context)
|
|
|
|
.getExpiringMessageManager()
|
|
|
|
.scheduleDeletion(expiringMessage.first, true, envelopeTimestamp, expiringMessage.second);
|
|
|
|
}
|
2016-02-19 17:07:41 -08:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:09:34 -08:00
|
|
|
MessageNotifier.setLastDesktopActivityTimestamp(envelopeTimestamp);
|
|
|
|
MessageNotifier.cancelDelayedNotifications();
|
2016-02-19 17:07:41 -08:00
|
|
|
MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull());
|
|
|
|
}
|
|
|
|
|
2015-07-06 17:36:49 -07:00
|
|
|
private void handleMediaMessage(@NonNull MasterSecretUnion masterSecret,
|
2016-03-23 10:34:41 -07:00
|
|
|
@NonNull SignalServiceEnvelope envelope,
|
|
|
|
@NonNull SignalServiceDataMessage message,
|
2015-07-06 17:36:49 -07:00
|
|
|
@NonNull Optional<Long> smsMessageId)
|
2015-05-29 16:23:47 -07:00
|
|
|
throws MmsException
|
|
|
|
{
|
|
|
|
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
|
2017-08-01 08:56:00 -07:00
|
|
|
Recipient recipient = getMessageDestination(envelope, message);
|
2017-07-26 09:59:15 -07:00
|
|
|
IncomingMediaMessage mediaMessage = new IncomingMediaMessage(masterSecret,
|
|
|
|
Address.fromExternal(context, envelope.getSource()),
|
|
|
|
message.getTimestamp(), -1,
|
2016-08-15 20:23:56 -07:00
|
|
|
message.getExpiresInSeconds() * 1000, false,
|
2015-05-29 16:23:47 -07:00
|
|
|
Optional.fromNullable(envelope.getRelay()),
|
|
|
|
message.getBody(),
|
|
|
|
message.getGroupInfo(),
|
|
|
|
message.getAttachments());
|
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
if (message.getExpiresInSeconds() != recipient.getExpireMessages()) {
|
2016-08-15 20:23:56 -07:00
|
|
|
handleExpirationUpdate(masterSecret, envelope, message, Optional.<Long>absent());
|
|
|
|
}
|
|
|
|
|
2017-01-22 13:52:36 -08:00
|
|
|
Optional<InsertResult> insertResult = database.insertSecureDecryptedMessageInbox(masterSecret, mediaMessage, -1);
|
2014-11-03 15:16:04 -08:00
|
|
|
|
2017-01-22 13:52:36 -08:00
|
|
|
if (insertResult.isPresent()) {
|
2017-03-28 12:05:30 -07:00
|
|
|
List<DatabaseAttachment> attachments = DatabaseFactory.getAttachmentDatabase(context).getAttachmentsForMessage(null, insertResult.get().getMessageId());
|
2014-11-03 15:16:04 -08:00
|
|
|
|
2017-01-22 13:52:36 -08:00
|
|
|
for (DatabaseAttachment attachment : attachments) {
|
|
|
|
ApplicationContext.getInstance(context)
|
|
|
|
.getJobManager()
|
2017-07-21 15:59:27 -07:00
|
|
|
.add(new AttachmentDownloadJob(context, insertResult.get().getMessageId(), attachment.getAttachmentId(), false));
|
2017-03-28 12:05:30 -07:00
|
|
|
|
|
|
|
if (!masterSecret.getMasterSecret().isPresent()) {
|
|
|
|
ApplicationContext.getInstance(context)
|
|
|
|
.getJobManager()
|
|
|
|
.add(new AttachmentFileNameJob(context, masterSecret.getAsymmetricMasterSecret().get(), attachment, mediaMessage));
|
|
|
|
}
|
2017-01-22 13:52:36 -08:00
|
|
|
}
|
2015-01-15 13:35:35 -08:00
|
|
|
|
2017-01-22 13:52:36 -08:00
|
|
|
if (smsMessageId.isPresent()) {
|
|
|
|
DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), insertResult.get().getThreadId());
|
|
|
|
}
|
2014-11-03 15:16:04 -08:00
|
|
|
}
|
|
|
|
|
2016-08-15 20:23:56 -07:00
|
|
|
private long handleSynchronizeSentExpirationUpdate(@NonNull MasterSecretUnion masterSecret,
|
|
|
|
@NonNull SentTranscriptMessage message,
|
|
|
|
@NonNull Optional<Long> smsMessageId)
|
|
|
|
throws MmsException
|
|
|
|
{
|
|
|
|
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
|
2017-08-01 08:56:00 -07:00
|
|
|
Recipient recipient = getSyncMessageDestination(message);
|
2016-08-15 20:23:56 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
OutgoingExpirationUpdateMessage expirationUpdateMessage = new OutgoingExpirationUpdateMessage(recipient,
|
2016-08-15 20:23:56 -07:00
|
|
|
message.getTimestamp(),
|
|
|
|
message.getMessage().getExpiresInSeconds() * 1000);
|
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient);
|
2017-04-22 16:29:26 -07:00
|
|
|
long messageId = database.insertMessageOutbox(masterSecret, expirationUpdateMessage, threadId, false, null);
|
2016-08-15 20:23:56 -07:00
|
|
|
|
2016-12-21 09:49:01 -08:00
|
|
|
database.markAsSent(messageId, true);
|
2016-08-15 20:23:56 -07:00
|
|
|
|
2017-08-21 18:47:37 -07:00
|
|
|
DatabaseFactory.getRecipientDatabase(context).setExpireMessages(recipient, message.getMessage().getExpiresInSeconds());
|
2016-08-15 20:23:56 -07:00
|
|
|
|
|
|
|
if (smsMessageId.isPresent()) {
|
|
|
|
DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
return threadId;
|
|
|
|
}
|
|
|
|
|
2015-11-24 16:01:21 -08:00
|
|
|
private long handleSynchronizeSentMediaMessage(@NonNull MasterSecretUnion masterSecret,
|
2015-07-06 17:36:49 -07:00
|
|
|
@NonNull SentTranscriptMessage message,
|
|
|
|
@NonNull Optional<Long> smsMessageId)
|
2015-05-29 16:23:47 -07:00
|
|
|
throws MmsException
|
|
|
|
{
|
|
|
|
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
|
2017-08-01 08:56:00 -07:00
|
|
|
Recipient recipients = getSyncMessageDestination(message);
|
2015-10-12 18:25:05 -07:00
|
|
|
OutgoingMediaMessage mediaMessage = new OutgoingMediaMessage(recipients, message.getMessage().getBody().orNull(),
|
|
|
|
PointerAttachment.forPointers(masterSecret, message.getMessage().getAttachments()),
|
2016-08-15 20:23:56 -07:00
|
|
|
message.getTimestamp(), -1,
|
|
|
|
message.getMessage().getExpiresInSeconds() * 1000,
|
|
|
|
ThreadDatabase.DistributionTypes.DEFAULT);
|
2015-05-29 16:23:47 -07:00
|
|
|
|
|
|
|
mediaMessage = new OutgoingSecureMediaMessage(mediaMessage);
|
|
|
|
|
2016-08-15 20:23:56 -07:00
|
|
|
if (recipients.getExpireMessages() != message.getMessage().getExpiresInSeconds()) {
|
|
|
|
handleSynchronizeSentExpirationUpdate(masterSecret, message, Optional.<Long>absent());
|
|
|
|
}
|
|
|
|
|
2015-05-29 16:23:47 -07:00
|
|
|
long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
|
2017-04-22 16:29:26 -07:00
|
|
|
long messageId = database.insertMessageOutbox(masterSecret, mediaMessage, threadId, false, null);
|
2015-05-29 16:23:47 -07:00
|
|
|
|
2016-12-21 09:49:01 -08:00
|
|
|
database.markAsSent(messageId, true);
|
2015-05-29 16:23:47 -07:00
|
|
|
|
2017-03-28 12:05:30 -07:00
|
|
|
for (DatabaseAttachment attachment : DatabaseFactory.getAttachmentDatabase(context).getAttachmentsForMessage(null, messageId)) {
|
2015-08-24 15:24:31 -07:00
|
|
|
ApplicationContext.getInstance(context)
|
|
|
|
.getJobManager()
|
2017-07-21 15:59:27 -07:00
|
|
|
.add(new AttachmentDownloadJob(context, messageId, attachment.getAttachmentId(), false));
|
2015-08-24 15:24:31 -07:00
|
|
|
}
|
2015-05-29 16:23:47 -07:00
|
|
|
|
|
|
|
if (smsMessageId.isPresent()) {
|
|
|
|
DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get());
|
|
|
|
}
|
2015-11-24 16:01:21 -08:00
|
|
|
|
2016-08-15 20:23:56 -07:00
|
|
|
if (message.getMessage().getExpiresInSeconds() > 0) {
|
|
|
|
database.markExpireStarted(messageId, message.getExpirationStartTimestamp());
|
|
|
|
ApplicationContext.getInstance(context)
|
|
|
|
.getExpiringMessageManager()
|
|
|
|
.scheduleDeletion(messageId, true,
|
|
|
|
message.getExpirationStartTimestamp(),
|
|
|
|
message.getMessage().getExpiresInSeconds());
|
|
|
|
}
|
|
|
|
|
2015-11-24 16:01:21 -08:00
|
|
|
return threadId;
|
2015-05-29 16:23:47 -07:00
|
|
|
}
|
|
|
|
|
2015-07-06 17:36:49 -07:00
|
|
|
private void handleTextMessage(@NonNull MasterSecretUnion masterSecret,
|
2016-03-23 10:34:41 -07:00
|
|
|
@NonNull SignalServiceEnvelope envelope,
|
|
|
|
@NonNull SignalServiceDataMessage message,
|
2015-07-06 17:36:49 -07:00
|
|
|
@NonNull Optional<Long> smsMessageId)
|
2016-08-15 20:23:56 -07:00
|
|
|
throws MmsException
|
2015-01-15 13:35:35 -08:00
|
|
|
{
|
2016-08-15 20:23:56 -07:00
|
|
|
EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
|
|
|
|
String body = message.getBody().isPresent() ? message.getBody().get() : "";
|
2017-08-01 08:56:00 -07:00
|
|
|
Recipient recipient = getMessageDestination(envelope, message);
|
2016-08-15 20:23:56 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
if (message.getExpiresInSeconds() != recipient.getExpireMessages()) {
|
2016-08-15 20:23:56 -07:00
|
|
|
handleExpirationUpdate(masterSecret, envelope, message, Optional.<Long>absent());
|
|
|
|
}
|
2015-05-29 16:23:47 -07:00
|
|
|
|
2017-01-22 13:52:36 -08:00
|
|
|
Long threadId;
|
2015-01-15 13:35:35 -08:00
|
|
|
|
2015-12-10 04:34:20 -08:00
|
|
|
if (smsMessageId.isPresent() && !message.getGroupInfo().isPresent()) {
|
2017-01-22 13:52:36 -08:00
|
|
|
threadId = database.updateBundleMessageBody(masterSecret, smsMessageId.get(), body).second;
|
2015-01-15 13:35:35 -08:00
|
|
|
} else {
|
2017-07-26 09:59:15 -07:00
|
|
|
IncomingTextMessage textMessage = new IncomingTextMessage(Address.fromExternal(context, envelope.getSource()),
|
2015-05-29 16:23:47 -07:00
|
|
|
envelope.getSourceDevice(),
|
|
|
|
message.getTimestamp(), body,
|
2016-08-15 20:23:56 -07:00
|
|
|
message.getGroupInfo(),
|
|
|
|
message.getExpiresInSeconds() * 1000);
|
2015-05-29 16:23:47 -07:00
|
|
|
|
|
|
|
textMessage = new IncomingEncryptedMessage(textMessage, body);
|
2017-01-22 13:52:36 -08:00
|
|
|
Optional<InsertResult> insertResult = database.insertMessageInbox(masterSecret, textMessage);
|
|
|
|
|
|
|
|
if (insertResult.isPresent()) threadId = insertResult.get().getThreadId();
|
|
|
|
else threadId = null;
|
2015-12-10 04:34:20 -08:00
|
|
|
|
|
|
|
if (smsMessageId.isPresent()) database.deleteMessage(smsMessageId.get());
|
2015-01-15 13:35:35 -08:00
|
|
|
}
|
2015-05-18 15:16:27 -07:00
|
|
|
|
2017-01-22 13:52:36 -08:00
|
|
|
if (threadId != null) {
|
|
|
|
MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), threadId);
|
|
|
|
}
|
2014-11-03 15:16:04 -08:00
|
|
|
}
|
|
|
|
|
2015-11-24 16:01:21 -08:00
|
|
|
private long handleSynchronizeSentTextMessage(@NonNull MasterSecretUnion masterSecret,
|
2015-07-06 17:36:49 -07:00
|
|
|
@NonNull SentTranscriptMessage message,
|
|
|
|
@NonNull Optional<Long> smsMessageId)
|
2016-08-15 20:23:56 -07:00
|
|
|
throws MmsException
|
2015-05-29 16:23:47 -07:00
|
|
|
{
|
|
|
|
EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
|
2017-08-01 08:56:00 -07:00
|
|
|
Recipient recipient = getSyncMessageDestination(message);
|
2015-05-29 16:23:47 -07:00
|
|
|
String body = message.getMessage().getBody().or("");
|
2016-08-15 20:23:56 -07:00
|
|
|
long expiresInMillis = message.getMessage().getExpiresInSeconds() * 1000;
|
2017-08-01 08:56:00 -07:00
|
|
|
OutgoingTextMessage outgoingTextMessage = new OutgoingTextMessage(recipient, body, expiresInMillis, -1);
|
2016-08-15 20:23:56 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
if (recipient.getExpireMessages() != message.getMessage().getExpiresInSeconds()) {
|
2016-08-15 20:23:56 -07:00
|
|
|
handleSynchronizeSentExpirationUpdate(masterSecret, message, Optional.<Long>absent());
|
|
|
|
}
|
2015-05-29 16:23:47 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient);
|
2017-04-22 16:29:26 -07:00
|
|
|
long messageId = database.insertMessageOutbox(masterSecret, threadId, outgoingTextMessage, false, message.getTimestamp(), null);
|
2015-05-29 16:23:47 -07:00
|
|
|
|
2016-12-21 09:49:01 -08:00
|
|
|
database.markAsSent(messageId, true);
|
2015-05-29 16:23:47 -07:00
|
|
|
|
|
|
|
if (smsMessageId.isPresent()) {
|
|
|
|
database.deleteMessage(smsMessageId.get());
|
|
|
|
}
|
2015-11-24 16:01:21 -08:00
|
|
|
|
2016-08-15 20:23:56 -07:00
|
|
|
if (expiresInMillis > 0) {
|
|
|
|
database.markExpireStarted(messageId, message.getExpirationStartTimestamp());
|
|
|
|
ApplicationContext.getInstance(context)
|
|
|
|
.getExpiringMessageManager()
|
|
|
|
.scheduleDeletion(messageId, false, message.getExpirationStartTimestamp(), expiresInMillis);
|
|
|
|
}
|
|
|
|
|
2015-11-24 16:01:21 -08:00
|
|
|
return threadId;
|
2015-05-29 16:23:47 -07:00
|
|
|
}
|
|
|
|
|
2015-07-06 17:36:49 -07:00
|
|
|
private void handleInvalidVersionMessage(@NonNull MasterSecretUnion masterSecret,
|
2016-03-23 10:34:41 -07:00
|
|
|
@NonNull SignalServiceEnvelope envelope,
|
2015-07-06 17:36:49 -07:00
|
|
|
@NonNull Optional<Long> smsMessageId)
|
|
|
|
{
|
2015-01-15 13:35:35 -08:00
|
|
|
EncryptingSmsDatabase smsDatabase = DatabaseFactory.getEncryptingSmsDatabase(context);
|
2014-11-03 15:16:04 -08:00
|
|
|
|
2015-05-18 15:16:27 -07:00
|
|
|
if (!smsMessageId.isPresent()) {
|
2017-01-22 13:52:36 -08:00
|
|
|
Optional<InsertResult> insertResult = insertPlaceholder(envelope);
|
|
|
|
|
|
|
|
if (insertResult.isPresent()) {
|
|
|
|
smsDatabase.markAsInvalidVersionKeyExchange(insertResult.get().getMessageId());
|
|
|
|
MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), insertResult.get().getThreadId());
|
|
|
|
}
|
2015-01-15 13:35:35 -08:00
|
|
|
} else {
|
2015-05-18 15:16:27 -07:00
|
|
|
smsDatabase.markAsInvalidVersionKeyExchange(smsMessageId.get());
|
2015-01-15 13:35:35 -08:00
|
|
|
}
|
2014-11-03 15:16:04 -08:00
|
|
|
}
|
|
|
|
|
2015-07-06 17:36:49 -07:00
|
|
|
private void handleCorruptMessage(@NonNull MasterSecretUnion masterSecret,
|
2016-03-23 10:34:41 -07:00
|
|
|
@NonNull SignalServiceEnvelope envelope,
|
2015-07-06 17:36:49 -07:00
|
|
|
@NonNull Optional<Long> smsMessageId)
|
|
|
|
{
|
2015-01-15 13:35:35 -08:00
|
|
|
EncryptingSmsDatabase smsDatabase = DatabaseFactory.getEncryptingSmsDatabase(context);
|
2014-11-03 15:16:04 -08:00
|
|
|
|
2015-05-18 15:16:27 -07:00
|
|
|
if (!smsMessageId.isPresent()) {
|
2017-01-22 13:52:36 -08:00
|
|
|
Optional<InsertResult> insertResult = insertPlaceholder(envelope);
|
|
|
|
|
|
|
|
if (insertResult.isPresent()) {
|
|
|
|
smsDatabase.markAsDecryptFailed(insertResult.get().getMessageId());
|
|
|
|
MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), insertResult.get().getThreadId());
|
|
|
|
}
|
2015-01-15 13:35:35 -08:00
|
|
|
} else {
|
2015-05-18 15:16:27 -07:00
|
|
|
smsDatabase.markAsDecryptFailed(smsMessageId.get());
|
2015-01-15 13:35:35 -08:00
|
|
|
}
|
2014-11-03 15:16:04 -08:00
|
|
|
}
|
|
|
|
|
2015-07-06 17:36:49 -07:00
|
|
|
private void handleNoSessionMessage(@NonNull MasterSecretUnion masterSecret,
|
2016-03-23 10:34:41 -07:00
|
|
|
@NonNull SignalServiceEnvelope envelope,
|
2015-07-06 17:36:49 -07:00
|
|
|
@NonNull Optional<Long> smsMessageId)
|
|
|
|
{
|
2015-01-15 13:35:35 -08:00
|
|
|
EncryptingSmsDatabase smsDatabase = DatabaseFactory.getEncryptingSmsDatabase(context);
|
2014-11-03 15:16:04 -08:00
|
|
|
|
2015-05-18 15:16:27 -07:00
|
|
|
if (!smsMessageId.isPresent()) {
|
2017-01-22 13:52:36 -08:00
|
|
|
Optional<InsertResult> insertResult = insertPlaceholder(envelope);
|
|
|
|
|
|
|
|
if (insertResult.isPresent()) {
|
|
|
|
smsDatabase.markAsNoSession(insertResult.get().getMessageId());
|
|
|
|
MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), insertResult.get().getThreadId());
|
|
|
|
}
|
2015-01-15 13:35:35 -08:00
|
|
|
} else {
|
2015-05-18 15:16:27 -07:00
|
|
|
smsDatabase.markAsNoSession(smsMessageId.get());
|
2015-01-15 13:35:35 -08:00
|
|
|
}
|
2014-11-03 15:16:04 -08:00
|
|
|
}
|
|
|
|
|
2015-07-06 17:36:49 -07:00
|
|
|
private void handleLegacyMessage(@NonNull MasterSecretUnion masterSecret,
|
2016-03-23 10:34:41 -07:00
|
|
|
@NonNull SignalServiceEnvelope envelope,
|
2015-07-06 17:36:49 -07:00
|
|
|
@NonNull Optional<Long> smsMessageId)
|
|
|
|
{
|
2015-01-15 13:35:35 -08:00
|
|
|
EncryptingSmsDatabase smsDatabase = DatabaseFactory.getEncryptingSmsDatabase(context);
|
2014-11-03 15:16:04 -08:00
|
|
|
|
2015-05-18 15:16:27 -07:00
|
|
|
if (!smsMessageId.isPresent()) {
|
2017-01-22 13:52:36 -08:00
|
|
|
Optional<InsertResult> insertResult = insertPlaceholder(envelope);
|
|
|
|
|
|
|
|
if (insertResult.isPresent()) {
|
|
|
|
smsDatabase.markAsLegacyVersion(insertResult.get().getMessageId());
|
|
|
|
MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), insertResult.get().getThreadId());
|
|
|
|
}
|
2015-01-15 13:35:35 -08:00
|
|
|
} else {
|
2015-05-18 15:16:27 -07:00
|
|
|
smsDatabase.markAsLegacyVersion(smsMessageId.get());
|
2015-01-15 13:35:35 -08:00
|
|
|
}
|
2014-11-03 15:16:04 -08:00
|
|
|
}
|
|
|
|
|
2015-07-06 17:36:49 -07:00
|
|
|
private void handleDuplicateMessage(@NonNull MasterSecretUnion masterSecret,
|
2016-03-23 10:34:41 -07:00
|
|
|
@NonNull SignalServiceEnvelope envelope,
|
2015-07-06 17:36:49 -07:00
|
|
|
@NonNull Optional<Long> smsMessageId)
|
|
|
|
{
|
2015-01-15 13:35:35 -08:00
|
|
|
// Let's start ignoring these now
|
|
|
|
// SmsDatabase smsDatabase = DatabaseFactory.getEncryptingSmsDatabase(context);
|
2015-01-25 17:43:24 -08:00
|
|
|
//
|
2015-01-15 13:35:35 -08:00
|
|
|
// if (smsMessageId <= 0) {
|
|
|
|
// Pair<Long, Long> messageAndThreadId = insertPlaceholder(masterSecret, envelope);
|
|
|
|
// smsDatabase.markAsDecryptDuplicate(messageAndThreadId.first);
|
|
|
|
// MessageNotifier.updateNotification(context, masterSecret, messageAndThreadId.second);
|
|
|
|
// } else {
|
|
|
|
// smsDatabase.markAsDecryptDuplicate(smsMessageId);
|
|
|
|
// }
|
2014-11-03 15:16:04 -08:00
|
|
|
}
|
|
|
|
|
2015-07-06 17:36:49 -07:00
|
|
|
private void handleUntrustedIdentityMessage(@NonNull MasterSecretUnion masterSecret,
|
2016-03-23 10:34:41 -07:00
|
|
|
@NonNull SignalServiceEnvelope envelope,
|
2015-07-06 17:36:49 -07:00
|
|
|
@NonNull Optional<Long> smsMessageId)
|
|
|
|
{
|
2015-01-15 13:35:35 -08:00
|
|
|
try {
|
|
|
|
EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
|
2017-07-26 09:59:15 -07:00
|
|
|
Address sourceAddress = Address.fromExternal(context, envelope.getSource());
|
2016-11-09 09:37:40 -08:00
|
|
|
byte[] serialized = envelope.hasLegacyMessage() ? envelope.getLegacyMessage() : envelope.getContent();
|
|
|
|
PreKeySignalMessage whisperMessage = new PreKeySignalMessage(serialized);
|
2015-01-15 13:35:35 -08:00
|
|
|
IdentityKey identityKey = whisperMessage.getIdentityKey();
|
2016-11-09 09:37:40 -08:00
|
|
|
String encoded = Base64.encodeBytes(serialized);
|
|
|
|
|
2017-07-26 09:59:15 -07:00
|
|
|
IncomingTextMessage textMessage = new IncomingTextMessage(sourceAddress,
|
|
|
|
envelope.getSourceDevice(),
|
2015-01-15 13:35:35 -08:00
|
|
|
envelope.getTimestamp(), encoded,
|
2016-08-15 20:23:56 -07:00
|
|
|
Optional.<SignalServiceGroup>absent(), 0);
|
2015-01-15 13:35:35 -08:00
|
|
|
|
2015-05-18 15:16:27 -07:00
|
|
|
if (!smsMessageId.isPresent()) {
|
2016-11-09 09:37:40 -08:00
|
|
|
IncomingPreKeyBundleMessage bundleMessage = new IncomingPreKeyBundleMessage(textMessage, encoded, envelope.hasLegacyMessage());
|
2017-01-22 13:52:36 -08:00
|
|
|
Optional<InsertResult> insertResult = database.insertMessageInbox(masterSecret, bundleMessage);
|
2015-01-15 13:35:35 -08:00
|
|
|
|
2017-01-22 13:52:36 -08:00
|
|
|
if (insertResult.isPresent()) {
|
2017-07-26 09:59:15 -07:00
|
|
|
database.setMismatchedIdentity(insertResult.get().getMessageId(), sourceAddress, identityKey);
|
2017-01-22 13:52:36 -08:00
|
|
|
MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), insertResult.get().getThreadId());
|
|
|
|
}
|
2015-01-15 13:35:35 -08:00
|
|
|
} else {
|
2015-05-18 15:16:27 -07:00
|
|
|
database.updateMessageBody(masterSecret, smsMessageId.get(), encoded);
|
|
|
|
database.markAsPreKeyBundle(smsMessageId.get());
|
2017-07-26 09:59:15 -07:00
|
|
|
database.setMismatchedIdentity(smsMessageId.get(), sourceAddress, identityKey);
|
2015-01-15 13:35:35 -08:00
|
|
|
}
|
2015-03-03 11:44:49 -08:00
|
|
|
} catch (InvalidMessageException | InvalidVersionException e) {
|
2015-01-15 13:35:35 -08:00
|
|
|
throw new AssertionError(e);
|
|
|
|
}
|
2014-11-03 15:16:04 -08:00
|
|
|
}
|
|
|
|
|
2017-08-14 18:11:13 -07:00
|
|
|
private void handleProfileKey(@NonNull SignalServiceEnvelope envelope,
|
|
|
|
@NonNull SignalServiceDataMessage message)
|
|
|
|
{
|
2017-08-22 10:44:04 -07:00
|
|
|
RecipientDatabase database = DatabaseFactory.getRecipientDatabase(context);
|
|
|
|
Address sourceAddress = Address.fromExternal(context, envelope.getSource());
|
|
|
|
Recipient recipient = Recipient.from(context, sourceAddress, false);
|
2017-08-14 18:11:13 -07:00
|
|
|
|
2017-08-25 12:00:52 -07:00
|
|
|
if (recipient.getProfileKey() == null || !MessageDigest.isEqual(recipient.getProfileKey(), message.getProfileKey().get())) {
|
2017-08-22 10:44:04 -07:00
|
|
|
database.setProfileKey(recipient, message.getProfileKey().get());
|
2017-08-14 18:11:13 -07:00
|
|
|
ApplicationContext.getInstance(context).getJobManager().add(new RetrieveProfileJob(context, recipient));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-15 22:38:53 -07:00
|
|
|
private void handleDeliveryReceipt(@NonNull SignalServiceEnvelope envelope,
|
|
|
|
@NonNull SignalServiceReceiptMessage message)
|
|
|
|
{
|
|
|
|
for (long timestamp : message.getTimestamps()) {
|
|
|
|
Log.w(TAG, String.format("Received encrypted delivery receipt: (XXXXX, %d)", timestamp));
|
|
|
|
DatabaseFactory.getMmsSmsDatabase(context)
|
2017-09-30 08:45:45 -07:00
|
|
|
.incrementDeliveryReceiptCount(new SyncMessageId(Address.fromExternal(context, envelope.getSource()), timestamp), System.currentTimeMillis());
|
2017-09-15 22:38:53 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleReadReceipt(@NonNull SignalServiceEnvelope envelope,
|
|
|
|
@NonNull SignalServiceReceiptMessage message)
|
|
|
|
{
|
|
|
|
if (TextSecurePreferences.isReadReceiptsEnabled(context)) {
|
|
|
|
for (long timestamp : message.getTimestamps()) {
|
|
|
|
Log.w(TAG, String.format("Received encrypted read receipt: (XXXXX, %d)", timestamp));
|
|
|
|
|
|
|
|
DatabaseFactory.getMmsSmsDatabase(context)
|
2017-09-30 08:45:45 -07:00
|
|
|
.incrementReadReceiptCount(new SyncMessageId(Address.fromExternal(context, envelope.getSource()), timestamp), envelope.getTimestamp());
|
2017-09-15 22:38:53 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-22 13:52:36 -08:00
|
|
|
private Optional<InsertResult> insertPlaceholder(@NonNull SignalServiceEnvelope envelope) {
|
2015-07-06 17:36:49 -07:00
|
|
|
EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
|
2017-07-26 09:59:15 -07:00
|
|
|
IncomingTextMessage textMessage = new IncomingTextMessage(Address.fromExternal(context, envelope.getSource()),
|
|
|
|
envelope.getSourceDevice(),
|
2015-07-06 17:36:49 -07:00
|
|
|
envelope.getTimestamp(), "",
|
2016-08-15 20:23:56 -07:00
|
|
|
Optional.<SignalServiceGroup>absent(), 0);
|
2014-11-03 15:16:04 -08:00
|
|
|
|
|
|
|
textMessage = new IncomingEncryptedMessage(textMessage, "");
|
2015-07-06 17:36:49 -07:00
|
|
|
return database.insertMessageInbox(textMessage);
|
2014-11-03 15:16:04 -08:00
|
|
|
}
|
2015-05-18 15:16:27 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
private Recipient getSyncMessageDestination(SentTranscriptMessage message) {
|
2015-05-29 16:23:47 -07:00
|
|
|
if (message.getMessage().getGroupInfo().isPresent()) {
|
2017-08-21 18:32:38 -07:00
|
|
|
return Recipient.from(context, Address.fromExternal(context, GroupUtil.getEncodedId(message.getMessage().getGroupInfo().get().getGroupId(), false)), false);
|
2015-05-18 15:16:27 -07:00
|
|
|
} else {
|
2017-08-21 18:32:38 -07:00
|
|
|
return Recipient.from(context, Address.fromExternal(context, message.getDestination().get()), false);
|
2015-05-18 15:16:27 -07:00
|
|
|
}
|
|
|
|
}
|
2016-08-15 20:23:56 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
private Recipient getMessageDestination(SignalServiceEnvelope envelope, SignalServiceDataMessage message) {
|
2016-08-15 20:23:56 -07:00
|
|
|
if (message.getGroupInfo().isPresent()) {
|
2017-08-21 18:32:38 -07:00
|
|
|
return Recipient.from(context, Address.fromExternal(context, GroupUtil.getEncodedId(message.getGroupInfo().get().getGroupId(), false)), false);
|
2016-08-15 20:23:56 -07:00
|
|
|
} else {
|
2017-08-21 18:32:38 -07:00
|
|
|
return Recipient.from(context, Address.fromExternal(context, envelope.getSource()), false);
|
2016-08-15 20:23:56 -07:00
|
|
|
}
|
|
|
|
}
|
2014-11-03 15:16:04 -08:00
|
|
|
}
|