Improve example result handler

This commit is contained in:
Andrea Cavalli 2023-09-11 01:41:04 +02:00
parent 250dfa3a89
commit 4999183324
1 changed files with 12 additions and 15 deletions

View File

@ -152,21 +152,18 @@ public final class Example {
long chatId = update.message.chatId;
// Get the chat title
client.send(new TdApi.GetChat(chatId))
.thenApply(chatIdResult -> {
// Get the chat name
return chatIdResult.title;
})
.whenComplete((chatTitle, error) -> {
if (error != null) {
// Print error
System.err.printf("Can't get chat title of chat %s%n", chatId);
error.printStackTrace(System.err);
} else {
// Print the message
System.out.printf("Received new message from chat %s (%s): %s%n", chatTitle, chatId, text);
}
});
client.send(new TdApi.GetChat(chatId)).whenCompleteAsync((chatIdResult, error) -> {
if (error != null) {
// Print error
System.err.printf("Can't get chat title of chat %s%n", chatId);
error.printStackTrace(System.err);
} else {
// Get the chat name
String title = chatIdResult.title;
// Print the message
System.out.printf("Received new message from chat %s (%s): %s%n", title, chatId, text);
}
});
}
/**