Work with Telegram JNI Lib. Want to call getChatList() method and wait while TdApi.GetChats() returns result.

The current implementation of the method is as follows:

  1. Send a request to get chats in Telegram JNI Lib:

    client.send(new TdApi.GetChats (offsetOrder, offsetChatId, limit - chatList.size ()), new Client.ResultHandler()
  2. When it complete, recursively call getChatList() method and print the result.

How i can call getChatList() method and wait until it executes?

private static void getChatList(final int limit) {synchronized (chatList) {if (!haveFullChatList && limit > chatList.size()) {// have enough chats in the chat list or chat list is too smalllong offsetOrder=Long.MAX_VALUE;long offsetChatId=0;if (!chatList.isEmpty()) {OrderedChat last=chatList.last();offsetOrder=last.order;offsetChatId=last.chatId;}client.send(new TdApi.GetChats(offsetOrder, offsetChatId, limit - chatList.size()), new Client.ResultHandler() {@Overridepublic void onResult(TdApi.Object object) {switch (object.getConstructor()) {case TdApi.Error.CONSTRUCTOR:System.err.println("Receive an error for GetChats:" + newLine + object);break;case TdApi.Chats.CONSTRUCTOR:long[] chatIds=((TdApi.Chats) object).chatIds;if (chatIds.length==0) {synchronized (chatList) {haveFullChatList=true;}}// chats had already been received through updates, let's retry requestgetChatList(limit);break;default:System.err.println("Receive wrong response from TDLib:" + newLine + object);}}});return;}// have enough chats in the chat list to answer requestjava.util.Iterator<OrderedChat> iter=chatList.iterator();System.out.println();System.out.println("First " + limit + " chat(s) out of " + chatList.size() + " known chat(s):");for (int i=0; i < limit; i++) {long chatId=iter.next().chatId;TdApi.Chat chat=chats.get(chatId);synchronized (chat) {System.out.println(chatId + ": " + chat.title);}}}}
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.