Java Code Examples for org.whispersystems.signalservice.internal.push.SignalServiceProtos.SyncMessage#Builder

The following examples show how to use org.whispersystems.signalservice.internal.push.SignalServiceProtos.SyncMessage#Builder . 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 libsignal-service-java with GNU General Public License v3.0 6 votes vote down vote up
private byte[] createMultiDeviceVerifiedContent(VerifiedMessage verifiedMessage, byte[] nullMessage) {
  Content.Builder     container              = Content.newBuilder();
  SyncMessage.Builder syncMessage            = createSyncMessageBuilder();
  Verified.Builder    verifiedMessageBuilder = Verified.newBuilder();

  verifiedMessageBuilder.setNullMessage(ByteString.copyFrom(nullMessage));
  verifiedMessageBuilder.setIdentityKey(ByteString.copyFrom(verifiedMessage.getIdentityKey().serialize()));

  if (verifiedMessage.getDestination().getUuid().isPresent()) {
    verifiedMessageBuilder.setDestinationUuid(verifiedMessage.getDestination().getUuid().get().toString());
  }

  if (verifiedMessage.getDestination().getNumber().isPresent()) {
    verifiedMessageBuilder.setDestinationE164(verifiedMessage.getDestination().getNumber().get());
  }

  switch(verifiedMessage.getVerified()) {
    case DEFAULT:    verifiedMessageBuilder.setState(Verified.State.DEFAULT);    break;
    case VERIFIED:   verifiedMessageBuilder.setState(Verified.State.VERIFIED);   break;
    case UNVERIFIED: verifiedMessageBuilder.setState(Verified.State.UNVERIFIED); break;
    default:         throw new AssertionError("Unknown: " + verifiedMessage.getVerified());
  }

  syncMessage.setVerified(verifiedMessageBuilder);
  return container.setSyncMessage(syncMessage).build().toByteArray();
}
 
Example 2
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private byte[] createMultiDeviceReadContent(List<ReadMessage> readMessages) {
  Content.Builder     container = Content.newBuilder();
  SyncMessage.Builder builder   = createSyncMessageBuilder();

  for (ReadMessage readMessage : readMessages) {
    SyncMessage.Read.Builder readBuilder = SyncMessage.Read.newBuilder().setTimestamp(readMessage.getTimestamp());

    if (readMessage.getSender().getUuid().isPresent()) {
      readBuilder.setSenderUuid(readMessage.getSender().getUuid().get().toString());
    }

    if (readMessage.getSender().getNumber().isPresent()) {
      readBuilder.setSenderE164(readMessage.getSender().getNumber().get());
    }

    builder.addRead(readBuilder.build());
  }

  return container.setSyncMessage(builder).build().toByteArray();
}
 
Example 3
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 6 votes vote down vote up
private byte[] createMultiDeviceBlockedContent(BlockedListMessage blocked) {
  Content.Builder             container      = Content.newBuilder();
  SyncMessage.Builder         syncMessage    = createSyncMessageBuilder();
  SyncMessage.Blocked.Builder blockedMessage = SyncMessage.Blocked.newBuilder();

  for (SignalServiceAddress address : blocked.getAddresses()) {
    if (address.getUuid().isPresent()) {
      blockedMessage.addUuids(address.getUuid().get().toString());
    }
    if (address.getNumber().isPresent()) {
      blockedMessage.addNumbers(address.getNumber().get());
    }
  }

  for (byte[] groupId : blocked.getGroupIds()) {
    blockedMessage.addGroupIds(ByteString.copyFrom(groupId));
  }

  return container.setSyncMessage(syncMessage.setBlocked(blockedMessage)).build().toByteArray();
}
 
Example 4
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private byte[] createMultiDeviceBlockedContent(BlockedListMessage blocked) {
  Content.Builder             container      = Content.newBuilder();
  SyncMessage.Builder         syncMessage    = createSyncMessageBuilder();
  SyncMessage.Blocked.Builder blockedMessage = SyncMessage.Blocked.newBuilder();

  for (SignalServiceAddress address : blocked.getAddresses()) {
    if (address.getUuid().isPresent()) {
      blockedMessage.addUuids(address.getUuid().get().toString());
    }
    if (address.getNumber().isPresent()) {
      blockedMessage.addNumbers(address.getNumber().get());
    }
  }

  for (byte[] groupId : blocked.getGroupIds()) {
    blockedMessage.addGroupIds(ByteString.copyFrom(groupId));
  }

  return container.setSyncMessage(syncMessage.setBlocked(blockedMessage)).build().toByteArray();
}
 
Example 5
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private byte[] createMultiDeviceConfigurationContent(ConfigurationMessage configuration) {
  Content.Builder                   container            = Content.newBuilder();
  SyncMessage.Builder               syncMessage          = createSyncMessageBuilder();
  SyncMessage.Configuration.Builder configurationMessage = SyncMessage.Configuration.newBuilder();

  if (configuration.getReadReceipts().isPresent()) {
    configurationMessage.setReadReceipts(configuration.getReadReceipts().get());
  }

  if (configuration.getUnidentifiedDeliveryIndicators().isPresent()) {
    configurationMessage.setUnidentifiedDeliveryIndicators(configuration.getUnidentifiedDeliveryIndicators().get());
  }

  if (configuration.getTypingIndicators().isPresent()) {
    configurationMessage.setTypingIndicators(configuration.getTypingIndicators().get());
  }

  if (configuration.getLinkPreviews().isPresent()) {
    configurationMessage.setLinkPreviews(configuration.getLinkPreviews().get());
  }

  configurationMessage.setProvisioningVersion(ProvisioningProtos.ProvisioningVersion.CURRENT_VALUE);

  return container.setSyncMessage(syncMessage.setConfiguration(configurationMessage)).build().toByteArray();
}
 
Example 6
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 6 votes vote down vote up
private byte[] createMultiDeviceViewOnceOpenContent(ViewOnceOpenMessage readMessage) {
  Content.Builder                  container       = Content.newBuilder();
  SyncMessage.Builder              builder         = createSyncMessageBuilder();
  SyncMessage.ViewOnceOpen.Builder viewOnceBuilder = SyncMessage.ViewOnceOpen.newBuilder().setTimestamp(readMessage.getTimestamp());

  if (readMessage.getSender().getUuid().isPresent()) {
    viewOnceBuilder.setSenderUuid(readMessage.getSender().getUuid().get().toString());
  }

  if (readMessage.getSender().getNumber().isPresent()) {
    viewOnceBuilder.setSenderE164(readMessage.getSender().getNumber().get());
  }

  builder.setViewOnceOpen(viewOnceBuilder.build());

  return container.setSyncMessage(builder).build().toByteArray();
}
 
Example 7
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private byte[] createMultiDeviceFetchTypeContent(SignalServiceSyncMessage.FetchType fetchType) {
  Content.Builder                 container    = Content.newBuilder();
  SyncMessage.Builder             syncMessage  = createSyncMessageBuilder();
  SyncMessage.FetchLatest.Builder fetchMessage = SyncMessage.FetchLatest.newBuilder();

  switch (fetchType) {
    case LOCAL_PROFILE:
      fetchMessage.setType(SyncMessage.FetchLatest.Type.LOCAL_PROFILE);
      break;
    case STORAGE_MANIFEST:
      fetchMessage.setType(SyncMessage.FetchLatest.Type.STORAGE_MANIFEST);
      break;
    default:
      Log.w(TAG, "Unknown fetch type!");
      break;
  }

  return container.setSyncMessage(syncMessage.setFetchLatest(fetchMessage)).build().toByteArray();
}
 
Example 8
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 6 votes vote down vote up
private byte[] createMultiDeviceReadContent(List<ReadMessage> readMessages) {
  Content.Builder     container = Content.newBuilder();
  SyncMessage.Builder builder   = createSyncMessageBuilder();

  for (ReadMessage readMessage : readMessages) {
    SyncMessage.Read.Builder readBuilder = SyncMessage.Read.newBuilder().setTimestamp(readMessage.getTimestamp());

    if (readMessage.getSender().getUuid().isPresent()) {
      readBuilder.setSenderUuid(readMessage.getSender().getUuid().get().toString());
    }

    if (readMessage.getSender().getNumber().isPresent()) {
      readBuilder.setSenderE164(readMessage.getSender().getNumber().get());
    }

    builder.addRead(readBuilder.build());
  }

  return container.setSyncMessage(builder).build().toByteArray();
}
 
Example 9
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 6 votes vote down vote up
private byte[] createMultiDeviceFetchTypeContent(SignalServiceSyncMessage.FetchType fetchType) {
  Content.Builder                 container    = Content.newBuilder();
  SyncMessage.Builder             syncMessage  = createSyncMessageBuilder();
  SyncMessage.FetchLatest.Builder fetchMessage = SyncMessage.FetchLatest.newBuilder();

  switch (fetchType) {
    case LOCAL_PROFILE:
      fetchMessage.setType(SyncMessage.FetchLatest.Type.LOCAL_PROFILE);
      break;
    case STORAGE_MANIFEST:
      fetchMessage.setType(SyncMessage.FetchLatest.Type.STORAGE_MANIFEST);
      break;
    default:
      Log.w(TAG, "Unknown fetch type!");
      break;
  }

  return container.setSyncMessage(syncMessage.setFetchLatest(fetchMessage)).build().toByteArray();
}
 
Example 10
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private byte[] createMultiDeviceVerifiedContent(VerifiedMessage verifiedMessage, byte[] nullMessage) {
  Content.Builder     container              = Content.newBuilder();
  SyncMessage.Builder syncMessage            = createSyncMessageBuilder();
  Verified.Builder    verifiedMessageBuilder = Verified.newBuilder();

  verifiedMessageBuilder.setNullMessage(ByteString.copyFrom(nullMessage));
  verifiedMessageBuilder.setIdentityKey(ByteString.copyFrom(verifiedMessage.getIdentityKey().serialize()));

  if (verifiedMessage.getDestination().getUuid().isPresent()) {
    verifiedMessageBuilder.setDestinationUuid(verifiedMessage.getDestination().getUuid().get().toString());
  }

  if (verifiedMessage.getDestination().getNumber().isPresent()) {
    verifiedMessageBuilder.setDestinationE164(verifiedMessage.getDestination().getNumber().get());
  }

  switch(verifiedMessage.getVerified()) {
    case DEFAULT:    verifiedMessageBuilder.setState(Verified.State.DEFAULT);    break;
    case VERIFIED:   verifiedMessageBuilder.setState(Verified.State.VERIFIED);   break;
    case UNVERIFIED: verifiedMessageBuilder.setState(Verified.State.UNVERIFIED); break;
    default:         throw new AssertionError("Unknown: " + verifiedMessage.getVerified());
  }

  syncMessage.setVerified(verifiedMessageBuilder);
  return container.setSyncMessage(syncMessage).build().toByteArray();
}
 
Example 11
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private byte[] createMultiDeviceSyncKeysContent(KeysMessage keysMessage) {
  Content.Builder          container   = Content.newBuilder();
  SyncMessage.Builder      syncMessage = createSyncMessageBuilder();
  SyncMessage.Keys.Builder builder     = SyncMessage.Keys.newBuilder();

  if (keysMessage.getStorageService().isPresent()) {
    builder.setStorageService(ByteString.copyFrom(keysMessage.getStorageService().get().serialize()));
  } else {
    Log.w(TAG, "Invalid keys message!");
  }

  return container.setSyncMessage(syncMessage.setKeys(builder)).build().toByteArray();
}
 
Example 12
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
private SyncMessage.Builder createSyncMessageBuilder() {
  SecureRandom random  = new SecureRandom();
  byte[]       padding = Util.getRandomLengthBytes(512);
  random.nextBytes(padding);

  SyncMessage.Builder builder = SyncMessage.newBuilder();
  builder.setPadding(ByteString.copyFrom(padding));

  return builder;
}
 
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: 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 15
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private SyncMessage.Builder createSyncMessageBuilder() {
  SecureRandom random  = new SecureRandom();
  byte[]       padding = Util.getRandomLengthBytes(512);
  random.nextBytes(padding);

  SyncMessage.Builder builder = SyncMessage.newBuilder();
  builder.setPadding(ByteString.copyFrom(padding));

  return builder;
}
 
Example 16
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 17
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private byte[] createMultiDeviceStickerPackOperationContent(List<StickerPackOperationMessage> stickerPackOperations) {
  Content.Builder     container   = Content.newBuilder();
  SyncMessage.Builder syncMessage = createSyncMessageBuilder();

  for (StickerPackOperationMessage stickerPackOperation : stickerPackOperations) {
    SyncMessage.StickerPackOperation.Builder builder = SyncMessage.StickerPackOperation.newBuilder();

    if (stickerPackOperation.getPackId().isPresent()) {
      builder.setPackId(ByteString.copyFrom(stickerPackOperation.getPackId().get()));
    }

    if (stickerPackOperation.getPackKey().isPresent()) {
      builder.setPackKey(ByteString.copyFrom(stickerPackOperation.getPackKey().get()));
    }

    if (stickerPackOperation.getType().isPresent()) {
      switch (stickerPackOperation.getType().get()) {
        case INSTALL: builder.setType(SyncMessage.StickerPackOperation.Type.INSTALL); break;
        case REMOVE:  builder.setType(SyncMessage.StickerPackOperation.Type.REMOVE); break;
      }
    }

    syncMessage.addStickerPackOperation(builder);
  }

  return container.setSyncMessage(syncMessage).build().toByteArray();
}
 
Example 18
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
private byte[] createMultiDeviceStickerPackOperationContent(List<StickerPackOperationMessage> stickerPackOperations) {
  Content.Builder     container   = Content.newBuilder();
  SyncMessage.Builder syncMessage = createSyncMessageBuilder();

  for (StickerPackOperationMessage stickerPackOperation : stickerPackOperations) {
    SyncMessage.StickerPackOperation.Builder builder = SyncMessage.StickerPackOperation.newBuilder();

    if (stickerPackOperation.getPackId().isPresent()) {
      builder.setPackId(ByteString.copyFrom(stickerPackOperation.getPackId().get()));
    }

    if (stickerPackOperation.getPackKey().isPresent()) {
      builder.setPackKey(ByteString.copyFrom(stickerPackOperation.getPackKey().get()));
    }

    if (stickerPackOperation.getType().isPresent()) {
      switch (stickerPackOperation.getType().get()) {
        case INSTALL: builder.setType(SyncMessage.StickerPackOperation.Type.INSTALL); break;
        case REMOVE:  builder.setType(SyncMessage.StickerPackOperation.Type.REMOVE); break;
      }
    }

    syncMessage.addStickerPackOperation(builder);
  }

  return container.setSyncMessage(syncMessage).build().toByteArray();
}
 
Example 19
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 20
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private byte[] createMultiDeviceMessageRequestResponseContent(MessageRequestResponseMessage message) {
  Content.Builder container = Content.newBuilder();
  SyncMessage.Builder syncMessage = createSyncMessageBuilder();
  SyncMessage.MessageRequestResponse.Builder responseMessage = SyncMessage.MessageRequestResponse.newBuilder();

  if (message.getGroupId().isPresent()) {
    responseMessage.setGroupId(ByteString.copyFrom(message.getGroupId().get()));
  }

  if (message.getPerson().isPresent()) {
    if (message.getPerson().get().getNumber().isPresent()) {
      responseMessage.setThreadE164(message.getPerson().get().getNumber().get());
    }
    if (message.getPerson().get().getUuid().isPresent()) {
      responseMessage.setThreadUuid(message.getPerson().get().getUuid().get().toString());
    }
  }

  switch (message.getType()) {
    case ACCEPT:
      responseMessage.setType(SyncMessage.MessageRequestResponse.Type.ACCEPT);
      break;
    case DELETE:
      responseMessage.setType(SyncMessage.MessageRequestResponse.Type.DELETE);
      break;
    case BLOCK:
      responseMessage.setType(SyncMessage.MessageRequestResponse.Type.BLOCK);
      break;
    case BLOCK_AND_DELETE:
      responseMessage.setType(SyncMessage.MessageRequestResponse.Type.BLOCK_AND_DELETE);
      break;
    default:
      Log.w(TAG, "Unknown type!");
      responseMessage.setType(SyncMessage.MessageRequestResponse.Type.UNKNOWN);
      break;
  }

  syncMessage.setMessageRequestResponse(responseMessage);

  return container.setSyncMessage(syncMessage).build().toByteArray();
}