Search in sources :

Example 6 with ViewedMessage

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

the class MessageContentProcessor method handleSynchronizeViewedMessage.

private void handleSynchronizeViewedMessage(@NonNull List<ViewedMessage> viewedMessages, long envelopeTimestamp) {
    log(envelopeTimestamp, "Synchronize view message. Count: " + viewedMessages.size() + ", Timestamps: " + viewedMessages.stream().map(ViewedMessage::getTimestamp));
    List<Long> toMarkViewed = Stream.of(viewedMessages).map(message -> {
        RecipientId author = Recipient.externalPush(message.getSender()).getId();
        return SignalDatabase.mmsSms().getMessageFor(message.getTimestamp(), author);
    }).filter(message -> message != null && message.isMms()).map(MessageRecord::getId).toList();
    SignalDatabase.mms().setIncomingMessagesViewed(toMarkViewed);
    MessageNotifier messageNotifier = ApplicationDependencies.getMessageNotifier();
    messageNotifier.setLastDesktopActivityTimestamp(envelopeTimestamp);
    messageNotifier.cancelDelayedNotifications();
    messageNotifier.updateNotification(context);
}
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) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) MessageNotifier(org.thoughtcrime.securesms.notifications.MessageNotifier) ViewedMessage(org.whispersystems.signalservice.api.messages.multidevice.ViewedMessage)

Example 7 with ViewedMessage

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

the class SignalServiceMessageSender method createMultiDeviceViewedContent.

private Content createMultiDeviceViewedContent(List<ViewedMessage> readMessages) {
    Content.Builder container = Content.newBuilder();
    SyncMessage.Builder builder = createSyncMessageBuilder();
    for (ViewedMessage readMessage : readMessages) {
        SyncMessage.Viewed.Builder viewedBuilder = SyncMessage.Viewed.newBuilder().setTimestamp(readMessage.getTimestamp());
        viewedBuilder.setSenderUuid(readMessage.getSender().getServiceId().toString());
        if (readMessage.getSender().getNumber().isPresent()) {
            viewedBuilder.setSenderE164(readMessage.getSender().getNumber().get());
        }
        builder.addViewed(viewedBuilder.build());
    }
    return container.setSyncMessage(builder).build();
}
Also used : SyncMessage(org.whispersystems.signalservice.internal.push.SignalServiceProtos.SyncMessage) SignalServiceSyncMessage(org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage) EnvelopeContent(org.whispersystems.signalservice.api.crypto.EnvelopeContent) PlaintextContent(org.whispersystems.libsignal.protocol.PlaintextContent) Content(org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content) ViewedMessage(org.whispersystems.signalservice.api.messages.multidevice.ViewedMessage)

Example 8 with ViewedMessage

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

the class SignalServiceContent method createSynchronizeMessage.

private static SignalServiceSyncMessage createSynchronizeMessage(SignalServiceMetadata metadata, SignalServiceProtos.SyncMessage content) throws ProtocolInvalidKeyException, UnsupportedDataMessageException, InvalidMessageStructureException {
    if (content.hasSent()) {
        Map<SignalServiceAddress, Boolean> unidentifiedStatuses = new HashMap<>();
        SignalServiceProtos.SyncMessage.Sent sentContent = content.getSent();
        SignalServiceDataMessage dataMessage = createSignalServiceMessage(metadata, sentContent.getMessage());
        Optional<SignalServiceAddress> address = SignalServiceAddress.isValidAddress(sentContent.getDestinationUuid(), sentContent.getDestinationE164()) ? Optional.of(new SignalServiceAddress(ACI.parseOrThrow(sentContent.getDestinationUuid()), sentContent.getDestinationE164())) : Optional.<SignalServiceAddress>absent();
        if (!address.isPresent() && !dataMessage.getGroupContext().isPresent()) {
            throw new InvalidMessageStructureException("SyncMessage missing both destination and group ID!");
        }
        for (SignalServiceProtos.SyncMessage.Sent.UnidentifiedDeliveryStatus status : sentContent.getUnidentifiedStatusList()) {
            if (SignalServiceAddress.isValidAddress(status.getDestinationUuid(), status.getDestinationE164())) {
                SignalServiceAddress recipient = new SignalServiceAddress(ACI.parseOrThrow(status.getDestinationUuid()), status.getDestinationE164());
                unidentifiedStatuses.put(recipient, status.getUnidentified());
            } else {
                Log.w(TAG, "Encountered an invalid UnidentifiedDeliveryStatus in a SentTranscript! Ignoring.");
            }
        }
        return SignalServiceSyncMessage.forSentTranscript(new SentTranscriptMessage(address, sentContent.getTimestamp(), dataMessage, sentContent.getExpirationStartTimestamp(), unidentifiedStatuses, sentContent.getIsRecipientUpdate()));
    }
    if (content.hasRequest()) {
        return SignalServiceSyncMessage.forRequest(new RequestMessage(content.getRequest()));
    }
    if (content.getReadList().size() > 0) {
        List<ReadMessage> readMessages = new LinkedList<>();
        for (SignalServiceProtos.SyncMessage.Read read : content.getReadList()) {
            if (SignalServiceAddress.isValidAddress(read.getSenderUuid(), read.getSenderE164())) {
                SignalServiceAddress address = new SignalServiceAddress(ACI.parseOrThrow(read.getSenderUuid()), read.getSenderE164());
                readMessages.add(new ReadMessage(address, read.getTimestamp()));
            } else {
                Log.w(TAG, "Encountered an invalid ReadMessage! Ignoring.");
            }
        }
        return SignalServiceSyncMessage.forRead(readMessages);
    }
    if (content.getViewedList().size() > 0) {
        List<ViewedMessage> viewedMessages = new LinkedList<>();
        for (SignalServiceProtos.SyncMessage.Viewed viewed : content.getViewedList()) {
            if (SignalServiceAddress.isValidAddress(viewed.getSenderUuid(), viewed.getSenderE164())) {
                SignalServiceAddress address = new SignalServiceAddress(ACI.parseOrThrow(viewed.getSenderUuid()), viewed.getSenderE164());
                viewedMessages.add(new ViewedMessage(address, viewed.getTimestamp()));
            } else {
                Log.w(TAG, "Encountered an invalid ReadMessage! Ignoring.");
            }
        }
        return SignalServiceSyncMessage.forViewed(viewedMessages);
    }
    if (content.hasViewOnceOpen()) {
        if (SignalServiceAddress.isValidAddress(content.getViewOnceOpen().getSenderUuid(), content.getViewOnceOpen().getSenderE164())) {
            SignalServiceAddress address = new SignalServiceAddress(ACI.parseOrThrow(content.getViewOnceOpen().getSenderUuid()), content.getViewOnceOpen().getSenderE164());
            ViewOnceOpenMessage timerRead = new ViewOnceOpenMessage(address, content.getViewOnceOpen().getTimestamp());
            return SignalServiceSyncMessage.forViewOnceOpen(timerRead);
        } else {
            throw new InvalidMessageStructureException("ViewOnceOpen message has no sender!");
        }
    }
    if (content.hasVerified()) {
        if (SignalServiceAddress.isValidAddress(content.getVerified().getDestinationUuid(), content.getVerified().getDestinationE164())) {
            try {
                SignalServiceProtos.Verified verified = content.getVerified();
                SignalServiceAddress destination = new SignalServiceAddress(ACI.parseOrThrow(verified.getDestinationUuid()), verified.getDestinationE164());
                IdentityKey identityKey = new IdentityKey(verified.getIdentityKey().toByteArray(), 0);
                VerifiedMessage.VerifiedState verifiedState;
                if (verified.getState() == SignalServiceProtos.Verified.State.DEFAULT) {
                    verifiedState = VerifiedMessage.VerifiedState.DEFAULT;
                } else if (verified.getState() == SignalServiceProtos.Verified.State.VERIFIED) {
                    verifiedState = VerifiedMessage.VerifiedState.VERIFIED;
                } else if (verified.getState() == SignalServiceProtos.Verified.State.UNVERIFIED) {
                    verifiedState = VerifiedMessage.VerifiedState.UNVERIFIED;
                } else {
                    throw new InvalidMessageStructureException("Unknown state: " + verified.getState().getNumber(), metadata.getSender().getIdentifier(), metadata.getSenderDevice());
                }
                return SignalServiceSyncMessage.forVerified(new VerifiedMessage(destination, identityKey, verifiedState, System.currentTimeMillis()));
            } catch (InvalidKeyException e) {
                throw new ProtocolInvalidKeyException(e, metadata.getSender().getIdentifier(), metadata.getSenderDevice());
            }
        } else {
            throw new InvalidMessageStructureException("Verified message has no sender!");
        }
    }
    if (content.getStickerPackOperationList().size() > 0) {
        List<StickerPackOperationMessage> operations = new LinkedList<>();
        for (SignalServiceProtos.SyncMessage.StickerPackOperation operation : content.getStickerPackOperationList()) {
            byte[] packId = operation.hasPackId() ? operation.getPackId().toByteArray() : null;
            byte[] packKey = operation.hasPackKey() ? operation.getPackKey().toByteArray() : null;
            StickerPackOperationMessage.Type type = null;
            if (operation.hasType()) {
                switch(operation.getType()) {
                    case INSTALL:
                        type = StickerPackOperationMessage.Type.INSTALL;
                        break;
                    case REMOVE:
                        type = StickerPackOperationMessage.Type.REMOVE;
                        break;
                }
            }
            operations.add(new StickerPackOperationMessage(packId, packKey, type));
        }
        return SignalServiceSyncMessage.forStickerPackOperations(operations);
    }
    if (content.hasBlocked()) {
        List<String> numbers = content.getBlocked().getNumbersList();
        List<String> uuids = content.getBlocked().getUuidsList();
        List<SignalServiceAddress> addresses = new ArrayList<>(numbers.size() + uuids.size());
        List<byte[]> groupIds = new ArrayList<>(content.getBlocked().getGroupIdsList().size());
        for (String uuid : uuids) {
            Optional<SignalServiceAddress> address = SignalServiceAddress.fromRaw(uuid, null);
            if (address.isPresent()) {
                addresses.add(address.get());
            }
        }
        for (ByteString groupId : content.getBlocked().getGroupIdsList()) {
            groupIds.add(groupId.toByteArray());
        }
        return SignalServiceSyncMessage.forBlocked(new BlockedListMessage(addresses, groupIds));
    }
    if (content.hasConfiguration()) {
        Boolean readReceipts = content.getConfiguration().hasReadReceipts() ? content.getConfiguration().getReadReceipts() : null;
        Boolean unidentifiedDeliveryIndicators = content.getConfiguration().hasUnidentifiedDeliveryIndicators() ? content.getConfiguration().getUnidentifiedDeliveryIndicators() : null;
        Boolean typingIndicators = content.getConfiguration().hasTypingIndicators() ? content.getConfiguration().getTypingIndicators() : null;
        Boolean linkPreviews = content.getConfiguration().hasLinkPreviews() ? content.getConfiguration().getLinkPreviews() : null;
        return SignalServiceSyncMessage.forConfiguration(new ConfigurationMessage(Optional.fromNullable(readReceipts), Optional.fromNullable(unidentifiedDeliveryIndicators), Optional.fromNullable(typingIndicators), Optional.fromNullable(linkPreviews)));
    }
    if (content.hasFetchLatest() && content.getFetchLatest().hasType()) {
        switch(content.getFetchLatest().getType()) {
            case LOCAL_PROFILE:
                return SignalServiceSyncMessage.forFetchLatest(SignalServiceSyncMessage.FetchType.LOCAL_PROFILE);
            case STORAGE_MANIFEST:
                return SignalServiceSyncMessage.forFetchLatest(SignalServiceSyncMessage.FetchType.STORAGE_MANIFEST);
            case SUBSCRIPTION_STATUS:
                return SignalServiceSyncMessage.forFetchLatest(SignalServiceSyncMessage.FetchType.SUBSCRIPTION_STATUS);
        }
    }
    if (content.hasMessageRequestResponse()) {
        MessageRequestResponseMessage.Type type;
        switch(content.getMessageRequestResponse().getType()) {
            case ACCEPT:
                type = MessageRequestResponseMessage.Type.ACCEPT;
                break;
            case DELETE:
                type = MessageRequestResponseMessage.Type.DELETE;
                break;
            case BLOCK:
                type = MessageRequestResponseMessage.Type.BLOCK;
                break;
            case BLOCK_AND_DELETE:
                type = MessageRequestResponseMessage.Type.BLOCK_AND_DELETE;
                break;
            default:
                type = MessageRequestResponseMessage.Type.UNKNOWN;
                break;
        }
        MessageRequestResponseMessage responseMessage;
        if (content.getMessageRequestResponse().hasGroupId()) {
            responseMessage = MessageRequestResponseMessage.forGroup(content.getMessageRequestResponse().getGroupId().toByteArray(), type);
        } else {
            Optional<SignalServiceAddress> address = SignalServiceAddress.fromRaw(content.getMessageRequestResponse().getThreadUuid(), content.getMessageRequestResponse().getThreadE164());
            if (address.isPresent()) {
                responseMessage = MessageRequestResponseMessage.forIndividual(address.get(), type);
            } else {
                throw new InvalidMessageStructureException("Message request response has an invalid thread identifier!");
            }
        }
        return SignalServiceSyncMessage.forMessageRequestResponse(responseMessage);
    }
    if (content.hasOutgoingPayment()) {
        SignalServiceProtos.SyncMessage.OutgoingPayment outgoingPayment = content.getOutgoingPayment();
        switch(outgoingPayment.getPaymentDetailCase()) {
            case MOBILECOIN:
                {
                    SignalServiceProtos.SyncMessage.OutgoingPayment.MobileCoin mobileCoin = outgoingPayment.getMobileCoin();
                    Money.MobileCoin amount = Money.picoMobileCoin(mobileCoin.getAmountPicoMob());
                    Money.MobileCoin fee = Money.picoMobileCoin(mobileCoin.getFeePicoMob());
                    ByteString address = mobileCoin.getRecipientAddress();
                    Optional<SignalServiceAddress> recipient = SignalServiceAddress.fromRaw(outgoingPayment.getRecipientUuid(), null);
                    return SignalServiceSyncMessage.forOutgoingPayment(new OutgoingPaymentMessage(recipient, amount, fee, mobileCoin.getReceipt(), mobileCoin.getLedgerBlockIndex(), mobileCoin.getLedgerBlockTimestamp(), address.isEmpty() ? Optional.absent() : Optional.of(address.toByteArray()), Optional.of(outgoingPayment.getNote()), mobileCoin.getOutputPublicKeysList(), mobileCoin.getSpentKeyImagesList()));
                }
            default:
                return SignalServiceSyncMessage.empty();
        }
    }
    if (content.hasKeys() && content.getKeys().hasStorageService()) {
        byte[] storageKey = content.getKeys().getStorageService().toByteArray();
        return SignalServiceSyncMessage.forKeys(new KeysMessage(Optional.of(new StorageKey(storageKey))));
    }
    if (content.hasContacts()) {
        return SignalServiceSyncMessage.forContacts(new ContactsMessage(createAttachmentPointer(content.getContacts().getBlob()), content.getContacts().getComplete()));
    }
    return SignalServiceSyncMessage.empty();
}
Also used : HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) OutgoingPaymentMessage(org.whispersystems.signalservice.api.messages.multidevice.OutgoingPaymentMessage) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) BlockedListMessage(org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage) RequestMessage(org.whispersystems.signalservice.api.messages.multidevice.RequestMessage) ViewedMessage(org.whispersystems.signalservice.api.messages.multidevice.ViewedMessage) SentTranscriptMessage(org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage) Optional(org.whispersystems.libsignal.util.guava.Optional) ContactsMessage(org.whispersystems.signalservice.api.messages.multidevice.ContactsMessage) LinkedList(java.util.LinkedList) SignalServiceSyncMessage(org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage) ProtocolInvalidKeyException(org.signal.libsignal.metadata.ProtocolInvalidKeyException) SignalServiceProtos(org.whispersystems.signalservice.internal.push.SignalServiceProtos) ReadMessage(org.whispersystems.signalservice.api.messages.multidevice.ReadMessage) VerifiedMessage(org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage) InvalidMessageStructureException(org.whispersystems.signalservice.api.InvalidMessageStructureException) KeysMessage(org.whispersystems.signalservice.api.messages.multidevice.KeysMessage) ViewOnceOpenMessage(org.whispersystems.signalservice.api.messages.multidevice.ViewOnceOpenMessage) StickerPackOperationMessage(org.whispersystems.signalservice.api.messages.multidevice.StickerPackOperationMessage) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) ConfigurationMessage(org.whispersystems.signalservice.api.messages.multidevice.ConfigurationMessage) StorageKey(org.whispersystems.signalservice.api.storage.StorageKey) IdentityKey(org.whispersystems.libsignal.IdentityKey) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) ProtocolInvalidKeyException(org.signal.libsignal.metadata.ProtocolInvalidKeyException) MessageRequestResponseMessage(org.whispersystems.signalservice.api.messages.multidevice.MessageRequestResponseMessage)

Aggregations

ViewedMessage (org.whispersystems.signalservice.api.messages.multidevice.ViewedMessage)8 LinkedList (java.util.LinkedList)6 SignalServiceSyncMessage (org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage)6 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Recipient (org.thoughtcrime.securesms.recipients.Recipient)4 Optional (org.whispersystems.libsignal.util.guava.Optional)4 BlockedListMessage (org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage)4 ConfigurationMessage (org.whispersystems.signalservice.api.messages.multidevice.ConfigurationMessage)4 ContactsMessage (org.whispersystems.signalservice.api.messages.multidevice.ContactsMessage)4 KeysMessage (org.whispersystems.signalservice.api.messages.multidevice.KeysMessage)4 MessageRequestResponseMessage (org.whispersystems.signalservice.api.messages.multidevice.MessageRequestResponseMessage)4 OutgoingPaymentMessage (org.whispersystems.signalservice.api.messages.multidevice.OutgoingPaymentMessage)4 ReadMessage (org.whispersystems.signalservice.api.messages.multidevice.ReadMessage)4 RequestMessage (org.whispersystems.signalservice.api.messages.multidevice.RequestMessage)4 SentTranscriptMessage (org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage)4 StickerPackOperationMessage (org.whispersystems.signalservice.api.messages.multidevice.StickerPackOperationMessage)4 VerifiedMessage (org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage)4 ViewOnceOpenMessage (org.whispersystems.signalservice.api.messages.multidevice.ViewOnceOpenMessage)4 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)4