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