Search in sources :

Example 1 with ContactData

use of org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData in project Signal-Android by WhisperSystems.

the class ConversationActivity method addAttachmentContactInfo.

private void addAttachmentContactInfo(Uri contactUri) {
    ContactAccessor contactDataList = ContactAccessor.getInstance();
    ContactData contactData = contactDataList.getContactData(this, contactUri);
    if (contactData.numbers.size() == 1)
        composeText.append(contactData.numbers.get(0).number);
    else if (contactData.numbers.size() > 1)
        selectContactInfo(contactData);
}
Also used : ContactData(org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData) ContactAccessor(org.thoughtcrime.securesms.contacts.ContactAccessor)

Example 2 with ContactData

use of org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData in project Signal-Android by signalapp.

the class MultiDeviceContactUpdateJob method generateFullContactUpdate.

private void generateFullContactUpdate() throws IOException, UntrustedIdentityException, NetworkException {
    if (!Permissions.hasAny(context, Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS)) {
        Log.w(TAG, "No contact permissions, skipping multi-device contact update...");
        return;
    }
    File contactDataFile = createTempFile("multidevice-contact-update");
    try {
        DeviceContactsOutputStream out = new DeviceContactsOutputStream(new FileOutputStream(contactDataFile));
        Collection<ContactData> contacts = ContactAccessor.getInstance().getContactsWithPush(context);
        for (ContactData contactData : contacts) {
            Uri contactUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactData.id));
            Address address = Address.fromExternal(context, contactData.numbers.get(0).number);
            Recipient recipient = Recipient.from(context, address, false);
            Optional<IdentityDatabase.IdentityRecord> identity = DatabaseFactory.getIdentityDatabase(context).getIdentity(address);
            Optional<VerifiedMessage> verified = getVerifiedMessage(recipient, identity);
            Optional<String> name = Optional.fromNullable(contactData.name);
            Optional<String> color = Optional.of(recipient.getColor().serialize());
            Optional<byte[]> profileKey = Optional.fromNullable(recipient.getProfileKey());
            boolean blocked = recipient.isBlocked();
            Optional<Integer> expireTimer = recipient.getExpireMessages() > 0 ? Optional.of(recipient.getExpireMessages()) : Optional.absent();
            out.write(new DeviceContact(address.toPhoneString(), name, getAvatar(contactUri), color, verified, profileKey, blocked, expireTimer));
        }
        if (ProfileKeyUtil.hasProfileKey(context)) {
            out.write(new DeviceContact(TextSecurePreferences.getLocalNumber(context), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.of(ProfileKeyUtil.getProfileKey(context)), false, Optional.absent()));
        }
        out.close();
        sendUpdate(messageSender, contactDataFile, true);
    } catch (InvalidNumberException e) {
        Log.w(TAG, e);
    } finally {
        if (contactDataFile != null)
            contactDataFile.delete();
    }
}
Also used : DeviceContact(org.whispersystems.signalservice.api.messages.multidevice.DeviceContact) Address(org.thoughtcrime.securesms.database.Address) DeviceContactsOutputStream(org.whispersystems.signalservice.api.messages.multidevice.DeviceContactsOutputStream) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Uri(android.net.Uri) FileOutputStream(java.io.FileOutputStream) ContactData(org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData) VerifiedMessage(org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage) File(java.io.File)

Example 3 with ContactData

use of org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData in project Signal-Android by signalapp.

the class ConversationActivity method addAttachmentContactInfo.

private void addAttachmentContactInfo(Uri contactUri) {
    ContactAccessor contactDataList = ContactAccessor.getInstance();
    ContactData contactData = contactDataList.getContactData(this, contactUri);
    if (contactData.numbers.size() == 1)
        composeText.append(contactData.numbers.get(0).number);
    else if (contactData.numbers.size() > 1)
        selectContactInfo(contactData);
}
Also used : ContactData(org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData) ContactAccessor(org.thoughtcrime.securesms.contacts.ContactAccessor)

Example 4 with ContactData

use of org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData in project Signal-Android by WhisperSystems.

the class ConversationParentFragment method addAttachmentContactInfo.

private void addAttachmentContactInfo(Uri contactUri) {
    ContactAccessor contactDataList = ContactAccessor.getInstance();
    ContactData contactData = contactDataList.getContactData(requireContext(), contactUri);
    if (contactData.numbers.size() == 1)
        composeText.append(contactData.numbers.get(0).number);
    else if (contactData.numbers.size() > 1)
        selectContactInfo(contactData);
}
Also used : ContactData(org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData) ContactAccessor(org.thoughtcrime.securesms.contacts.ContactAccessor)

Aggregations

ContactData (org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData)4 ContactAccessor (org.thoughtcrime.securesms.contacts.ContactAccessor)3 Uri (android.net.Uri)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 Address (org.thoughtcrime.securesms.database.Address)1 Recipient (org.thoughtcrime.securesms.recipients.Recipient)1 DeviceContact (org.whispersystems.signalservice.api.messages.multidevice.DeviceContact)1 DeviceContactsOutputStream (org.whispersystems.signalservice.api.messages.multidevice.DeviceContactsOutputStream)1 VerifiedMessage (org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage)1 InvalidNumberException (org.whispersystems.signalservice.api.util.InvalidNumberException)1