Search in sources :

Example 21 with Recipient

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

the class AvatarImageView method setAvatarClickHandler.

private void setAvatarClickHandler(final Recipients recipients, boolean quickContactEnabled) {
    if (!recipients.isGroupRecipient() && quickContactEnabled) {
        setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Recipient recipient = recipients.getPrimaryRecipient();
                if (recipient != null && recipient.getContactUri() != null) {
                    ContactsContract.QuickContact.showQuickContact(getContext(), AvatarImageView.this, recipient.getContactUri(), ContactsContract.QuickContact.MODE_LARGE, null);
                } else if (recipient != null) {
                    final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
                    intent.putExtra(ContactsContract.Intents.Insert.PHONE, recipient.getNumber());
                    intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
                    getContext().startActivity(intent);
                }
            }
        });
    } else {
        setOnClickListener(null);
    }
}
Also used : Recipient(org.thoughtcrime.securesms.recipients.Recipient) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View)

Example 22 with Recipient

use of org.thoughtcrime.securesms.recipients.Recipient 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 23 with Recipient

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

the class RegistrationService method handleCommonRegistration.

private void handleCommonRegistration(SignalServiceAccountManager accountManager, String number, String password, String signalingKey, boolean supportsGcm) throws IOException {
    setState(new RegistrationState(RegistrationState.STATE_GENERATING_KEYS, number));
    Recipient self = RecipientFactory.getRecipientsFromString(this, number, false).getPrimaryRecipient();
    IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(this);
    List<PreKeyRecord> records = PreKeyUtil.generatePreKeys(this);
    PreKeyRecord lastResort = PreKeyUtil.generateLastResortKey(this);
    SignedPreKeyRecord signedPreKey = PreKeyUtil.generateSignedPreKey(this, identityKey, true);
    accountManager.setPreKeys(identityKey.getPublicKey(), lastResort, signedPreKey, records);
    setState(new RegistrationState(RegistrationState.STATE_GCM_REGISTERING, number));
    if (supportsGcm) {
        String gcmRegistrationId = GoogleCloudMessaging.getInstance(this).register(GcmRefreshJob.REGISTRATION_ID);
        accountManager.setGcmId(Optional.of(gcmRegistrationId));
        TextSecurePreferences.setGcmRegistrationId(this, gcmRegistrationId);
        TextSecurePreferences.setGcmDisabled(this, false);
    } else {
        TextSecurePreferences.setGcmDisabled(this, true);
    }
    TextSecurePreferences.setWebsocketRegistered(this, true);
    DatabaseFactory.getIdentityDatabase(this).saveIdentity(self.getRecipientId(), identityKey.getPublicKey());
    DirectoryHelper.refreshDirectory(this, accountManager, number);
    DirectoryRefreshListener.schedule(this);
    RotateSignedPreKeyListener.schedule(this);
}
Also used : PreKeyRecord(org.whispersystems.libsignal.state.PreKeyRecord) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient) IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord)

Example 24 with Recipient

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

the class SelectedRecipientsAdapter method getView.

@Override
public View getView(final int position, View v, final ViewGroup parent) {
    if (v == null) {
        v = LayoutInflater.from(context).inflate(R.layout.selected_recipient_list_item, parent, false);
    }
    final RecipientWrapper rw = (RecipientWrapper) getItem(position);
    final Recipient p = rw.getRecipient();
    final boolean modifiable = rw.isModifiable();
    TextView name = (TextView) v.findViewById(R.id.name);
    TextView phone = (TextView) v.findViewById(R.id.phone);
    ImageButton delete = (ImageButton) v.findViewById(R.id.delete);
    name.setText(p.getName());
    phone.setText(p.getNumber());
    delete.setVisibility(modifiable ? View.VISIBLE : View.GONE);
    delete.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (onRecipientDeletedListener != null) {
                onRecipientDeletedListener.onRecipientDeleted(recipients.get(position).getRecipient());
            }
        }
    });
    return v;
}
Also used : ImageButton(android.widget.ImageButton) Recipient(org.thoughtcrime.securesms.recipients.Recipient) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View)

Example 25 with Recipient

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

the class IdentityUtil method getRemoteIdentityKey.

@UiThread
public static ListenableFuture<Optional<IdentityKey>> getRemoteIdentityKey(final Context context, final MasterSecret masterSecret, final Recipient recipient) {
    final SettableFuture<Optional<IdentityKey>> future = new SettableFuture<>();
    new AsyncTask<Recipient, Void, Optional<IdentityKey>>() {

        @Override
        protected Optional<IdentityKey> doInBackground(Recipient... recipient) {
            SessionStore sessionStore = new TextSecureSessionStore(context, masterSecret);
            SignalProtocolAddress axolotlAddress = new SignalProtocolAddress(recipient[0].getNumber(), SignalServiceAddress.DEFAULT_DEVICE_ID);
            SessionRecord record = sessionStore.loadSession(axolotlAddress);
            if (record == null) {
                return Optional.absent();
            }
            return Optional.fromNullable(record.getSessionState().getRemoteIdentityKey());
        }

        @Override
        protected void onPostExecute(Optional<IdentityKey> result) {
            future.set(result);
        }
    }.execute(recipient);
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) IdentityKey(org.whispersystems.libsignal.IdentityKey) Optional(org.whispersystems.libsignal.util.guava.Optional) Recipient(org.thoughtcrime.securesms.recipients.Recipient) TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) SessionStore(org.whispersystems.libsignal.state.SessionStore) TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) SessionRecord(org.whispersystems.libsignal.state.SessionRecord) UiThread(android.support.annotation.UiThread)

Aggregations

Recipient (org.thoughtcrime.securesms.recipients.Recipient)26 View (android.view.View)5 Recipients (org.thoughtcrime.securesms.recipients.Recipients)5 InvalidNumberException (org.whispersystems.signalservice.api.util.InvalidNumberException)5 RecipientFormattingException (org.thoughtcrime.securesms.recipients.RecipientFormattingException)3 Intent (android.content.Intent)2 AdapterView (android.widget.AdapterView)2 TextView (android.widget.TextView)2 File (java.io.File)2 RecipientsAdapter (org.thoughtcrime.securesms.contacts.RecipientsAdapter)2 IdentityKey (org.whispersystems.libsignal.IdentityKey)2 SignalProtocolAddress (org.whispersystems.libsignal.SignalProtocolAddress)2 Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 UiThread (android.support.annotation.UiThread)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1