org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream Java Examples

The following examples show how to use org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public SignalServiceAttachmentPointer uploadAttachment(SignalServiceAttachmentStream attachment) throws IOException {
  byte[]             attachmentKey    = attachment.getResumableUploadSpec().transform(ResumableUploadSpec::getSecretKey).or(() -> Util.getSecretBytes(64));
  byte[]             attachmentIV     = attachment.getResumableUploadSpec().transform(ResumableUploadSpec::getIV).or(() -> Util.getSecretBytes(16));
  long               paddedLength     = PaddingInputStream.getPaddedSize(attachment.getLength());
  InputStream        dataStream       = new PaddingInputStream(attachment.getInputStream(), attachment.getLength());
  long               ciphertextLength = AttachmentCipherOutputStream.getCiphertextLength(paddedLength);
  PushAttachmentData attachmentData   = new PushAttachmentData(attachment.getContentType(),
                                                               dataStream,
                                                               ciphertextLength,
                                                               new AttachmentCipherOutputStreamFactory(attachmentKey, attachmentIV),
                                                               attachment.getListener(),
                                                               attachment.getCancelationSignal(),
                                                               attachment.getResumableUploadSpec().orNull());

  if (attachmentsV3.get()) {
    return uploadAttachmentV3(attachment, attachmentKey, attachmentData);
  } else {
    return uploadAttachmentV2(attachment, attachmentKey, attachmentData);
  }
}
 
Example #2
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private SignalServiceAttachmentPointer uploadAttachmentV3(SignalServiceAttachmentStream attachment, byte[] attachmentKey, PushAttachmentData attachmentData) throws IOException {
  byte[] digest = socket.uploadAttachment(attachmentData);
  return new SignalServiceAttachmentPointer(attachmentData.getResumableUploadSpec().getCdnNumber(),
                                            new SignalServiceAttachmentRemoteId(attachmentData.getResumableUploadSpec().getCdnKey()),
                                            attachment.getContentType(),
                                            attachmentKey,
                                            Optional.of(Util.toIntExact(attachment.getLength())),
                                            attachment.getPreview(),
                                            attachment.getWidth(),
                                            attachment.getHeight(),
                                            Optional.of(digest),
                                            attachment.getFileName(),
                                            attachment.getVoiceNote(),
                                            attachment.getCaption(),
                                            attachment.getBlurHash(),
                                            attachment.getUploadTimestamp());
}
 
Example #3
Source File: Utils.java    From signal-cli with GNU General Public License v3.0 6 votes vote down vote up
static File retrieveAttachment(SignalServiceAttachmentStream stream, File outputFile) throws IOException {
    InputStream input = stream.getInputStream();

    try (OutputStream output = new FileOutputStream(outputFile)) {
        byte[] buffer = new byte[4096];
        int read;

        while ((read = input.read(buffer)) != -1) {
            output.write(buffer, 0, read);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return null;
    }
    return outputFile;
}
 
Example #4
Source File: DeviceContact.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public DeviceContact(SignalServiceAddress address,
                     Optional<String> name,
                     Optional<SignalServiceAttachmentStream> avatar,
                     Optional<String> color,
                     Optional<VerifiedMessage> verified,
                     Optional<ProfileKey> profileKey,
                     boolean blocked,
                     Optional<Integer> expirationTimer,
                     Optional<Integer> inboxPosition,
                     boolean archived)
{
  this.address         = address;
  this.name            = name;
  this.avatar          = avatar;
  this.color           = color;
  this.verified        = verified;
  this.profileKey      = profileKey;
  this.blocked         = blocked;
  this.expirationTimer = expirationTimer;
  this.inboxPosition   = inboxPosition;
  this.archived        = archived;
}
 
Example #5
Source File: MultiDeviceContactUpdateJob.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private Optional<SignalServiceAttachmentStream> getProfileAvatar(@NonNull RecipientId recipientId) {
  if (AvatarHelper.hasAvatar(context, recipientId)) {
    try {
      long length = AvatarHelper.getAvatarLength(context, recipientId);
      return Optional.of(SignalServiceAttachmentStream.newStreamBuilder()
                                                      .withStream(AvatarHelper.getAvatar(context, recipientId))
                                                      .withContentType("image/*")
                                                      .withLength(length)
                                                      .build());
    } catch (IOException e) {
      Log.w(TAG, "Failed to read profile avatar!", e);
      return Optional.absent();
    }
  }

  return Optional.absent();
}
 
Example #6
Source File: DeviceGroup.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public DeviceGroup(byte[] id,
                   Optional<String> name,
                   List<SignalServiceAddress> members,
                   Optional<SignalServiceAttachmentStream> avatar,
                   boolean active,
                   Optional<Integer> expirationTimer,
                   Optional<String> color,
                   boolean blocked,
                   Optional<Integer> inboxPosition,
                   boolean archived)
{
  this.id              = id;
  this.name            = name;
  this.members         = members;
  this.avatar          = avatar;
  this.active          = active;
  this.expirationTimer = expirationTimer;
  this.color           = color;
  this.blocked         = blocked;
  this.inboxPosition   = inboxPosition;
  this.archived        = archived;
}
 
Example #7
Source File: MultiDeviceContactUpdateJob.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
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)),
                                UnidentifiedAccessUtil.getAccessForSync(context));
    } catch (IOException ioe) {
      throw new NetworkException(ioe);
    }
  }
}
 
Example #8
Source File: DeviceContact.java    From libsignal-service-java with GNU General Public License v3.0 6 votes vote down vote up
public DeviceContact(SignalServiceAddress address, Optional<String> name,
                     Optional<SignalServiceAttachmentStream> avatar,
                     Optional<String> color,
                     Optional<VerifiedMessage> verified,
                     Optional<byte[]> profileKey,
                     boolean blocked,
                     Optional<Integer> expirationTimer)
{
  this.address         = address;
  this.name            = name;
  this.avatar          = avatar;
  this.color           = color;
  this.verified        = verified;
  this.profileKey      = profileKey;
  this.blocked         = blocked;
  this.expirationTimer = expirationTimer;
}
 
Example #9
Source File: DeviceGroupsInputStream.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
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();

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

  return new DeviceGroup(id, name, members, avatar, active);
}
 
Example #10
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private SignalServiceAttachmentPointer uploadAttachmentV2(SignalServiceAttachmentStream attachment, byte[] attachmentKey, PushAttachmentData attachmentData) throws NonSuccessfulResponseCodeException, PushNetworkException {
  AttachmentV2UploadAttributes       v2UploadAttributes = null;
  Optional<SignalServiceMessagePipe> localPipe          = pipe.get();

  if (localPipe.isPresent()) {
    Log.d(TAG, "Using pipe to retrieve attachment upload attributes...");
    try {
      v2UploadAttributes = localPipe.get().getAttachmentV2UploadAttributes();
    } catch (IOException e) {
      Log.w(TAG, "Failed to retrieve attachment upload attributes using pipe. Falling back...");
    }
  }

  if (v2UploadAttributes == null) {
    Log.d(TAG, "Not using pipe to retrieve attachment upload attributes...");
    v2UploadAttributes = socket.getAttachmentV2UploadAttributes();
  }

  Pair<Long, byte[]> attachmentIdAndDigest = socket.uploadAttachment(attachmentData, v2UploadAttributes);

  return new SignalServiceAttachmentPointer(0,
                                            new SignalServiceAttachmentRemoteId(attachmentIdAndDigest.first()),
                                            attachment.getContentType(),
                                            attachmentKey,
                                            Optional.of(Util.toIntExact(attachment.getLength())),
                                            attachment.getPreview(),
                                            attachment.getWidth(), attachment.getHeight(),
                                            Optional.of(attachmentIdAndDigest.second()),
                                            attachment.getFileName(),
                                            attachment.getVoiceNote(),
                                            attachment.getCaption(),
                                            attachment.getBlurHash(),
                                            attachment.getUploadTimestamp());
}
 
Example #11
Source File: DeviceGroup.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
public DeviceGroup(byte[] id, Optional<String> name, List<String> members, Optional<SignalServiceAttachmentStream> avatar, boolean active) {
  this.id       = id;
  this.name     = name;
  this.members  = members;
  this.avatar   = avatar;
  this.active   = active;
}
 
Example #12
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
private byte[] createMultiDeviceContactsContent(SignalServiceAttachmentStream contacts, boolean complete) throws IOException {
  Content.Builder     container = Content.newBuilder();
  SyncMessage.Builder builder   = createSyncMessageBuilder();
  builder.setContacts(SyncMessage.Contacts.newBuilder()
                                          .setBlob(createAttachmentPointer(contacts))
                                          .setComplete(complete));

  return container.setSyncMessage(builder).build().toByteArray();
}
 
Example #13
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
private byte[] createMultiDeviceGroupsContent(SignalServiceAttachmentStream groups) throws IOException {
  Content.Builder     container = Content.newBuilder();
  SyncMessage.Builder builder   = createSyncMessageBuilder();
  builder.setGroups(SyncMessage.Groups.newBuilder()
                                      .setBlob(createAttachmentPointer(groups)));

  return container.setSyncMessage(builder).build().toByteArray();
}
 
Example #14
Source File: DeviceGroup.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
public DeviceGroup(byte[] id, Optional<String> name, List<SignalServiceAddress> members,
                   Optional<SignalServiceAttachmentStream> avatar,
                   boolean active, Optional<Integer> expirationTimer,
                   Optional<String> color, boolean blocked)
{
  this.id              = id;
  this.name            = name;
  this.members         = members;
  this.avatar          = avatar;
  this.active          = active;
  this.expirationTimer = expirationTimer;
  this.color           = color;
  this.blocked         = blocked;
}
 
Example #15
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
private Optional<SignalServiceAttachmentStream> createGroupAvatarAttachment(byte[] groupId) throws IOException {
    File file = getGroupAvatarFile(groupId);
    if (!file.exists()) {
        return Optional.absent();
    }

    return Optional.of(Utils.createAttachment(file));
}
 
Example #16
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
private Optional<SignalServiceAttachmentStream> createContactAvatarAttachment(String number) throws IOException {
    File file = getContactAvatarFile(number);
    if (!file.exists()) {
        return Optional.absent();
    }

    return Optional.of(Utils.createAttachment(file));
}
 
Example #17
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
private File retrieveContactAvatarAttachment(SignalServiceAttachment attachment, String number) throws IOException, InvalidMessageException, MissingConfigurationException {
    IOUtils.createPrivateDirectories(pathConfig.getAvatarsPath());
    if (attachment.isPointer()) {
        SignalServiceAttachmentPointer pointer = attachment.asPointer();
        return retrieveAttachment(pointer, getContactAvatarFile(number), false);
    } else {
        SignalServiceAttachmentStream stream = attachment.asStream();
        return Utils.retrieveAttachment(stream, getContactAvatarFile(number));
    }
}
 
Example #18
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
private File retrieveGroupAvatarAttachment(SignalServiceAttachment attachment, byte[] groupId) throws IOException, InvalidMessageException, MissingConfigurationException {
    IOUtils.createPrivateDirectories(pathConfig.getAvatarsPath());
    if (attachment.isPointer()) {
        SignalServiceAttachmentPointer pointer = attachment.asPointer();
        return retrieveAttachment(pointer, getGroupAvatarFile(groupId), false);
    } else {
        SignalServiceAttachmentStream stream = attachment.asStream();
        return Utils.retrieveAttachment(stream, getGroupAvatarFile(groupId));
    }
}
 
Example #19
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
void sendGroups() throws IOException, UntrustedIdentityException {
    File groupsFile = IOUtils.createTempFile();

    try {
        try (OutputStream fos = new FileOutputStream(groupsFile)) {
            DeviceGroupsOutputStream out = new DeviceGroupsOutputStream(fos);
            for (GroupInfo record : account.getGroupStore().getGroups()) {
                out.write(new DeviceGroup(record.groupId, Optional.fromNullable(record.name),
                        new ArrayList<>(record.getMembers()), createGroupAvatarAttachment(record.groupId),
                        record.isMember(account.getSelfAddress()), Optional.of(record.messageExpirationTime),
                        Optional.fromNullable(record.color), record.blocked, Optional.fromNullable(record.inboxPosition), record.archived));
            }
        }

        if (groupsFile.exists() && groupsFile.length() > 0) {
            try (FileInputStream groupsFileStream = new FileInputStream(groupsFile)) {
                SignalServiceAttachmentStream attachmentStream = SignalServiceAttachment.newStreamBuilder()
                        .withStream(groupsFileStream)
                        .withContentType("application/octet-stream")
                        .withLength(groupsFile.length())
                        .build();

                sendSyncMessage(SignalServiceSyncMessage.forGroups(attachmentStream));
            }
        }
    } finally {
        try {
            Files.delete(groupsFile.toPath());
        } catch (IOException e) {
            System.err.println("Failed to delete groups temp file “" + groupsFile + "”: " + e.getMessage());
        }
    }
}
 
Example #20
Source File: Utils.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
static SignalServiceAttachmentStream createAttachment(File attachmentFile) throws IOException {
    InputStream attachmentStream = new FileInputStream(attachmentFile);
    final long attachmentSize = attachmentFile.length();
    final String mime = getFileMimeType(attachmentFile);
    // TODO mabybe add a parameter to set the voiceNote, preview, width, height and caption option
    final long uploadTimestamp = System.currentTimeMillis();
    Optional<byte[]> preview = Optional.absent();
    Optional<String> caption = Optional.absent();
    Optional<String> blurHash = Optional.absent();
    final Optional<ResumableUploadSpec> resumableUploadSpec = Optional.absent();
    return new SignalServiceAttachmentStream(attachmentStream, mime, attachmentSize, Optional.of(attachmentFile.getName()), false, preview, 0, 0, uploadTimestamp, caption, blurHash, null, null, resumableUploadSpec);
}
 
Example #21
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private byte[] createMultiDeviceContactsContent(SignalServiceAttachmentStream contacts, boolean complete) throws IOException {
  Content.Builder     container = Content.newBuilder();
  SyncMessage.Builder builder   = createSyncMessageBuilder();
  builder.setContacts(SyncMessage.Contacts.newBuilder()
                                          .setBlob(createAttachmentPointer(contacts))
                                          .setComplete(complete));

  return container.setSyncMessage(builder).build().toByteArray();
}
 
Example #22
Source File: DeviceContact.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
public DeviceContact(String number, Optional<String> name,
                     Optional<SignalServiceAttachmentStream> avatar,
                     Optional<String> color,
                     Optional<VerifiedMessage> verified,
                     Optional<byte[]> profileKey)
{
  this.number     = number;
  this.name       = name;
  this.avatar     = avatar;
  this.color      = color;
  this.verified   = verified;
  this.profileKey = profileKey;
}
 
Example #23
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private byte[] createMultiDeviceGroupsContent(SignalServiceAttachmentStream groups) throws IOException {
  Content.Builder     container = Content.newBuilder();
  SyncMessage.Builder builder   = createSyncMessageBuilder();
  builder.setGroups(SyncMessage.Groups.newBuilder()
                                      .setBlob(createAttachmentPointer(groups)));

  return container.setSyncMessage(builder).build().toByteArray();
}
 
Example #24
Source File: MultiDeviceContactUpdateJob.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private Optional<SignalServiceAttachmentStream> getAvatar(@NonNull RecipientId recipientId, @Nullable Uri uri) {
  Optional<SignalServiceAttachmentStream> stream = getSystemAvatar(uri);

  if (!stream.isPresent()) {
    return getProfileAvatar(recipientId);
  }

  return stream;
}
 
Example #25
Source File: MultiDeviceProfileKeyUpdateJob.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onRun() throws IOException, UntrustedIdentityException {
  if (!TextSecurePreferences.isMultiDevice(context)) {
    Log.i(TAG, "Not multi device...");
    return;
  }

  Optional<ProfileKey>       profileKey = Optional.of(ProfileKeyUtil.getSelfProfileKey());
  ByteArrayOutputStream      baos       = new ByteArrayOutputStream();
  DeviceContactsOutputStream out        = new DeviceContactsOutputStream(baos);

  out.write(new DeviceContact(RecipientUtil.toSignalServiceAddress(context, Recipient.self()),
                              Optional.absent(),
                              Optional.absent(),
                              Optional.absent(),
                              Optional.absent(),
                              profileKey,
                              false,
                              Optional.absent(),
                              Optional.absent(),
                              false));

  out.close();

  SignalServiceMessageSender    messageSender    = ApplicationDependencies.getSignalServiceMessageSender();
  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, UnidentifiedAccessUtil.getAccessForSync(context));
}
 
Example #26
Source File: MultiDeviceGroupUpdateJob.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
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),
                            UnidentifiedAccessUtil.getAccessForSync(context));
}
 
Example #27
Source File: MultiDeviceGroupUpdateJob.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private Optional<SignalServiceAttachmentStream> getAvatar(@NonNull RecipientId recipientId) throws IOException {
  if (!AvatarHelper.hasAvatar(context, recipientId)) return Optional.absent();

  return Optional.of(SignalServiceAttachment.newStreamBuilder()
                                            .withStream(AvatarHelper.getAvatar(context, recipientId))
                                            .withContentType("image/*")
                                            .withLength(AvatarHelper.getAvatarLength(context, recipientId))
                                            .build());
}
 
Example #28
Source File: DeviceContactsInputStream.java    From libsignal-service-java with GNU General Public License v3.0 4 votes vote down vote up
public DeviceContact read() throws IOException {
  long   detailsLength     = readRawVarint32();
  byte[] detailsSerialized = new byte[(int)detailsLength];
  Util.readFully(in, detailsSerialized);

  SignalServiceProtos.ContactDetails details = SignalServiceProtos.ContactDetails.parseFrom(detailsSerialized);

  if (!SignalServiceAddress.isValidAddress(details.getUuid(), details.getNumber())) {
    throw new IOException("Missing contact address!");
  }

  SignalServiceAddress                    address     = new SignalServiceAddress(UuidUtil.parseOrNull(details.getUuid()), details.getNumber());
  Optional<String>                        name        = Optional.fromNullable(details.getName());
  Optional<SignalServiceAttachmentStream> avatar      = Optional.absent();
  Optional<String>                        color       = details.hasColor() ? Optional.of(details.getColor()) : Optional.<String>absent();
  Optional<VerifiedMessage>               verified    = Optional.absent();
  Optional<byte[]>                        profileKey  = Optional.absent();
  boolean                                 blocked     = false;
  Optional<Integer>                       expireTimer = Optional.absent();

  if (details.hasAvatar()) {
    long        avatarLength      = details.getAvatar().getLength();
    InputStream avatarStream      = new LimitedInputStream(in, avatarLength);
    String      avatarContentType = details.getAvatar().getContentType();

    avatar = Optional.of(new SignalServiceAttachmentStream(avatarStream, avatarContentType, avatarLength, Optional.<String>absent(), false, null));
  }

  if (details.hasVerified()) {
    try {
      if (!SignalServiceAddress.isValidAddress(details.getVerified().getDestinationUuid(), details.getVerified().getDestinationE164())) {
        throw new InvalidMessageException("Missing Verified address!");
      }
      IdentityKey          identityKey = new IdentityKey(details.getVerified().getIdentityKey().toByteArray(), 0);
      SignalServiceAddress destination = new SignalServiceAddress(UuidUtil.parseOrNull(details.getVerified().getDestinationUuid()),
                                                                  details.getVerified().getDestinationE164());

      VerifiedMessage.VerifiedState state;

      switch (details.getVerified().getState()) {
        case VERIFIED:  state = VerifiedMessage.VerifiedState.VERIFIED;   break;
        case UNVERIFIED:state = VerifiedMessage.VerifiedState.UNVERIFIED; break;
        case DEFAULT:   state = VerifiedMessage.VerifiedState.DEFAULT;    break;
        default:        throw new InvalidMessageException("Unknown state: " + details.getVerified().getState());
      }

      verified = Optional.of(new VerifiedMessage(destination, identityKey, state, System.currentTimeMillis()));
    } catch (InvalidKeyException | InvalidMessageException e) {
      Log.w(TAG, e);
      verified = Optional.absent();
    }
  }

  if (details.hasProfileKey()) {
    profileKey = Optional.fromNullable(details.getProfileKey().toByteArray());
  }

  if (details.hasExpireTimer() && details.getExpireTimer() > 0) {
    expireTimer = Optional.of(details.getExpireTimer());
  }

  blocked = details.getBlocked();

  return new DeviceContact(address, name, avatar, color, verified, profileKey, blocked, expireTimer);
}
 
Example #29
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private AttachmentPointer createAttachmentPointer(SignalServiceAttachmentStream attachment)
    throws IOException
{
  return createAttachmentPointer(uploadAttachment(attachment));
}
 
Example #30
Source File: DeviceContact.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public Optional<SignalServiceAttachmentStream> getAvatar() {
  return avatar;
}