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();
}
}
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();
}
}
Aggregations