Search in sources :

Example 1 with SignalServiceAttachmentStream

use of org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream in project libsignal-service-java by signalapp.

the class DeviceGroupsInputStream method read.

public DeviceGroup read() throws IOException {
    long detailsLength = readRawVarint32();
    byte[] detailsSerialized = new byte[(int) detailsLength];
    Util.readFully(in, detailsSerialized);
    SignalServiceProtos.GroupDetails details = SignalServiceProtos.GroupDetails.parseFrom(detailsSerialized);
    if (!details.hasId()) {
        throw new IOException("ID missing on group record!");
    }
    byte[] id = details.getId().toByteArray();
    Optional<String> name = Optional.fromNullable(details.getName());
    List<String> members = details.getMembersList();
    Optional<SignalServiceAttachmentStream> avatar = Optional.absent();
    boolean active = details.getActive();
    Optional<Integer> expirationTimer = Optional.absent();
    if (details.hasAvatar()) {
        long avatarLength = details.getAvatar().getLength();
        InputStream avatarStream = new ChunkedInputStream.LimitedInputStream(in, avatarLength);
        String avatarContentType = details.getAvatar().getContentType();
        avatar = Optional.of(new SignalServiceAttachmentStream(avatarStream, avatarContentType, avatarLength, Optional.<String>absent(), false, null));
    }
    if (details.hasExpireTimer() && details.getExpireTimer() > 0) {
        expirationTimer = Optional.of(details.getExpireTimer());
    }
    return new DeviceGroup(id, name, members, avatar, active, expirationTimer);
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) SignalServiceAttachmentStream(org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream) SignalServiceProtos(org.whispersystems.signalservice.internal.push.SignalServiceProtos)

Example 2 with SignalServiceAttachmentStream

use of org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream 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 3 with SignalServiceAttachmentStream

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

the class MultiDeviceGroupUpdateJob method sendUpdate.

private void sendUpdate(SignalServiceMessageSender messageSender, File contactsFile) throws IOException, UntrustedIdentityException {
    FileInputStream contactsFileStream = new FileInputStream(contactsFile);
    SignalServiceAttachmentStream attachmentStream = SignalServiceAttachment.newStreamBuilder().withStream(contactsFileStream).withContentType("application/octet-stream").withLength(contactsFile.length()).build();
    messageSender.sendMessage(SignalServiceSyncMessage.forGroups(attachmentStream));
}
Also used : FileInputStream(java.io.FileInputStream) SignalServiceAttachmentStream(org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream)

Example 4 with SignalServiceAttachmentStream

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

the class MultiDeviceContactUpdateJob method sendUpdate.

private void sendUpdate(SignalServiceMessageSender messageSender, File contactsFile) 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(attachmentStream));
        } catch (IOException ioe) {
            throw new NetworkException(ioe);
        }
    }
}
Also used : IOException(java.io.IOException) PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) FileInputStream(java.io.FileInputStream) SignalServiceAttachmentStream(org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream)

Example 5 with SignalServiceAttachmentStream

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

the class MultiDeviceGroupUpdateJob method sendUpdate.

private void sendUpdate(SignalServiceMessageSender messageSender, File contactsFile) throws IOException, UntrustedIdentityException {
    FileInputStream contactsFileStream = new FileInputStream(contactsFile);
    SignalServiceAttachmentStream attachmentStream = SignalServiceAttachment.newStreamBuilder().withStream(contactsFileStream).withContentType("application/octet-stream").withLength(contactsFile.length()).build();
    messageSender.sendMessage(SignalServiceSyncMessage.forGroups(attachmentStream));
}
Also used : FileInputStream(java.io.FileInputStream) SignalServiceAttachmentStream(org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream)

Aggregations

SignalServiceAttachmentStream (org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream)7 FileInputStream (java.io.FileInputStream)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)2 ContactsMessage (org.whispersystems.signalservice.api.messages.multidevice.ContactsMessage)2 PushNetworkException (org.whispersystems.signalservice.api.push.exceptions.PushNetworkException)2 SignalServiceProtos (org.whispersystems.signalservice.internal.push.SignalServiceProtos)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IdentityKey (org.whispersystems.libsignal.IdentityKey)1 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)1 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)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