Search in sources :

Example 6 with RecipientFormattingException

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

the class SingleRecipientPanel method initRecipientsEditor.

private void initRecipientsEditor() {
    Recipients recipients;
    recipientsText = (RecipientsEditor) findViewById(R.id.recipients_text);
    try {
        recipients = getRecipients();
    } catch (RecipientFormattingException e) {
        recipients = RecipientFactory.getRecipientsFor(getContext(), new LinkedList<Recipient>(), true);
    }
    recipients.addListener(this);
    recipientsText.setAdapter(new RecipientsAdapter(this.getContext()));
    recipientsText.populate(recipients);
    recipientsText.setOnFocusChangeListener(new FocusChangedListener());
    recipientsText.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (panelChangeListener != null) {
                try {
                    panelChangeListener.onRecipientsPanelUpdate(getRecipients());
                } catch (RecipientFormattingException rfe) {
                    panelChangeListener.onRecipientsPanelUpdate(null);
                }
            }
            recipientsText.setText("");
        }
    });
}
Also used : Recipients(org.thoughtcrime.securesms.recipients.Recipients) Recipient(org.thoughtcrime.securesms.recipients.Recipient) View(android.view.View) AdapterView(android.widget.AdapterView) AdapterView(android.widget.AdapterView) RecipientsAdapter(org.thoughtcrime.securesms.contacts.RecipientsAdapter) RecipientFormattingException(org.thoughtcrime.securesms.recipients.RecipientFormattingException)

Example 7 with RecipientFormattingException

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

the class PushRecipientsPanel 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 8 with RecipientFormattingException

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

the class PushGroupSendJob method onPushSend.

@Override
public void onPushSend(MasterSecret masterSecret) throws MmsException, IOException, NoSuchMessageException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    OutgoingMediaMessage message = database.getOutgoingMessage(masterSecret, messageId);
    try {
        deliver(masterSecret, message, filterRecipientId);
        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()) {
            Recipient recipient = RecipientFactory.getRecipientsFromString(context, nfe.getE164number(), false).getPrimaryRecipient();
            failures.add(new NetworkFailure(recipient.getRecipientId()));
        }
        for (UntrustedIdentityException uie : e.getUntrustedIdentityExceptions()) {
            Recipient recipient = RecipientFactory.getRecipientsFromString(context, uie.getE164Number(), false).getPrimaryRecipient();
            database.addMismatchedIdentity(messageId, recipient.getRecipientId(), 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) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) Recipient(org.thoughtcrime.securesms.recipients.Recipient) NetworkFailure(org.thoughtcrime.securesms.database.documents.NetworkFailure) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) LinkedList(java.util.LinkedList) List(java.util.List) NetworkFailureException(org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException) RecipientFormattingException(org.thoughtcrime.securesms.recipients.RecipientFormattingException) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 9 with RecipientFormattingException

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

the class MmsDatabase method insertMessageInbox.

private Optional<InsertResult> insertMessageInbox(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.getFrom().serialize());
    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(retrieved.getBody(), retrieved.getAttachments(), contentValues, null);
    if (!Types.isExpirationTimerUpdate(mailbox)) {
        DatabaseFactory.getThreadDatabase(context).incrementUnread(threadId, 1);
        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(org.thoughtcrime.securesms.mms.MmsException) RecipientFormattingException(org.thoughtcrime.securesms.recipients.RecipientFormattingException)

Example 10 with RecipientFormattingException

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

the class ConversationActivity method sendMessage.

private void sendMessage() {
    try {
        Recipient recipient = getRecipient();
        if (recipient == null) {
            throw new RecipientFormattingException("Badly formatted");
        }
        boolean forceSms = sendButton.isManualSelection() && sendButton.getSelectedTransport().isSms();
        int subscriptionId = sendButton.getSelectedTransport().getSimSubscriptionId().or(-1);
        long expiresIn = recipient.getExpireMessages() * 1000L;
        boolean initiating = threadId == -1;
        Log.w(TAG, "isManual Selection: " + sendButton.isManualSelection());
        Log.w(TAG, "forceSms: " + forceSms);
        if ((recipient.isMmsGroupRecipient() || recipient.getAddress().isEmail()) && !isMmsEnabled) {
            handleManualMmsRequired();
        } else if (!forceSms && identityRecords.isUnverified()) {
            handleUnverifiedRecipients();
        } else if (!forceSms && identityRecords.isUntrusted()) {
            handleUntrustedRecipients();
        } else if (attachmentManager.isAttachmentPresent() || recipient.isGroupRecipient() || recipient.getAddress().isEmail()) {
            sendMediaMessage(forceSms, expiresIn, subscriptionId, initiating);
        } else {
            sendTextMessage(forceSms, expiresIn, subscriptionId, initiating);
        }
    } 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) Recipient(org.thoughtcrime.securesms.recipients.Recipient) RecipientFormattingException(org.thoughtcrime.securesms.recipients.RecipientFormattingException) SuppressLint(android.annotation.SuppressLint)

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