Example #1
0
  private void TL_Updates(TL.Object obj) {
    if (obj.name.equals("updatesTooLong")) api_updates_getDifference();

    boolean chat = obj.name.equals("updateShortChatMessage");
    if (obj.name.equals("updateShortMessage") || chat) {
      cb.onMessage(
          Dialog.Message.newObject(
              obj.getInt("id"),
              obj.getInt("from_id"),
              chat ? obj.getInt("chat_id") : -1,
              obj.getInt("from_id"),
              obj.getInt("date"),
              obj.getString("message"),
              null),
          Dialog.MSG_INCOMING | Dialog.MSG_HISTORY);
      setUpdate(obj.getInt("date"), obj.getInt("pts"), obj.getInt("seq"));
    }

    if (obj.name.equals("updateShort")) {
      onUpdate(obj.getObject("update"), null, null);
      setUpdate(obj.getInt("date"), -1, -1);
    }

    if (obj.name.equals("updatesCombined") || obj.name.equals("updates")) {
      TL.Vector updates = obj.getVector("updates");
      for (int i = 0; i < updates.count; i++)
        onUpdate(updates.getObject(i), obj.getVector("users"), obj.getVector("chats"));
      setUpdate(obj.getInt("date"), -1, obj.getInt("seq"));
    }
  }
Example #2
0
  private void TL_RpcError(TL.Object obj) {
    int code = obj.getInt("error_code");
    String msg = obj.getString("error_message");

    Common.logError(String.format("rpc_error: %s (%d)\n", msg, code));

    Message req_msg = TLMessage.get(req_msg_id);
    if (req_msg == null) return;
    Common.logError("message object: " + req_msg.obj.name + ":" + req_msg.obj.type);

    int idx = msg.indexOf("_MIGRATE_");
    if (idx > 0) {
      String type = msg.substring(0, idx);

      String num = msg.substring(idx + 9);
      if ((idx = num.indexOf(":")) > 0) num = num.substring(0, idx);
      int dc_id = Integer.parseInt(num);
      Common.logError("redirect to dc: " + dc_id);

      MTProto m = MTProto.getConnection(dc_id, cb, reuseFlag);
      cb.onRedirect(m);
      if (type.equals("PHONE") || type.equals("NETWORK") || type.equals("USER")) dc_this = dc_id;

      m.sendMessage(req_msg);
    }
  }
Example #3
0
  private void TL_Config(TL.Object obj) {
    dc_date = obj.getInt("date");
    MTProto.dc_this = obj.getInt("this_dc");
    dcState.set("id", dc_this);
    updateDcStates();

    TL.Vector dc_options = obj.getVector("dc_options");

    ArrayList<TL.Object> new_dcStates = new ArrayList<TL.Object>();

    for (int i = 0; i < dc_options.count; i++) {
      TL.Object dcObj = dc_options.getObject(i);
      int id = dcObj.getInt("id");

      TL.Object state =
          TL.newObject(
              "joim.dcState",
              id,
              dcObj.getString("ip_address"),
              dcObj.getInt("port"),
              new byte[0],
              false,
              GEN_session_id(),
              0L,
              0);

      for (int j = 0; j < MTProto.dcStates.size(); j++) {
        TL.Object item = MTProto.dcStates.get(j);
        if (id == item.getInt("id") && state.getString("ip").equals(item.getString("ip"))) {
          state.set("auth_key", item.getBytes("auth_key"));
          state.set("bind", item.getBool("bind"));
          state.set("session", item.getLong("session"));
          state.set("server_salt", item.getLong("server_salt"));
          state.set("seqno", item.getInt("seqno"));
          if (state.getInt("port") == item.getInt("port")) dcState = state;
          break;
        }
      }

      new_dcStates.add(state);
    }

    dcStates = new_dcStates;
    send_queue();
    cb.onReady();
  }
Example #4
0
 public void onConnect() {
   connected = true;
   Common.logInfo(
       "connected to dc["
           + dcState.getInt("id")
           + "] "
           + dcState.getString("ip")
           + ":"
           + dcState.getInt("port"));
   if (auth_key == null || auth_key.length == 0) {
     auth();
   } else onAuthorized();
 }
Example #5
0
 private void TL_updateUserName(TL.Object update) {
   cb.onUserName(
       update.getInt("user_id"), update.getString("first_name"), update.getString("last_name"));
 }