Beispiel #1
0
  @Export
  public JsFacade(String[] endpoints) {

    provider = (JsFileSystemProvider) Storage.getFileSystemRuntime();

    String clientName = IdentityUtils.getClientName();
    String uniqueId = IdentityUtils.getUniqueId();

    ConfigurationBuilder configuration = new ConfigurationBuilder();
    configuration.setApiConfiguration(
        new ApiConfiguration(APP_NAME, APP_ID, APP_KEY, clientName, uniqueId));
    configuration.setPhoneBookProvider(new JsPhoneBookProvider());
    configuration.setNotificationProvider(new JsNotificationsProvider());

    // Is Web application
    configuration.setPlatformType(PlatformType.WEB);

    // Device Category
    // Only Desktop is supported for JS library
    configuration.setDeviceCategory(DeviceCategory.DESKTOP);

    // Adding endpoints
    for (String endpoint : endpoints) {
      configuration.addEndpoint(endpoint);
    }

    messenger = new JsMessenger(configuration.build());

    Log.d(TAG, "JsMessenger created");
  }
  @Override
  public void preStart() {
    pendingMessages = new PendingMessagesStorage();
    byte[] p = preferences().getBytes(PREFERENCES);
    if (p != null) {
      try {
        pendingMessages = PendingMessagesStorage.fromBytes(p);
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

    boolean isChanged = false;
    ArrayList<PendingMessage> messages = pendingMessages.getPendingMessages();
    for (PendingMessage pending : messages.toArray(new PendingMessage[messages.size()])) {
      if (pending.getContent() instanceof TextContent) {
        performSendContent(pending.getPeer(), pending.getRid(), pending.getContent());
      } else if (pending.getContent() instanceof DocumentContent) {
        DocumentContent documentContent = (DocumentContent) pending.getContent();
        if (documentContent.getSource() instanceof FileLocalSource) {
          if (Storage.isFsPersistent()) {
            performUploadFile(
                pending.getRid(),
                ((FileLocalSource) documentContent.getSource()).getFileDescriptor(),
                ((FileLocalSource) documentContent.getSource()).getFileName());
          } else {
            List<Long> rids = new ArrayList<>();
            rids.add(pending.getRid());
            context().getMessagesModule().getRouter().onMessagesDeleted(pending.getPeer(), rids);
            pendingMessages.getPendingMessages().remove(pending);
            isChanged = true;
          }
        } else {
          performSendContent(pending.getPeer(), pending.getRid(), pending.getContent());
        }
      }
    }

    if (isChanged) {
      savePending();
    }
  }
Beispiel #3
0
  @Override
  public void preStart() {
    alreadyInTemp = false; // Storage.isAlreadyInTemp(descriptor);
    isWriteToDestProvider = Storage.isFsPersistent() && !alreadyInTemp;

    srcReference = Storage.fileFromDescriptor(descriptor);
    if (srcReference == null) {
      if (LOG) {
        Log.d(TAG, "Error during file reference creating");
      }
      reportError();
      return;
    }

    if (isWriteToDestProvider) {
      destReference = Storage.createTempFile();
      if (destReference == null) {
        if (LOG) {
          Log.w(TAG, "Error during file dest reference creating");
        }
        reportError();
        return;
      }
    }

    srcReference
        .openRead()
        .flatMap(
            f -> {
              inputFile = f;
              if (isWriteToDestProvider) {
                return destReference.openWrite(srcReference.getSize());
              } else {
                return Promise.success(null);
              }
            })
        .flatMap(
            f -> {
              outputFile = f;

              crc32 = new CRC32();

              blocksCount = srcReference.getSize() / blockSize;
              if (srcReference.getSize() % blockSize != 0) {
                blocksCount++;
              }

              if (LOG) {
                Log.d(TAG, "Starting uploading " + blocksCount + " blocks");
                Log.d(TAG, "Requesting upload config...");
              }

              return api(new RequestGetFileUploadUrl(srcReference.getSize()));
            })
        .then(
            r -> {
              if (LOG) {
                Log.d(TAG, "Upload config loaded");
              }
              uploadConfig = r.getUploadKey();
              checkQueue();
            })
        .failure(
            e -> {
              if (LOG) {
                Log.w(TAG, "Error during initialization of upload");
              }
              reportError();
            });
  }
  public SearchModule(Modules modules) {
    super(modules);

    searchList = Storage.createList(STORAGE_SEARCH, SearchEntity.CREATOR);
  }