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")); } }
private void TL_contacts_ImportedContacts(TL.Object obj) { User.addUsers(obj.getVector("users")); TL.Vector imported = obj.getVector("imported"); for (int i = 0; i < imported.count; i++) { TL.Object c = imported.getObject(i); User.getUser(c.getInt("user_id")).client_id = c.getLong("client_id"); } SyncUtils.updateContacts(Main.main); }
private void TL_messages_StatedMessages(TL.Object obj) { setUpdate(-1, obj.getInt("pts"), obj.getInt("seq")); User.addUsers(obj.getVector("users")); TL.Vector messages = obj.getVector("messages"); for (int i = 0; i < messages.count; i++) { TL.Object message = messages.getObject(i); Dialog d = Dialog.getDialog(message.getInt("from_id"), message.getObject("to_id"), true); Dialog.newMessage(message, Dialog.MSG_INCOMING); } }
private void TL_messages_StatedMessage(TL.Object obj) { setUpdate(-1, obj.getInt("pts"), obj.getInt("seq")); User.addUsers(obj.getVector("users")); TL.Object message = obj.getObject("message"); Dialog d = Dialog.getDialog(message.getInt("from_id"), message.getObject("to_id"), true); Dialog.newMessage(message, Dialog.MSG_INCOMING); }
private void TL_MsgsAck(TL.Object obj) { TL.Vector msg_ids = obj.getVector("msg_ids"); for (int i = 0; i < msg_ids.count; i++) { Message msg = TLMessage.get(msg_ids.getLong(i)); if (msg != null) msg.accepted = true; // TLMessage.delete(msg_ids.getLong(i)); } }
private void TL_updates_Difference(TL.Object obj) { if (obj.name.equals("updates.differenceEmpty")) setUpdate(obj.getInt("date"), -1, obj.getInt("seq")); if (obj.name.equals("updates.difference") || obj.name.equals("updates.differenceSlice")) { TL.Vector other_updates = obj.getVector("other_updates"); for (int i = 0; i < other_updates.count; i++) onUpdate(other_updates.getObject(i), obj.getVector("users"), obj.getVector("chats")); TL.Vector new_messages = obj.getVector("new_messages"); for (int i = 0; i < new_messages.count; i++) Dialog.newMessage(new_messages.getObject(i), Dialog.MSG_HISTORY); // if (new_messages.count > 0) // Dialog.vibrate(); if (obj.name.equals("updates.differenceSlice")) { TL_updates_State(obj.getObject("intermediate_state")); this.api_updates_getDifference(); } else TL_updates_State(obj.getObject("state")); } }
public void TL_messages_Dialogs(TL.Object obj) { User.addUsers(obj.getVector("users")); Chat.addChats(obj.getVector("chats")); // dialogs TL.Vector dialogs = obj.getVector("dialogs"); for (int i = 0; i < dialogs.count; i++) { TL.Object dobj = dialogs.getObject(i); Dialog d = Dialog.getDialog(-1, dobj.getObject("peer"), true); d.updating = true; } // messages TL.Vector messages = obj.getVector("messages"); for (int i = 0; i < messages.count; i++) cb.onMessage(messages.getObject(i), Dialog.MSG_HISTORY); for (int i = 0; i < dialogs.count; i++) { TL.Object dobj = dialogs.getObject(i); Dialog d = Dialog.getDialog(-1, dobj.getObject("peer"), true); if (dobj.getInt("top_message") == -7) // config_dialogs magic d.noHistory = true; d.unread_count = dobj.getInt("unread_count"); d.updating = false; Main.main.updateDialog(d); } Common.logError("dialogs: " + Dialog.dialogs.size()); // slice if (obj.name.equals("messages.dialogsSlice") && dialogs.count > 0) { int limit = obj.getInt("count") - Dialog.dialogs.size(); if (limit > 0) api_messages_getDialogs(Dialog.dialogs.size(), 0, limit); } if (Main.main != null) Main.main.resetDialogs(); }
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(); }
private void TL_ResPQ(TL.Object obj) { sv_nonce = obj.getBytes("server_nonce"); BigInteger pq = new BigInteger(1, obj.getBytes("pq")); TL.Vector v_fp = obj.getVector("server_public_key_fingerprints"); fp = v_fp.getLong(0); Common.logError("pq: " + pq.toString()); // prime factorization for pq BigInteger q = Common.rho(pq); BigInteger p = pq.divide(q); if (p.compareTo(q) > 0) { BigInteger t = p; p = q; q = t; } SecureRandom rnd = new SecureRandom(); new_nonce = new byte[32]; rnd.nextBytes(new_nonce); // generate encrypted_data TL.Object data_obj = TL.newObject("p_q_inner_data", pq, p, q, cl_nonce, sv_nonce, new_nonce); byte[] data = data_obj.serialize(); byte[] hash = Common.getSHA1(data); byte[] data_with_hash = new byte[255]; System.arraycopy(hash, 0, data_with_hash, 0, hash.length); System.arraycopy(data, 0, data_with_hash, hash.length, data.length); GEN_random_bytes(data_with_hash, data.length + hash.length, 255); byte[] encrypted_data = Common.RSA(RSA_MODULUS, RSA_EXPONENT, data_with_hash); // req_DH_params TL.Object req_obj = TL.newObject("req_DH_params", cl_nonce, sv_nonce, p, q, fp, encrypted_data); send(req_obj, false, false); }
private void TL_updateRestoreMessages(TL.Object update) { setUpdate(-1, update.getInt("pts"), -1); TL.Vector messages = update.getVector("messages"); for (int i = 0; i < messages.count; i++) Dialog.messageRestore(messages.getInt(i)); }
private void TL_contacts_Contacts(TL.Object obj) { if (obj.name.equals("contacts.contacts")) User.addUsers(obj.getVector("users")); }
private void TL_messages_ChatFull(TL.Object obj) { User.addUsers(obj.getVector("users")); TL.Object full_chat = obj.getObject("full_chat"); Chat chat = Chat.getChat(full_chat.getInt("id")); if (chat != null) chat.update(full_chat); }
private void TL_photos_Photo(TL.Object obj) { User.addUsers(obj.getVector("users")); }