org.whispersystems.signalservice.api.messages.multidevice.StickerPackOperationMessage Java Examples

The following examples show how to use org.whispersystems.signalservice.api.messages.multidevice.StickerPackOperationMessage. 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: MultiDeviceStickerPackSyncJob.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onRun() throws Exception {
  if (!TextSecurePreferences.isMultiDevice(context)) {
    Log.i(TAG, "Not multi device, aborting...");
    return;
  }

  List<StickerPackOperationMessage> operations = new LinkedList<>();

  try (StickerPackRecordReader reader = new StickerPackRecordReader(DatabaseFactory.getStickerDatabase(context).getInstalledStickerPacks())) {
    StickerPackRecord pack;
    while ((pack = reader.getNext()) != null) {
      byte[] packIdBytes  = Hex.fromStringCondensed(pack.getPackId());
      byte[] packKeyBytes = Hex.fromStringCondensed(pack.getPackKey());

      operations.add(new StickerPackOperationMessage(packIdBytes, packKeyBytes, StickerPackOperationMessage.Type.INSTALL));
    }
  }

  SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
  messageSender.sendMessage(SignalServiceSyncMessage.forStickerPackOperations(operations),
                            UnidentifiedAccessUtil.getAccessForSync(context));
}
 
Example #2
Source File: PushProcessMessageJob.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private void handleSynchronizeStickerPackOperation(@NonNull List<StickerPackOperationMessage> stickerPackOperations) {
  JobManager jobManager = ApplicationDependencies.getJobManager();

  for (StickerPackOperationMessage operation : stickerPackOperations) {
    if (operation.getPackId().isPresent() && operation.getPackKey().isPresent() && operation.getType().isPresent()) {
      String packId  = Hex.toStringCondensed(operation.getPackId().get());
      String packKey = Hex.toStringCondensed(operation.getPackKey().get());

      switch (operation.getType().get()) {
        case INSTALL:
          jobManager.add(StickerPackDownloadJob.forInstall(packId, packKey, false));
          break;
        case REMOVE:
          DatabaseFactory.getStickerDatabase(context).uninstallPack(packId);
          break;
      }
    } else {
      Log.w(TAG, "Received incomplete sticker pack operation sync.");
    }
  }
}
 
Example #3
Source File: MultiDeviceStickerPackOperationJob.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onRun() throws Exception {
  if (!TextSecurePreferences.isMultiDevice(context)) {
    Log.i(TAG, "Not multi device, aborting...");
    return;
  }

  byte[] packIdBytes  = Hex.fromStringCondensed(packId);
  byte[] packKeyBytes = Hex.fromStringCondensed(packKey);

  StickerPackOperationMessage.Type remoteType;

  switch (type) {
    case INSTALL: remoteType = StickerPackOperationMessage.Type.INSTALL; break;
    case REMOVE:  remoteType = StickerPackOperationMessage.Type.REMOVE; break;
    default:      throw new AssertionError("No matching type?");
  }

  SignalServiceMessageSender  messageSender        = ApplicationDependencies.getSignalServiceMessageSender();
  StickerPackOperationMessage stickerPackOperation = new StickerPackOperationMessage(packIdBytes, packKeyBytes, remoteType);

  messageSender.sendMessage(SignalServiceSyncMessage.forStickerPackOperations(Collections.singletonList(stickerPackOperation)),
                            UnidentifiedAccessUtil.getAccessForSync(context));
}
 
Example #4
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 #5
Source File: JsonStickerPackOperationMessage.java    From signald with GNU General Public License v3.0 5 votes vote down vote up
JsonStickerPackOperationMessage(StickerPackOperationMessage message) {
  if(message.getPackId().isPresent()) {
    packID = Hex.toStringCondensed(message.getPackId().get()); 
  }

  if(message.getPackKey().isPresent()) {
    packKey = Hex.toStringCondensed(message.getPackKey().get());
  }

  if(message.getType().isPresent()) {
    type = message.getType().get().toString();
  }
}
 
Example #6
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 #7
Source File: JsonSyncMessage.java    From signald with GNU General Public License v3.0 4 votes vote down vote up
JsonSyncMessage(SignalServiceSyncMessage syncMessage, String username) throws IOException, NoSuchAccountException {
    if(syncMessage.getSent().isPresent()) {
        this.sent = new JsonSentTranscriptMessage(syncMessage.getSent().get(), username);
    }

    if(syncMessage.getContacts().isPresent()) {
      ContactsMessage c = syncMessage.getContacts().get();
      contacts = new JsonAttachment(c.getContactsStream(), username);
      contactsComplete = c.isComplete();
    }

    if(syncMessage.getGroups().isPresent()) {
      groups = new JsonAttachment(syncMessage.getGroups().get(), username);
    }

    if(syncMessage.getBlockedList().isPresent()) {
        blockedNumbers = syncMessage.getBlockedList().get().getNumbers();
        for(byte[] groupId : syncMessage.getBlockedList().get().getGroupIds()) {
            blockedGroups.add(Base64.encodeBytes(groupId));
        }
    }

    if(syncMessage.getRequest().isPresent()) {
        requestType = syncMessage.getRequest().get().getRequest().toString();
    }

    if(syncMessage.getRead().isPresent()) {
        this.readMessages = syncMessage.getRead().get();
    }

    if(syncMessage.getViewOnceOpen().isPresent()) {
        this.viewOnceOpen = new JsonViewOnceOpenMessage(syncMessage.getViewOnceOpen().get());
    }

    if(syncMessage.getVerified().isPresent()) {
       this.verified = new JsonVerifiedMessage(syncMessage.getVerified().get());
    }

    if(syncMessage.getStickerPackOperations().isPresent()) {
      for(StickerPackOperationMessage message : syncMessage.getStickerPackOperations().get()) {
        stickerPackOperations.add(new JsonStickerPackOperationMessage(message));
      }
    }
}