Search in sources :

Example 1 with RecipientFormattingException

use of org.thoughtcrime.securesms.recipients.RecipientFormattingException in project Signal-Android by WhisperSystems.

the class ConversationActivity method sendMessage.

private void sendMessage() {
    try {
        Recipients recipients = getRecipients();
        if (recipients == null) {
            throw new RecipientFormattingException("Badly formatted");
        }
        boolean forceSms = sendButton.isManualSelection() && sendButton.getSelectedTransport().isSms();
        int subscriptionId = sendButton.getSelectedTransport().getSimSubscriptionId().or(-1);
        long expiresIn = recipients.getExpireMessages() * 1000;
        Log.w(TAG, "isManual Selection: " + sendButton.isManualSelection());
        Log.w(TAG, "forceSms: " + forceSms);
        if ((!recipients.isSingleRecipient() || recipients.isEmailRecipient()) && !isMmsEnabled) {
            handleManualMmsRequired();
        } else if (attachmentManager.isAttachmentPresent() || !recipients.isSingleRecipient() || recipients.isGroupRecipient() || recipients.isEmailRecipient()) {
            sendMediaMessage(forceSms, expiresIn, subscriptionId);
        } else {
            sendTextMessage(forceSms, expiresIn, subscriptionId);
        }
    } catch (RecipientFormattingException ex) {
        Toast.makeText(ConversationActivity.this, R.string.ConversationActivity_recipient_is_not_a_valid_sms_or_email_address_exclamation, Toast.LENGTH_LONG).show();
        Log.w(TAG, ex);
    } catch (InvalidMessageException ex) {
        Toast.makeText(ConversationActivity.this, R.string.ConversationActivity_message_is_empty_exclamation, Toast.LENGTH_SHORT).show();
        Log.w(TAG, ex);
    }
}
Also used : InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) Recipients(org.thoughtcrime.securesms.recipients.Recipients) RecipientFormattingException(org.thoughtcrime.securesms.recipients.RecipientFormattingException)

Example 2 with RecipientFormattingException

use of org.thoughtcrime.securesms.recipients.RecipientFormattingException in project Signal-Android by WhisperSystems.

the class SingleRecipientPanel method getRecipients.

public Recipients getRecipients() throws RecipientFormattingException {
    String rawText = recipientsText.getText().toString();
    Recipients recipients = RecipientFactory.getRecipientsFromString(getContext(), rawText, true);
    if (recipients.isEmpty())
        throw new RecipientFormattingException("Recipient List Is Empty!");
    return recipients;
}
Also used : Recipients(org.thoughtcrime.securesms.recipients.Recipients) RecipientFormattingException(org.thoughtcrime.securesms.recipients.RecipientFormattingException)

Example 3 with RecipientFormattingException

use of org.thoughtcrime.securesms.recipients.RecipientFormattingException in project Signal-Android by signalapp.

the class PushGroupSendJob method onPushSend.

@Override
public void onPushSend() throws MmsException, IOException, NoSuchMessageException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    OutgoingMediaMessage message = database.getOutgoingMessage(messageId);
    try {
        deliver(message, filterAddress == null ? null : Address.fromSerialized(filterAddress));
        database.markAsSent(messageId, true);
        markAttachmentsUploaded(messageId, message.getAttachments());
        if (message.getExpiresIn() > 0 && !message.isExpirationUpdate()) {
            database.markExpireStarted(messageId);
            ApplicationContext.getInstance(context).getExpiringMessageManager().scheduleDeletion(messageId, true, message.getExpiresIn());
        }
    } catch (InvalidNumberException | RecipientFormattingException | UndeliverableMessageException e) {
        Log.w(TAG, e);
        database.markAsSentFailed(messageId);
        notifyMediaMessageDeliveryFailed(context, messageId);
    } catch (EncapsulatedExceptions e) {
        Log.w(TAG, e);
        List<NetworkFailure> failures = new LinkedList<>();
        for (NetworkFailureException nfe : e.getNetworkExceptions()) {
            failures.add(new NetworkFailure(Address.fromSerialized(nfe.getE164number())));
        }
        for (UntrustedIdentityException uie : e.getUntrustedIdentityExceptions()) {
            database.addMismatchedIdentity(messageId, Address.fromSerialized(uie.getE164Number()), uie.getIdentityKey());
        }
        database.addFailures(messageId, failures);
        if (e.getNetworkExceptions().isEmpty() && e.getUntrustedIdentityExceptions().isEmpty()) {
            database.markAsSent(messageId, true);
            markAttachmentsUploaded(messageId, message.getAttachments());
        } else {
            database.markAsSentFailed(messageId);
            notifyMediaMessageDeliveryFailed(context, messageId);
        }
    }
}
Also used : EncapsulatedExceptions(org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) LinkedList(java.util.LinkedList) List(java.util.List) NetworkFailureException(org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException) NetworkFailure(org.thoughtcrime.securesms.database.documents.NetworkFailure) RecipientFormattingException(org.thoughtcrime.securesms.recipients.RecipientFormattingException) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 4 with RecipientFormattingException

use of org.thoughtcrime.securesms.recipients.RecipientFormattingException in project Signal-Android by WhisperSystems.

the class ConversationParentFragment method sendMessage.

private void sendMessage(@Nullable String metricId) {
    if (inputPanel.isRecordingInLockedMode()) {
        inputPanel.releaseRecordingLock();
        return;
    }
    Draft voiceNote = draftViewModel.getVoiceNoteDraft();
    if (voiceNote != null) {
        AudioSlide audioSlide = AudioSlide.createFromVoiceNoteDraft(requireContext(), voiceNote);
        sendVoiceNote(Objects.requireNonNull(audioSlide.getUri()), audioSlide.getFileSize());
        draftViewModel.clearVoiceNoteDraft();
        return;
    }
    try {
        Recipient recipient = getRecipient();
        if (recipient == null) {
            throw new RecipientFormattingException("Badly formatted");
        }
        String message = getMessage();
        TransportOption transport = sendButton.getSelectedTransport();
        boolean forceSms = (recipient.isForceSmsSelection() || sendButton.isManualSelection()) && transport.isSms();
        int subscriptionId = sendButton.getSelectedTransport().getSimSubscriptionId().or(-1);
        long expiresIn = TimeUnit.SECONDS.toMillis(recipient.getExpiresInSeconds());
        boolean initiating = threadId == -1;
        boolean needsSplit = !transport.isSms() && message.length() > transport.calculateCharacters(message).maxPrimaryMessageSize;
        boolean isMediaMessage = attachmentManager.isAttachmentPresent() || recipient.isGroup() || recipient.getEmail().isPresent() || inputPanel.getQuote().isPresent() || composeText.hasMentions() || linkPreviewViewModel.hasLinkPreview() || needsSplit;
        Log.i(TAG, "[sendMessage] recipient: " + recipient.getId() + ", threadId: " + threadId + ",  forceSms: " + forceSms + ", isManual: " + sendButton.isManualSelection());
        if ((recipient.isMmsGroup() || recipient.getEmail().isPresent()) && !isMmsEnabled) {
            handleManualMmsRequired();
        } else if (!forceSms && (identityRecords.isUnverified(true) || identityRecords.isUntrusted(true))) {
            handleRecentSafetyNumberChange();
        } else if (isMediaMessage) {
            sendMediaMessage(forceSms, expiresIn, false, subscriptionId, initiating, metricId);
        } else {
            sendTextMessage(forceSms, expiresIn, subscriptionId, initiating, metricId);
        }
    } catch (RecipientFormattingException ex) {
        Toast.makeText(requireContext(), R.string.ConversationActivity_recipient_is_not_a_valid_sms_or_email_address_exclamation, Toast.LENGTH_LONG).show();
        Log.w(TAG, ex);
    } catch (InvalidMessageException ex) {
        Toast.makeText(requireContext(), R.string.ConversationActivity_message_is_empty_exclamation, Toast.LENGTH_SHORT).show();
        Log.w(TAG, ex);
    }
}
Also used : TransportOption(org.thoughtcrime.securesms.TransportOption) VoiceNoteDraft(org.thoughtcrime.securesms.components.voice.VoiceNoteDraft) Draft(org.thoughtcrime.securesms.database.DraftDatabase.Draft) InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) AudioSlide(org.thoughtcrime.securesms.mms.AudioSlide) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SpannableString(android.text.SpannableString) RecipientFormattingException(org.thoughtcrime.securesms.recipients.RecipientFormattingException) SuppressLint(android.annotation.SuppressLint)

Example 5 with RecipientFormattingException

use of org.thoughtcrime.securesms.recipients.RecipientFormattingException in project Signal-Android by WhisperSystems.

the class MmsDatabase method insertMessageInbox.

private Optional<InsertResult> insertMessageInbox(MasterSecretUnion masterSecret, IncomingMediaMessage retrieved, String contentLocation, long threadId, long mailbox) throws MmsException {
    if (threadId == -1 || retrieved.isGroupMessage()) {
        try {
            threadId = getThreadIdFor(retrieved);
        } catch (RecipientFormattingException e) {
            Log.w("MmsDatabase", e);
            if (threadId == -1)
                throw new MmsException(e);
        }
    }
    ContentValues contentValues = new ContentValues();
    contentValues.put(DATE_SENT, retrieved.getSentTimeMillis());
    contentValues.put(ADDRESS, retrieved.getAddresses().getFrom());
    contentValues.put(MESSAGE_BOX, mailbox);
    contentValues.put(MESSAGE_TYPE, PduHeaders.MESSAGE_TYPE_RETRIEVE_CONF);
    contentValues.put(THREAD_ID, threadId);
    contentValues.put(CONTENT_LOCATION, contentLocation);
    contentValues.put(STATUS, Status.DOWNLOAD_INITIALIZED);
    contentValues.put(DATE_RECEIVED, generatePduCompatTimestamp());
    contentValues.put(PART_COUNT, retrieved.getAttachments().size());
    contentValues.put(SUBSCRIPTION_ID, retrieved.getSubscriptionId());
    contentValues.put(EXPIRES_IN, retrieved.getExpiresIn());
    contentValues.put(READ, retrieved.isExpirationUpdate() ? 1 : 0);
    if (!contentValues.containsKey(DATE_SENT)) {
        contentValues.put(DATE_SENT, contentValues.getAsLong(DATE_RECEIVED));
    }
    if (retrieved.isPushMessage() && isDuplicate(retrieved, threadId)) {
        Log.w(TAG, "Ignoring duplicate media message (" + retrieved.getSentTimeMillis() + ")");
        return Optional.absent();
    }
    long messageId = insertMediaMessage(masterSecret, retrieved.getAddresses(), retrieved.getBody(), retrieved.getAttachments(), contentValues);
    if (!Types.isExpirationTimerUpdate(mailbox)) {
        DatabaseFactory.getThreadDatabase(context).setUnread(threadId);
        DatabaseFactory.getThreadDatabase(context).update(threadId, true);
    }
    notifyConversationListeners(threadId);
    jobManager.add(new TrimThreadJob(context, threadId));
    return Optional.of(new InsertResult(messageId, threadId));
}
Also used : ContentValues(android.content.ContentValues) TrimThreadJob(org.thoughtcrime.securesms.jobs.TrimThreadJob) MmsException(ws.com.google.android.mms.MmsException) RecipientFormattingException(org.thoughtcrime.securesms.recipients.RecipientFormattingException)

Aggregations

RecipientFormattingException (org.thoughtcrime.securesms.recipients.RecipientFormattingException)10 Recipient (org.thoughtcrime.securesms.recipients.Recipient)4 Recipients (org.thoughtcrime.securesms.recipients.Recipients)4 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)3 SuppressLint (android.annotation.SuppressLint)2 ContentValues (android.content.ContentValues)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)2 NetworkFailure (org.thoughtcrime.securesms.database.documents.NetworkFailure)2 TrimThreadJob (org.thoughtcrime.securesms.jobs.TrimThreadJob)2 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)2 UndeliverableMessageException (org.thoughtcrime.securesms.transport.UndeliverableMessageException)2 UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)2 EncapsulatedExceptions (org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions)2 NetworkFailureException (org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException)2 InvalidNumberException (org.whispersystems.signalservice.api.util.InvalidNumberException)2 SpannableString (android.text.SpannableString)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1