Search in sources :

Example 6 with SharedContact

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

the class PushMediaSendJob method deliver.

private boolean deliver(OutgoingMediaMessage message) throws IOException, InsecureFallbackApprovalException, UntrustedIdentityException, UndeliverableMessageException {
    if (message.getRecipient() == null) {
        throw new UndeliverableMessageException("No destination address.");
    }
    try {
        rotateSenderCertificateIfNecessary();
        Recipient messageRecipient = message.getRecipient().fresh();
        if (messageRecipient.isUnregistered()) {
            throw new UndeliverableMessageException(messageRecipient.getId() + " not registered!");
        }
        SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
        SignalServiceAddress address = RecipientUtil.toSignalServiceAddress(context, messageRecipient);
        List<Attachment> attachments = Stream.of(message.getAttachments()).filterNot(Attachment::isSticker).toList();
        List<SignalServiceAttachment> serviceAttachments = getAttachmentPointersFor(attachments);
        Optional<byte[]> profileKey = getProfileKey(messageRecipient);
        Optional<SignalServiceDataMessage.Quote> quote = getQuoteFor(message);
        Optional<SignalServiceDataMessage.Sticker> sticker = getStickerFor(message);
        List<SharedContact> sharedContacts = getSharedContactsFor(message);
        List<Preview> previews = getPreviewsFor(message);
        SignalServiceDataMessage mediaMessage = SignalServiceDataMessage.newBuilder().withBody(message.getBody()).withAttachments(serviceAttachments).withTimestamp(message.getSentTimeMillis()).withExpiration((int) (message.getExpiresIn() / 1000)).withViewOnce(message.isViewOnce()).withProfileKey(profileKey.orNull()).withQuote(quote.orNull()).withSticker(sticker.orNull()).withSharedContacts(sharedContacts).withPreviews(previews).asExpirationUpdate(message.isExpirationUpdate()).build();
        if (Util.equals(SignalStore.account().getAci(), address.getServiceId())) {
            Optional<UnidentifiedAccessPair> syncAccess = UnidentifiedAccessUtil.getAccessForSync(context);
            SendMessageResult result = messageSender.sendSyncMessage(mediaMessage);
            SignalDatabase.messageLog().insertIfPossible(messageRecipient.getId(), message.getSentTimeMillis(), result, ContentHint.RESENDABLE, new MessageId(messageId, true));
            return syncAccess.isPresent();
        } else {
            SendMessageResult result = messageSender.sendDataMessage(address, UnidentifiedAccessUtil.getAccessFor(context, messageRecipient), ContentHint.RESENDABLE, mediaMessage, IndividualSendEvents.EMPTY);
            SignalDatabase.messageLog().insertIfPossible(messageRecipient.getId(), message.getSentTimeMillis(), result, ContentHint.RESENDABLE, new MessageId(messageId, true));
            return result.getSuccess().isUnidentified();
        }
    } catch (UnregisteredUserException e) {
        warn(TAG, String.valueOf(message.getSentTimeMillis()), e);
        throw new InsecureFallbackApprovalException(e);
    } catch (FileNotFoundException e) {
        warn(TAG, String.valueOf(message.getSentTimeMillis()), e);
        throw new UndeliverableMessageException(e);
    } catch (ServerRejectedException e) {
        throw new UndeliverableMessageException(e);
    }
}
Also used : UnregisteredUserException(org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException) FileNotFoundException(java.io.FileNotFoundException) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) InsecureFallbackApprovalException(org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) Preview(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage.Preview) Recipient(org.thoughtcrime.securesms.recipients.Recipient) UnidentifiedAccessPair(org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair) ServerRejectedException(org.whispersystems.signalservice.api.push.exceptions.ServerRejectedException) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) SharedContact(org.whispersystems.signalservice.api.messages.shared.SharedContact) MessageId(org.thoughtcrime.securesms.database.model.MessageId) SyncMessageId(org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId)

Aggregations

SharedContact (org.whispersystems.signalservice.api.messages.shared.SharedContact)6 LinkedList (java.util.LinkedList)4 Attachment (org.thoughtcrime.securesms.attachments.Attachment)3 SignalServiceDataMessage (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage)3 MessageId (org.thoughtcrime.securesms.database.model.MessageId)2 UndeliverableMessageException (org.thoughtcrime.securesms.transport.UndeliverableMessageException)2 SignalServiceAttachment (org.whispersystems.signalservice.api.messages.SignalServiceAttachment)2 Preview (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage.Preview)2 ServerRejectedException (org.whispersystems.signalservice.api.push.exceptions.ServerRejectedException)2 ByteString (com.google.protobuf.ByteString)1 FileNotFoundException (java.io.FileNotFoundException)1 ProtocolInvalidMessageException (org.signal.libsignal.metadata.ProtocolInvalidMessageException)1 PointerAttachment (org.thoughtcrime.securesms.attachments.PointerAttachment)1 Contact (org.thoughtcrime.securesms.contactshare.Contact)1 Avatar (org.thoughtcrime.securesms.contactshare.Contact.Avatar)1 Email (org.thoughtcrime.securesms.contactshare.Contact.Email)1 Name (org.thoughtcrime.securesms.contactshare.Contact.Name)1 Phone (org.thoughtcrime.securesms.contactshare.Contact.Phone)1 PostalAddress (org.thoughtcrime.securesms.contactshare.Contact.PostalAddress)1 SyncMessageId (org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId)1