Search in sources :

Example 1 with SignalServiceReceiptMessage

use of org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage in project Signal-Android by WhisperSystems.

the class SendReadReceiptJob method onRun.

@Override
public void onRun() throws IOException, UntrustedIdentityException, UndeliverableMessageException {
    if (!Recipient.self().isRegistered()) {
        throw new NotPushRegisteredException();
    }
    if (!TextSecurePreferences.isReadReceiptsEnabled(context) || messageSentTimestamps.isEmpty())
        return;
    if (!RecipientUtil.isMessageRequestAccepted(context, threadId)) {
        Log.w(TAG, "Refusing to send receipts to untrusted recipient");
        return;
    }
    Recipient recipient = Recipient.resolved(recipientId);
    if (recipient.isSelf()) {
        Log.i(TAG, "Not sending to self, aborting.");
    }
    if (recipient.isBlocked()) {
        Log.w(TAG, "Refusing to send receipts to blocked recipient");
        return;
    }
    if (recipient.isGroup()) {
        Log.w(TAG, "Refusing to send receipts to group");
        return;
    }
    if (recipient.isUnregistered()) {
        Log.w(TAG, recipient.getId() + " not registered!");
        return;
    }
    SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
    SignalServiceAddress remoteAddress = RecipientUtil.toSignalServiceAddress(context, recipient);
    SignalServiceReceiptMessage receiptMessage = new SignalServiceReceiptMessage(SignalServiceReceiptMessage.Type.READ, messageSentTimestamps, timestamp);
    SendMessageResult result = messageSender.sendReceipt(remoteAddress, UnidentifiedAccessUtil.getAccessFor(context, Recipient.resolved(recipientId)), receiptMessage);
    if (Util.hasItems(messageIds)) {
        SignalDatabase.messageLog().insertIfPossible(recipientId, timestamp, result, ContentHint.IMPLICIT, messageIds);
    }
}
Also used : NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalServiceReceiptMessage(org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult)

Example 2 with SignalServiceReceiptMessage

use of org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage in project Signal-Android by WhisperSystems.

the class SendViewedReceiptJob method onRun.

@Override
public void onRun() throws IOException, UntrustedIdentityException {
    if (!Recipient.self().isRegistered()) {
        throw new NotPushRegisteredException();
    }
    if (!TextSecurePreferences.isReadReceiptsEnabled(context)) {
        Log.w(TAG, "Read receipts not enabled!");
        return;
    }
    if (messageSentTimestamps.isEmpty()) {
        Log.w(TAG, "No sync timestamps!");
        return;
    }
    if (!RecipientUtil.isMessageRequestAccepted(context, threadId)) {
        Log.w(TAG, "Refusing to send receipts to untrusted recipient");
        return;
    }
    Recipient recipient = Recipient.resolved(recipientId);
    if (recipient.isSelf()) {
        Log.i(TAG, "Not sending view receipt to self.");
        return;
    }
    if (recipient.isBlocked()) {
        Log.w(TAG, "Refusing to send receipts to blocked recipient");
        return;
    }
    if (recipient.isGroup()) {
        Log.w(TAG, "Refusing to send receipts to group");
        return;
    }
    if (recipient.isUnregistered()) {
        Log.w(TAG, recipient.getId() + " not registered!");
        return;
    }
    SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
    SignalServiceAddress remoteAddress = RecipientUtil.toSignalServiceAddress(context, recipient);
    SignalServiceReceiptMessage receiptMessage = new SignalServiceReceiptMessage(SignalServiceReceiptMessage.Type.VIEWED, messageSentTimestamps, timestamp);
    SendMessageResult result = messageSender.sendReceipt(remoteAddress, UnidentifiedAccessUtil.getAccessFor(context, Recipient.resolved(recipientId)), receiptMessage);
    if (Util.hasItems(messageIds)) {
        SignalDatabase.messageLog().insertIfPossible(recipientId, timestamp, result, ContentHint.IMPLICIT, messageIds);
    }
}
Also used : NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalServiceReceiptMessage(org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult)

Example 3 with SignalServiceReceiptMessage

use of org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage in project Signal-Android by WhisperSystems.

the class SendDeliveryReceiptJob method onRun.

@Override
public void onRun() throws IOException, UntrustedIdentityException, UndeliverableMessageException {
    if (!Recipient.self().isRegistered()) {
        throw new NotPushRegisteredException();
    }
    SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
    Recipient recipient = Recipient.resolved(recipientId);
    if (recipient.isSelf()) {
        Log.i(TAG, "Not sending to self, abort");
        return;
    }
    if (recipient.isUnregistered()) {
        Log.w(TAG, recipient.getId() + " is unregistered!");
        return;
    }
    SignalServiceAddress remoteAddress = RecipientUtil.toSignalServiceAddress(context, recipient);
    SignalServiceReceiptMessage receiptMessage = new SignalServiceReceiptMessage(SignalServiceReceiptMessage.Type.DELIVERY, Collections.singletonList(messageSentTimestamp), timestamp);
    SendMessageResult result = messageSender.sendReceipt(remoteAddress, UnidentifiedAccessUtil.getAccessFor(context, recipient), receiptMessage);
    if (messageId != null) {
        SignalDatabase.messageLog().insertIfPossible(recipientId, timestamp, result, ContentHint.IMPLICIT, messageId);
    }
}
Also used : NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalServiceReceiptMessage(org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult)

Example 4 with SignalServiceReceiptMessage

use of org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage in project Signal-Android by WhisperSystems.

the class MessageContentProcessor method handleViewedReceipt.

private void handleViewedReceipt(@NonNull SignalServiceContent content, @NonNull SignalServiceReceiptMessage message, @NonNull Recipient senderRecipient) {
    if (!TextSecurePreferences.isReadReceiptsEnabled(context)) {
        log("Ignoring viewed receipts for IDs: " + Util.join(message.getTimestamps(), ", "));
        return;
    }
    log(TAG, "Processing viewed receipts. Sender: " + senderRecipient.getId() + ", Device: " + content.getSenderDevice() + ", Timestamps: " + Util.join(message.getTimestamps(), ", "));
    List<SyncMessageId> ids = Stream.of(message.getTimestamps()).map(t -> new SyncMessageId(senderRecipient.getId(), t)).toList();
    Collection<SyncMessageId> unhandled = SignalDatabase.mmsSms().incrementViewedReceiptCounts(ids, content.getTimestamp());
    for (SyncMessageId id : unhandled) {
        warn(String.valueOf(content.getTimestamp()), "[handleViewedReceipt] Could not find matching message! timestamp: " + id.getTimetamp() + "  author: " + senderRecipient.getId());
        ApplicationDependencies.getEarlyMessageCache().store(senderRecipient.getId(), id.getTimetamp(), content);
    }
}
Also used : LinkPreview(org.thoughtcrime.securesms.linkpreview.LinkPreview) StickerPackOperationMessage(org.whispersystems.signalservice.api.messages.multidevice.StickerPackOperationMessage) NonNull(androidx.annotation.NonNull) RecipientUtil(org.thoughtcrime.securesms.recipients.RecipientUtil) PaymentTransactionCheckJob(org.thoughtcrime.securesms.jobs.PaymentTransactionCheckJob) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) LinkPreviewUtil(org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil) SecureRandom(java.security.SecureRandom) SignalServiceContent(org.whispersystems.signalservice.api.messages.SignalServiceContent) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord) RequestGroupInfoJob(org.thoughtcrime.securesms.jobs.RequestGroupInfoJob) Map(java.util.Map) GroupChangeBusyException(org.thoughtcrime.securesms.groups.GroupChangeBusyException) ThreadRecord(org.thoughtcrime.securesms.database.model.ThreadRecord) OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) MultiDeviceGroupUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceGroupUpdateJob) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) ReactionRecord(org.thoughtcrime.securesms.database.model.ReactionRecord) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) Nullable(androidx.annotation.Nullable) SignalServiceGroupContext(org.whispersystems.signalservice.api.messages.SignalServiceGroupContext) StickerPackDownloadJob(org.thoughtcrime.securesms.jobs.StickerPackDownloadJob) SignalServiceGroupV2(org.whispersystems.signalservice.api.messages.SignalServiceGroupV2) MessageLogEntry(org.thoughtcrime.securesms.database.model.MessageLogEntry) CallId(org.signal.ringrtc.CallId) GroupUtil(org.thoughtcrime.securesms.util.GroupUtil) PendingRetryReceiptModel(org.thoughtcrime.securesms.database.model.PendingRetryReceiptModel) RefreshOwnProfileJob(org.thoughtcrime.securesms.jobs.RefreshOwnProfileJob) Attachment(org.thoughtcrime.securesms.attachments.Attachment) MultiDeviceBlockedUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceBlockedUpdateJob) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) MediaUtil(org.thoughtcrime.securesms.util.MediaUtil) MmsSmsDatabase(org.thoughtcrime.securesms.database.MmsSmsDatabase) StickerDatabase(org.thoughtcrime.securesms.database.StickerDatabase) GroupsV1MigrationUtil(org.thoughtcrime.securesms.groups.GroupsV1MigrationUtil) MobileCoinPublicAddress(org.thoughtcrime.securesms.payments.MobileCoinPublicAddress) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) SignalServiceTypingMessage(org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage) ProfileKeySendJob(org.thoughtcrime.securesms.jobs.ProfileKeySendJob) Stream(com.annimon.stream.Stream) PaymentMetaDataUtil(org.thoughtcrime.securesms.database.PaymentMetaDataUtil) Util(org.thoughtcrime.securesms.util.Util) RefreshAttributesJob(org.thoughtcrime.securesms.jobs.RefreshAttributesJob) GroupRecord(org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord) AttachmentDatabase(org.thoughtcrime.securesms.database.AttachmentDatabase) RetrieveProfileJob(org.thoughtcrime.securesms.jobs.RetrieveProfileJob) ArrayList(java.util.ArrayList) PaymentDatabase(org.thoughtcrime.securesms.database.PaymentDatabase) BlockedListMessage(org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage) ContactModelMapper(org.thoughtcrime.securesms.contactshare.ContactModelMapper) MultiDeviceConfigurationUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceConfigurationUpdateJob) NullMessageSendJob(org.thoughtcrime.securesms.jobs.NullMessageSendJob) IncomingEncryptedMessage(org.thoughtcrime.securesms.sms.IncomingEncryptedMessage) OutgoingEndSessionMessage(org.thoughtcrime.securesms.sms.OutgoingEndSessionMessage) HangupMessage(org.whispersystems.signalservice.api.messages.calls.HangupMessage) EmojiUtil(org.thoughtcrime.securesms.components.emoji.EmojiUtil) ECPublicKey(org.whispersystems.libsignal.ecc.ECPublicKey) SignalServiceGroup(org.whispersystems.signalservice.api.messages.SignalServiceGroup) SignalServiceCallMessage(org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage) ReadMessage(org.whispersystems.signalservice.api.messages.multidevice.ReadMessage) IncomingEndSessionMessage(org.thoughtcrime.securesms.sms.IncomingEndSessionMessage) ViewOnceOpenMessage(org.whispersystems.signalservice.api.messages.multidevice.ViewOnceOpenMessage) MessageRequestResponseMessage(org.whispersystems.signalservice.api.messages.multidevice.MessageRequestResponseMessage) OutgoingEncryptedMessage(org.thoughtcrime.securesms.sms.OutgoingEncryptedMessage) KeysMessage(org.whispersystems.signalservice.api.messages.multidevice.KeysMessage) DistributionId(org.whispersystems.signalservice.api.push.DistributionId) GroupReceiptInfo(org.thoughtcrime.securesms.database.GroupReceiptDatabase.GroupReceiptInfo) RequestMessage(org.whispersystems.signalservice.api.messages.multidevice.RequestMessage) IdentityUtil(org.thoughtcrime.securesms.util.IdentityUtil) MessageId(org.thoughtcrime.securesms.database.model.MessageId) Collectors(com.annimon.stream.Collectors) GroupReceiptDatabase(org.thoughtcrime.securesms.database.GroupReceiptDatabase) Contact(org.thoughtcrime.securesms.contactshare.Contact) TextUtils(android.text.TextUtils) Hex(org.thoughtcrime.securesms.util.Hex) IOException(java.io.IOException) Optional(org.whispersystems.libsignal.util.guava.Optional) StickerLocator(org.thoughtcrime.securesms.stickers.StickerLocator) GroupV1MessageProcessor(org.thoughtcrime.securesms.groups.GroupV1MessageProcessor) TrimThreadJob(org.thoughtcrime.securesms.jobs.TrimThreadJob) IncomingMediaMessage(org.thoughtcrime.securesms.mms.IncomingMediaMessage) Money(org.whispersystems.signalservice.api.payments.Money) SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) VerifiedMessage(org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage) MessageNotifier(org.thoughtcrime.securesms.notifications.MessageNotifier) SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) AttachmentDownloadJob(org.thoughtcrime.securesms.jobs.AttachmentDownloadJob) SerializationException(com.mobilecoin.lib.exceptions.SerializationException) PointerAttachment(org.thoughtcrime.securesms.attachments.PointerAttachment) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) MultiDeviceStickerPackSyncJob(org.thoughtcrime.securesms.jobs.MultiDeviceStickerPackSyncJob) WebRtcData(org.thoughtcrime.securesms.service.webrtc.WebRtcData) SentTranscriptMessage(org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage) Mention(org.thoughtcrime.securesms.database.model.Mention) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) AutomaticSessionResetJob(org.thoughtcrime.securesms.jobs.AutomaticSessionResetJob) SecurityEvent(org.thoughtcrime.securesms.crypto.SecurityEvent) StorageSyncHelper(org.thoughtcrime.securesms.storage.StorageSyncHelper) Locale(java.util.Locale) ResendMessageJob(org.thoughtcrime.securesms.jobs.ResendMessageJob) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) Recipient(org.thoughtcrime.securesms.recipients.Recipient) BusyMessage(org.whispersystems.signalservice.api.messages.calls.BusyMessage) StickerSlide(org.thoughtcrime.securesms.mms.StickerSlide) MultiDeviceContactSyncJob(org.thoughtcrime.securesms.jobs.MultiDeviceContactSyncJob) SyncMessageId(org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId) PaymentLedgerUpdateJob(org.thoughtcrime.securesms.jobs.PaymentLedgerUpdateJob) Collection(java.util.Collection) ProfileKeyUtil(org.thoughtcrime.securesms.crypto.ProfileKeyUtil) SendDeliveryReceiptJob(org.thoughtcrime.securesms.jobs.SendDeliveryReceiptJob) OutgoingSecureMediaMessage(org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage) UUID(java.util.UUID) SenderKeyDistributionSendJob(org.thoughtcrime.securesms.jobs.SenderKeyDistributionSendJob) OutgoingExpirationUpdateMessage(org.thoughtcrime.securesms.mms.OutgoingExpirationUpdateMessage) Objects(java.util.Objects) Log(org.signal.core.util.logging.Log) FeatureFlags(org.thoughtcrime.securesms.util.FeatureFlags) List(java.util.List) MarkReadReceiver(org.thoughtcrime.securesms.notifications.MarkReadReceiver) ViewedMessage(org.whispersystems.signalservice.api.messages.multidevice.ViewedMessage) GroupNotAMemberException(org.thoughtcrime.securesms.groups.GroupNotAMemberException) GroupId(org.thoughtcrime.securesms.groups.GroupId) SharedContact(org.whispersystems.signalservice.api.messages.shared.SharedContact) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) ContactsMessage(org.whispersystems.signalservice.api.messages.multidevice.ContactsMessage) GroupV2UpdateSelfProfileKeyJob(org.thoughtcrime.securesms.jobs.GroupV2UpdateSelfProfileKeyJob) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage) SignalServiceReceiptMessage(org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage) InsertResult(org.thoughtcrime.securesms.database.MessageDatabase.InsertResult) PushProcessMessageJob(org.thoughtcrime.securesms.jobs.PushProcessMessageJob) AnswerMessage(org.whispersystems.signalservice.api.messages.calls.AnswerMessage) MultiDevicePniIdentityUpdateJob(org.thoughtcrime.securesms.jobs.MultiDevicePniIdentityUpdateJob) Context(android.content.Context) ConfigurationMessage(org.whispersystems.signalservice.api.messages.multidevice.ConfigurationMessage) RemotePeer(org.thoughtcrime.securesms.ringrtc.RemotePeer) BadGroupIdException(org.thoughtcrime.securesms.groups.BadGroupIdException) HashMap(java.util.HashMap) RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) OfferMessage(org.whispersystems.signalservice.api.messages.calls.OfferMessage) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) UriAttachment(org.thoughtcrime.securesms.attachments.UriAttachment) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) OpaqueMessage(org.whispersystems.signalservice.api.messages.calls.OpaqueMessage) GroupManager(org.thoughtcrime.securesms.groups.GroupManager) SuppressLint(android.annotation.SuppressLint) GroupCallPeekJob(org.thoughtcrime.securesms.jobs.GroupCallPeekJob) QuoteModel(org.thoughtcrime.securesms.mms.QuoteModel) Build(android.os.Build) LinkedList(java.util.LinkedList) MultiDeviceContactUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob) MultiDeviceKeysUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceKeysUpdateJob) SignalServiceAttachmentPointer(org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer) DecryptionErrorMessage(org.whispersystems.libsignal.protocol.DecryptionErrorMessage) StickerRecord(org.thoughtcrime.securesms.database.model.StickerRecord) MmsException(org.thoughtcrime.securesms.mms.MmsException) RemoteDeleteUtil(org.thoughtcrime.securesms.util.RemoteDeleteUtil) TombstoneAttachment(org.thoughtcrime.securesms.attachments.TombstoneAttachment) OutgoingPaymentMessage(org.whispersystems.signalservice.api.messages.multidevice.OutgoingPaymentMessage) TimeUnit(java.util.concurrent.TimeUnit) IceUpdateMessage(org.whispersystems.signalservice.api.messages.calls.IceUpdateMessage) RateLimitUtil(org.thoughtcrime.securesms.ratelimit.RateLimitUtil) SignalServiceSyncMessage(org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage) SessionRecord(org.whispersystems.libsignal.state.SessionRecord) Collections(java.util.Collections) SyncMessageId(org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId)

Example 5 with SignalServiceReceiptMessage

use of org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage in project Signal-Android by signalapp.

the class PushDecryptJob method handleMessage.

private void handleMessage(SignalServiceEnvelope envelope, Optional<Long> smsMessageId) {
    try {
        GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context);
        SignalProtocolStore axolotlStore = new SignalProtocolStoreImpl(context);
        SignalServiceAddress localAddress = new SignalServiceAddress(TextSecurePreferences.getLocalNumber(context));
        SignalServiceCipher cipher = new SignalServiceCipher(localAddress, axolotlStore);
        SignalServiceContent content = cipher.decrypt(envelope);
        if (content.getDataMessage().isPresent()) {
            SignalServiceDataMessage message = content.getDataMessage().get();
            if (message.isEndSession())
                handleEndSessionMessage(envelope, message, smsMessageId);
            else if (message.isGroupUpdate())
                handleGroupMessage(envelope, message, smsMessageId);
            else if (message.isExpirationUpdate())
                handleExpirationUpdate(envelope, message, smsMessageId);
            else if (message.getAttachments().isPresent())
                handleMediaMessage(envelope, message, smsMessageId);
            else if (message.getBody().isPresent())
                handleTextMessage(envelope, message, smsMessageId);
            if (message.getGroupInfo().isPresent() && groupDatabase.isUnknownGroup(GroupUtil.getEncodedId(message.getGroupInfo().get().getGroupId(), false))) {
                handleUnknownGroupMessage(envelope, message.getGroupInfo().get());
            }
            if (message.getProfileKey().isPresent() && message.getProfileKey().get().length == 32) {
                handleProfileKey(envelope, message);
            }
        } else if (content.getSyncMessage().isPresent()) {
            SignalServiceSyncMessage syncMessage = content.getSyncMessage().get();
            if (syncMessage.getSent().isPresent())
                handleSynchronizeSentMessage(envelope, syncMessage.getSent().get());
            else if (syncMessage.getRequest().isPresent())
                handleSynchronizeRequestMessage(syncMessage.getRequest().get());
            else if (syncMessage.getRead().isPresent())
                handleSynchronizeReadMessage(syncMessage.getRead().get(), envelope.getTimestamp());
            else if (syncMessage.getVerified().isPresent())
                handleSynchronizeVerifiedMessage(syncMessage.getVerified().get());
            else
                Log.w(TAG, "Contains no known sync types...");
        } 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);
            else if (message.getBusyMessage().isPresent())
                handleCallBusyMessage(envelope, message.getBusyMessage().get());
        } else if (content.getReceiptMessage().isPresent()) {
            SignalServiceReceiptMessage message = content.getReceiptMessage().get();
            if (message.isReadReceipt())
                handleReadReceipt(envelope, message);
            else if (message.isDeliveryReceipt())
                handleDeliveryReceipt(envelope, message);
        } else {
            Log.w(TAG, "Got unrecognized message...");
        }
        if (envelope.isPreKeySignalMessage()) {
            ApplicationContext.getInstance(context).getJobManager().add(new RefreshPreKeysJob(context));
        }
    } catch (InvalidVersionException e) {
        Log.w(TAG, e);
        handleInvalidVersionMessage(envelope, smsMessageId);
    } catch (InvalidMessageException | InvalidKeyIdException | InvalidKeyException | MmsException e) {
        Log.w(TAG, e);
        handleCorruptMessage(envelope, smsMessageId);
    } catch (NoSessionException e) {
        Log.w(TAG, e);
        handleNoSessionMessage(envelope, smsMessageId);
    } catch (LegacyMessageException e) {
        Log.w(TAG, e);
        handleLegacyMessage(envelope, smsMessageId);
    } catch (DuplicateMessageException e) {
        Log.w(TAG, e);
        handleDuplicateMessage(envelope, smsMessageId);
    } catch (UntrustedIdentityException e) {
        Log.w(TAG, e);
        handleUntrustedIdentityMessage(envelope, smsMessageId);
    }
}
Also used : InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) UntrustedIdentityException(org.whispersystems.libsignal.UntrustedIdentityException) SignalServiceCipher(org.whispersystems.signalservice.api.crypto.SignalServiceCipher) InvalidVersionException(org.whispersystems.libsignal.InvalidVersionException) SignalServiceReceiptMessage(org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) SignalServiceSyncMessage(org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage) SignalServiceContent(org.whispersystems.signalservice.api.messages.SignalServiceContent) NoSessionException(org.whispersystems.libsignal.NoSessionException) SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) SignalProtocolStore(org.whispersystems.libsignal.state.SignalProtocolStore) MmsException(org.thoughtcrime.securesms.mms.MmsException) DuplicateMessageException(org.whispersystems.libsignal.DuplicateMessageException) SignalProtocolStoreImpl(org.thoughtcrime.securesms.crypto.storage.SignalProtocolStoreImpl) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SignalServiceCallMessage(org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage) InvalidKeyIdException(org.whispersystems.libsignal.InvalidKeyIdException) LegacyMessageException(org.whispersystems.libsignal.LegacyMessageException)

Aggregations

SignalServiceReceiptMessage (org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage)8 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)7 Recipient (org.thoughtcrime.securesms.recipients.Recipient)6 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)3 NotPushRegisteredException (org.thoughtcrime.securesms.net.NotPushRegisteredException)3 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)3 SendMessageResult (org.whispersystems.signalservice.api.messages.SendMessageResult)3 SignalServiceDataMessage (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage)3 SignalServiceCallMessage (org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage)3 SignalServiceSyncMessage (org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage)3 SuppressLint (android.annotation.SuppressLint)2 Context (android.content.Context)2 Build (android.os.Build)2 TextUtils (android.text.TextUtils)2 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 Collectors (com.annimon.stream.Collectors)2 Stream (com.annimon.stream.Stream)2 SerializationException (com.mobilecoin.lib.exceptions.SerializationException)2 IOException (java.io.IOException)2