Closed ShafiqSadat closed 7 months ago
Client not fully close when call client.sendClose()
package org.example; import it.tdlight.Init; import it.tdlight.Log; import it.tdlight.Slf4JLogMessageHandler; import it.tdlight.client.*; import it.tdlight.jni.TdApi; import it.tdlight.jni.TdApi.AuthorizationState; import java.nio.file.Path; import java.nio.file.Paths; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; public final class SessionChecker { public static void checkSession(int APP_ID, String APP_HASH, String sessionName) throws Exception { Init.init(); Log.setLogMessageHandler(1, new Slf4JLogMessageHandler()); try (SimpleTelegramClientFactory clientFactory = new SimpleTelegramClientFactory()) { APIToken apiToken = new APIToken(APP_ID, APP_HASH); TDLibSettings settings = TDLibSettings.create(apiToken); Path sessionPath = Paths.get(sessionName); settings.setDatabaseDirectoryPath(sessionPath.resolve("data")); settings.setDownloadedFilesDirectoryPath(sessionPath.resolve("downloads")); SimpleTelegramClientBuilder clientBuilder = clientFactory.builder(settings); ConsoleInteractiveAuthenticationData authenticationData = AuthenticationSupplier.consoleLogin(); try (SimpleTelegramClient client = clientBuilder.build(authenticationData)) { client.addUpdateHandler(TdApi.UpdateAuthorizationState.class, (update) -> { onUpdateAuthorizationState(update, client); }); try { TdApi.User me = client.getMeAsync().get(1, TimeUnit.MINUTES); System.out.println(me.toString()); } catch (Exception e) { throw new RuntimeException(e); } } } } private static void onUpdateAuthorizationState(TdApi.UpdateAuthorizationState update, SimpleTelegramClient client) { AuthorizationState authorizationState = update.authorizationState; if (authorizationState instanceof TdApi.AuthorizationStateReady) { System.out.println("Logged in"); client.sendClose(); } else if (authorizationState instanceof TdApi.AuthorizationStateClosing) { System.out.println("Closing..."); } else if (authorizationState instanceof TdApi.AuthorizationStateClosed) { System.out.println("Closed"); } else if (authorizationState instanceof TdApi.AuthorizationStateLoggingOut) { System.out.println("Logging out..."); } else if (authorizationState instanceof TdApi.AuthorizationStateWaitPhoneNumber) { System.out.println("WaitPhoneNumber"); client.sendClose(); } } }
Fixed in https://github.com/tdlight-team/tdlight-java/releases/tag/v3.4.0%2Btd.1.8.26
Client not fully close when call client.sendClose()