Search in sources :

Example 1 with ContactsMessage

use of org.whispersystems.signalservice.api.messages.multidevice.ContactsMessage in project Signal-Android by signalapp.

the class MultiDeviceContactUpdateJob method sendUpdate.

private void sendUpdate(SignalServiceMessageSender messageSender, File contactsFile, boolean complete) throws IOException, UntrustedIdentityException, NetworkException {
    if (contactsFile.length() > 0) {
        FileInputStream contactsFileStream = new FileInputStream(contactsFile);
        SignalServiceAttachmentStream attachmentStream = SignalServiceAttachment.newStreamBuilder().withStream(contactsFileStream).withContentType("application/octet-stream").withLength(contactsFile.length()).build();
        try {
            messageSender.sendMessage(SignalServiceSyncMessage.forContacts(new ContactsMessage(attachmentStream, complete)));
        } catch (IOException ioe) {
            throw new NetworkException(ioe);
        }
    }
}
Also used : ContactsMessage(org.whispersystems.signalservice.api.messages.multidevice.ContactsMessage) IOException(java.io.IOException) PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) FileInputStream(java.io.FileInputStream) SignalServiceAttachmentStream(org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream)

Example 2 with ContactsMessage

use of org.whispersystems.signalservice.api.messages.multidevice.ContactsMessage in project Signal-Android by signalapp.

the class MultiDeviceProfileKeyUpdateJob method onRun.

@Override
public void onRun(MasterSecret masterSecret) throws IOException, UntrustedIdentityException {
    if (!TextSecurePreferences.isMultiDevice(getContext())) {
        Log.w(TAG, "Not multi device...");
        return;
    }
    Optional<byte[]> profileKey = Optional.of(ProfileKeyUtil.getProfileKey(getContext()));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DeviceContactsOutputStream out = new DeviceContactsOutputStream(baos);
    out.write(new DeviceContact(TextSecurePreferences.getLocalNumber(getContext()), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), profileKey, false, Optional.absent()));
    out.close();
    SignalServiceAttachmentStream attachmentStream = SignalServiceAttachment.newStreamBuilder().withStream(new ByteArrayInputStream(baos.toByteArray())).withContentType("application/octet-stream").withLength(baos.toByteArray().length).build();
    SignalServiceSyncMessage syncMessage = SignalServiceSyncMessage.forContacts(new ContactsMessage(attachmentStream, false));
    messageSender.sendMessage(syncMessage);
}
Also used : DeviceContact(org.whispersystems.signalservice.api.messages.multidevice.DeviceContact) ByteArrayInputStream(java.io.ByteArrayInputStream) DeviceContactsOutputStream(org.whispersystems.signalservice.api.messages.multidevice.DeviceContactsOutputStream) ContactsMessage(org.whispersystems.signalservice.api.messages.multidevice.ContactsMessage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SignalServiceSyncMessage(org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage) SignalServiceAttachmentStream(org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream)

Aggregations

SignalServiceAttachmentStream (org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream)2 ContactsMessage (org.whispersystems.signalservice.api.messages.multidevice.ContactsMessage)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 DeviceContact (org.whispersystems.signalservice.api.messages.multidevice.DeviceContact)1 DeviceContactsOutputStream (org.whispersystems.signalservice.api.messages.multidevice.DeviceContactsOutputStream)1 SignalServiceSyncMessage (org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage)1 PushNetworkException (org.whispersystems.signalservice.api.push.exceptions.PushNetworkException)1