Skip to content

Commit 4d77c73

Browse files
committed
Add logOutAsync and loadChatListMainAsync
1 parent c2ad58f commit 4d77c73

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

example/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<dependency>
2727
<groupId>it.tdlight</groupId>
2828
<artifactId>tdlight-java-bom</artifactId>
29-
<version>3.3.2+td.1.8.26</version>
29+
<version>3.4.0+td.1.8.26</version>
3030
<type>pom</type>
3131
<scope>import</scope>
3232
</dependency>

example/src/main/java/it/tdlight/example/Example.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
import it.tdlight.client.TDLibSettings;
1313
import it.tdlight.jni.TdApi;
1414
import it.tdlight.jni.TdApi.AuthorizationState;
15+
import it.tdlight.jni.TdApi.CreatePrivateChat;
1516
import it.tdlight.jni.TdApi.FormattedText;
17+
import it.tdlight.jni.TdApi.GetChat;
1618
import it.tdlight.jni.TdApi.InputMessageText;
1719
import it.tdlight.jni.TdApi.Message;
1820
import it.tdlight.jni.TdApi.MessageContent;
@@ -75,9 +77,12 @@ public static void main(String[] args) throws Exception {
7577
// Get me
7678
TdApi.User me = app.getClient().getMeAsync().get(1, TimeUnit.MINUTES);
7779

80+
// Create the "saved messages" chat
81+
var savedMessagesChat = app.getClient().send(new CreatePrivateChat(me.id, true)).get(1, TimeUnit.MINUTES);
82+
7883
// Send a test message
7984
var req = new SendMessage();
80-
req.chatId = me.id;
85+
req.chatId = savedMessagesChat.id;
8186
var txt = new InputMessageText();
8287
txt.text = new FormattedText("TDLight test", new TextEntity[0]);
8388
req.inputMessageContent = txt;

tdlight-java/src/main/java/it/tdlight/client/SimpleTelegramClient.java

+18
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import it.tdlight.jni.TdApi.ChatListArchive;
1313
import it.tdlight.jni.TdApi.ChatListMain;
1414
import it.tdlight.jni.TdApi.Function;
15+
import it.tdlight.jni.TdApi.LoadChats;
16+
import it.tdlight.jni.TdApi.LogOut;
1517
import it.tdlight.jni.TdApi.Message;
1618
import it.tdlight.jni.TdApi.Update;
1719
import it.tdlight.jni.TdApi.User;
@@ -504,6 +506,22 @@ public CompletableFuture<User> getMeAsync() {
504506
return meGetter.getMeAsync();
505507
}
506508

509+
/**
510+
* 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.
511+
*
512+
**/
513+
public CompletableFuture<Void> loadChatListMainAsync() {
514+
return send(new LoadChats(new ChatListMain(), 2000)).thenAccept(ok -> {});
515+
}
516+
517+
/**
518+
* 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.
519+
*
520+
**/
521+
public CompletableFuture<Void> logOutAsync() {
522+
return send(new LogOut()).thenAccept(ok -> {});
523+
}
524+
507525
public boolean isMainChatsListLoaded() {
508526
return mainChatsLoader.isLoaded();
509527
}

0 commit comments

Comments
 (0)