From 4d77c73e95109e718a7deaa1975dce42ab3e9d58 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Thu, 21 Mar 2024 00:56:40 +0100 Subject: [PATCH] Add logOutAsync and loadChatListMainAsync --- example/pom.xml | 2 +- .../main/java/it/tdlight/example/Example.java | 7 ++++++- .../tdlight/client/SimpleTelegramClient.java | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/example/pom.xml b/example/pom.xml index d8f58276c..eacff6685 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -26,7 +26,7 @@ it.tdlight tdlight-java-bom - 3.3.2+td.1.8.26 + 3.4.0+td.1.8.26 pom import diff --git a/example/src/main/java/it/tdlight/example/Example.java b/example/src/main/java/it/tdlight/example/Example.java index dd0d0c18c..72a3d8b47 100644 --- a/example/src/main/java/it/tdlight/example/Example.java +++ b/example/src/main/java/it/tdlight/example/Example.java @@ -12,7 +12,9 @@ import it.tdlight.client.TDLibSettings; import it.tdlight.jni.TdApi; import it.tdlight.jni.TdApi.AuthorizationState; +import it.tdlight.jni.TdApi.CreatePrivateChat; import it.tdlight.jni.TdApi.FormattedText; +import it.tdlight.jni.TdApi.GetChat; import it.tdlight.jni.TdApi.InputMessageText; import it.tdlight.jni.TdApi.Message; import it.tdlight.jni.TdApi.MessageContent; @@ -75,9 +77,12 @@ public static void main(String[] args) throws Exception { // Get me TdApi.User me = app.getClient().getMeAsync().get(1, TimeUnit.MINUTES); + // Create the "saved messages" chat + var savedMessagesChat = app.getClient().send(new CreatePrivateChat(me.id, true)).get(1, TimeUnit.MINUTES); + // Send a test message var req = new SendMessage(); - req.chatId = me.id; + req.chatId = savedMessagesChat.id; var txt = new InputMessageText(); txt.text = new FormattedText("TDLight test", new TextEntity[0]); req.inputMessageContent = txt; diff --git a/tdlight-java/src/main/java/it/tdlight/client/SimpleTelegramClient.java b/tdlight-java/src/main/java/it/tdlight/client/SimpleTelegramClient.java index 8239e786e..402897757 100644 --- a/tdlight-java/src/main/java/it/tdlight/client/SimpleTelegramClient.java +++ b/tdlight-java/src/main/java/it/tdlight/client/SimpleTelegramClient.java @@ -12,6 +12,8 @@ import it.tdlight.jni.TdApi.ChatListArchive; import it.tdlight.jni.TdApi.ChatListMain; import it.tdlight.jni.TdApi.Function; +import it.tdlight.jni.TdApi.LoadChats; +import it.tdlight.jni.TdApi.LogOut; import it.tdlight.jni.TdApi.Message; import it.tdlight.jni.TdApi.Update; import it.tdlight.jni.TdApi.User; @@ -504,6 +506,22 @@ public CompletableFuture getMeAsync() { return meGetter.getMeAsync(); } + /** + * Loads more chats from the main chat list. The loaded chats and their positions in the chat list will be sent through updates. Chats are sorted by the pair (chat.position.order, chat.id) in descending order. Returns a 404 error if all chats have been loaded. + * + **/ + public CompletableFuture loadChatListMainAsync() { + return send(new LoadChats(new ChatListMain(), 2000)).thenAccept(ok -> {}); + } + + /** + * Closes the TDLib instance after a proper logout. Requires an available network connection. All local data will be destroyed. After the logout completes, updateAuthorizationState with authorizationStateClosed will be sent. + * + **/ + public CompletableFuture logOutAsync() { + return send(new LogOut()).thenAccept(ok -> {}); + } + public boolean isMainChatsListLoaded() { return mainChatsLoader.isLoaded(); }