Search in sources :

Example 1 with DeviceContactsOutputStream

use of org.whispersystems.signalservice.api.messages.multidevice.DeviceContactsOutputStream in project Signal-Android by WhisperSystems.

the class MultiDeviceContactUpdateJob method generateSingleContactUpdate.

private void generateSingleContactUpdate(long recipientId) throws IOException, UntrustedIdentityException, NetworkException {
    SignalServiceMessageSender messageSender = messageSenderFactory.create();
    File contactDataFile = createTempFile("multidevice-contact-update");
    try {
        DeviceContactsOutputStream out = new DeviceContactsOutputStream(new FileOutputStream(contactDataFile));
        Recipient recipient = RecipientFactory.getRecipientForId(context, recipientId, false);
        out.write(new DeviceContact(Util.canonicalizeNumber(context, recipient.getNumber()), Optional.fromNullable(recipient.getName()), getAvatar(recipient.getContactUri()), Optional.fromNullable(recipient.getColor().serialize())));
        out.close();
        sendUpdate(messageSender, contactDataFile);
    } catch (InvalidNumberException e) {
        Log.w(TAG, e);
    } finally {
        if (contactDataFile != null)
            contactDataFile.delete();
    }
}
Also used : DeviceContact(org.whispersystems.signalservice.api.messages.multidevice.DeviceContact) DeviceContactsOutputStream(org.whispersystems.signalservice.api.messages.multidevice.DeviceContactsOutputStream) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) FileOutputStream(java.io.FileOutputStream) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) Recipient(org.thoughtcrime.securesms.recipients.Recipient) File(java.io.File)

Example 2 with DeviceContactsOutputStream

use of org.whispersystems.signalservice.api.messages.multidevice.DeviceContactsOutputStream in project Signal-Android by WhisperSystems.

the class MultiDeviceContactUpdateJob method generateFullContactUpdate.

private void generateFullContactUpdate() throws IOException, UntrustedIdentityException, NetworkException {
    SignalServiceMessageSender messageSender = messageSenderFactory.create();
    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));
            String number = Util.canonicalizeNumber(context, contactData.numbers.get(0).number);
            Optional<String> name = Optional.fromNullable(contactData.name);
            Optional<String> color = getColor(number);
            out.write(new DeviceContact(number, name, getAvatar(contactUri), color));
        }
        out.close();
        sendUpdate(messageSender, contactDataFile);
    } catch (InvalidNumberException e) {
        Log.w(TAG, e);
    } finally {
        if (contactDataFile != null)
            contactDataFile.delete();
    }
}
Also used : DeviceContact(org.whispersystems.signalservice.api.messages.multidevice.DeviceContact) DeviceContactsOutputStream(org.whispersystems.signalservice.api.messages.multidevice.DeviceContactsOutputStream) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) FileOutputStream(java.io.FileOutputStream) ContactData(org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) File(java.io.File) Uri(android.net.Uri)

Aggregations

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