From 214a9afdb87700c80af08790b7cb967153cb932d Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 24 Mar 2023 17:05:50 +0300 Subject: Telegram: more correct connection state detection --- protocols/Telegram/src/auth.cpp | 4 ---- protocols/Telegram/src/proto.h | 1 + protocols/Telegram/src/server.cpp | 30 ++++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) (limited to 'protocols/Telegram/src') diff --git a/protocols/Telegram/src/auth.cpp b/protocols/Telegram/src/auth.cpp index 92962f5d79..8a64b2a015 100644 --- a/protocols/Telegram/src/auth.cpp +++ b/protocols/Telegram/src/auth.cpp @@ -137,10 +137,6 @@ void CTelegramProto::ProcessAuth(TD::updateAuthorizationState *pObj) CallFunctionSync(EnterEmailCode, this); break; - case TD::authorizationStateReady::ID: - OnLoggedIn(); - break; - case TD::authorizationStateClosed::ID: debugLogA("Connection terminated, exiting"); LogOut(); diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index 1234bb3ed3..42bf428802 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -208,6 +208,7 @@ class CTelegramProto : public PROTO void ProcessChatLastMessage(TD::updateChatLastMessage *pObj); void ProcessChatNotification(TD::updateChatNotificationSettings *pObj); void ProcessChatPosition(TD::updateChatPosition *pObj); + void ProcessConnectionState(TD::updateConnectionState *pObj); void ProcessDeleteMessage(TD::updateDeleteMessages *pObj); void ProcessFile(TD::updateFile *pObj); void ProcessGroups(TD::updateChatFilters *pObj); diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index a42736c049..85afbae93d 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -168,6 +168,10 @@ void CTelegramProto::ProcessResponse(td::ClientManager::Response response) ProcessDeleteMessage((TD::updateDeleteMessages*)response.object.get()); break; + case TD::updateConnectionState::ID: + ProcessConnectionState((TD::updateConnectionState *)response.object.get()); + break; + case TD::updateFile::ID: ProcessFile((TD::updateFile *)response.object.get()); break; @@ -418,6 +422,32 @@ void CTelegramProto::ProcessChatPosition(TD::updateChatPosition *pObj) } } +void CTelegramProto::ProcessConnectionState(TD::updateConnectionState *pObj) +{ + switch (pObj->state_->get_id()) { + case TD::connectionStateConnecting::ID: + debugLogA("Connection state: connecting"); + break; + + case TD::connectionStateConnectingToProxy::ID: + debugLogA("Connection state: connecting to proxy"); + break; + + case TD::connectionStateWaitingForNetwork::ID: + debugLogA("Connection state: waiting for network"); + break; + + case TD::connectionStateUpdating::ID: + debugLogA("Connection state: updating"); + break; + + case TD::connectionStateReady::ID: + debugLogA("Connection state: connected"); + OnLoggedIn(); + break; + } +} + void CTelegramProto::ProcessDeleteMessage(TD::updateDeleteMessages *pObj) { if (!pObj->is_permanent_) -- cgit v1.2.3