Пример #1
0
  public JsPromise findUsers(final String query) {
    return JsPromise.create(
        new JsPromiseExecutor() {
          @Override
          public void execute() {
            messenger
                .findUsers(query)
                .start(
                    new CommandCallback<UserVM[]>() {
                      @Override
                      public void onResult(UserVM[] users) {
                        JsArray<JsUser> jsUsers = JsArray.createArray().cast();

                        for (UserVM user : users) {
                          jsUsers.push(messenger.getJsUser(user.getId()).get());
                        }

                        resolve(jsUsers);
                      }

                      @Override
                      public void onError(Exception e) {
                        reject(e.getMessage());
                      }
                    });
          }
        });
  }
Пример #2
0
  public JsPromise editMyAbout(final String newAbout) {
    return JsPromise.create(
        new JsPromiseExecutor() {
          @Override
          public void execute() {
            //noinspection ConstantConditions
            messenger
                .editMyAbout(newAbout)
                .start(
                    new CommandCallback<Boolean>() {
                      @Override
                      public void onResult(Boolean res) {
                        Log.d(TAG, "editMyAbout:result");
                        resolve();
                      }

                      @Override
                      public void onError(Exception e) {
                        Log.d(TAG, "editMyAbout:error");
                        reject();
                      }
                    });
          }
        });
  }
Пример #3
0
  public JsPromise removeContact(final int uid) {
    return JsPromise.create(
        new JsPromiseExecutor() {
          @Override
          public void execute() {
            //noinspection ConstantConditions
            messenger
                .removeContact(uid)
                .start(
                    new CommandCallback<Boolean>() {
                      @Override
                      public void onResult(Boolean res) {
                        resolve();
                      }

                      @Override
                      public void onError(Exception e) {
                        reject();
                      }
                    });
          }
        });
  }
Пример #4
0
  public JsPromise revokeInviteLink(final int gid) {
    return JsPromise.create(
        new JsPromiseExecutor() {
          @Override
          public void execute() {
            //noinspection ConstantConditions
            messenger
                .revokeInviteLink(gid)
                .start(
                    new CommandCallback<String>() {
                      @Override
                      public void onResult(String res) {
                        resolve(res);
                      }

                      @Override
                      public void onError(Exception e) {
                        reject();
                      }
                    });
          }
        });
  }
Пример #5
0
  public JsPromise editGroupTitle(final int gid, final String newTitle) {
    return JsPromise.create(
        new JsPromiseExecutor() {
          @Override
          public void execute() {
            //noinspection ConstantConditions
            messenger
                .editGroupTitle(gid, newTitle)
                .start(
                    new CommandCallback<Boolean>() {
                      @Override
                      public void onResult(Boolean res) {
                        resolve();
                      }

                      @Override
                      public void onError(Exception e) {
                        reject();
                      }
                    });
          }
        });
  }
Пример #6
0
  public JsPromise joinGroupViaLink(final String url) {
    return JsPromise.create(
        new JsPromiseExecutor() {
          @Override
          public void execute() {
            //noinspection ConstantConditions
            messenger
                .joinGroupViaLink(url)
                .start(
                    new CommandCallback<Integer>() {
                      @Override
                      public void onResult(Integer res) {
                        resolve(JsPeer.create(Peer.group(res)));
                      }

                      @Override
                      public void onError(Exception e) {
                        reject();
                      }
                    });
          }
        });
  }
Пример #7
0
  public JsPromise createGroup(final String title, final JsFile file, final int[] uids) {
    return JsPromise.create(
        new JsPromiseExecutor() {
          @Override
          public void execute() {
            String avatarDescriptor = provider.registerUploadFile(file);
            //noinspection ConstantConditions
            messenger
                .createGroup(title, avatarDescriptor, uids)
                .start(
                    new CommandCallback<Integer>() {
                      @Override
                      public void onResult(Integer res) {
                        resolve(JsPeer.create(Peer.group(res)));
                      }

                      @Override
                      public void onError(Exception e) {
                        reject();
                      }
                    });
          }
        });
  }