Skip to content

Commit

Permalink
Add logOutAsync and loadChatListMainAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
cavallium committed Mar 20, 2024
1 parent c2ad58f commit 4d77c73
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<dependency>
<groupId>it.tdlight</groupId>
<artifactId>tdlight-java-bom</artifactId>
<version>3.3.2+td.1.8.26</version>
<version>3.4.0+td.1.8.26</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
7 changes: 6 additions & 1 deletion example/src/main/java/it/tdlight/example/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -504,6 +506,22 @@ public CompletableFuture<User> 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<Void> 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<Void> logOutAsync() {
return send(new LogOut()).thenAccept(ok -> {});
}

public boolean isMainChatsListLoaded() {
return mainChatsLoader.isLoaded();
}
Expand Down

0 comments on commit 4d77c73

Please sign in to comment.