summaryrefslogtreecommitdiff
path: root/protocols/Telegram
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2023-01-02 15:41:19 +0300
committerGeorge Hazan <ghazan@miranda.im>2023-01-02 15:41:19 +0300
commit16c56fd6e23135895b73082c11a5ae6a321cc9f9 (patch)
treef775069b7e43406300a069ec3ffc0c5753071b42 /protocols/Telegram
parentda270c8f594c9846aa4e5d2f4b20c061e12426ff (diff)
fixes #3288 (Telegram: автозавершение сессии при удалении учётки)
Diffstat (limited to 'protocols/Telegram')
-rw-r--r--protocols/Telegram/src/auth.cpp7
-rw-r--r--protocols/Telegram/src/mt_proto.cpp11
-rw-r--r--protocols/Telegram/src/mt_proto.h7
-rw-r--r--protocols/Telegram/src/server.cpp18
4 files changed, 27 insertions, 16 deletions
diff --git a/protocols/Telegram/src/auth.cpp b/protocols/Telegram/src/auth.cpp
index 9591f5fc98..22254ea460 100644
--- a/protocols/Telegram/src/auth.cpp
+++ b/protocols/Telegram/src/auth.cpp
@@ -100,12 +100,7 @@ void CMTProto::ProcessAuth(TD::updateAuthorizationState *pObj)
OnLoggedIn();
break;
- case TD::authorizationStateLoggingOut::ID:
- debugLogA("Server required us to log out, exiting");
- LogOut();
- break;
-
- case TD::authorizationStateClosing::ID:
+ case TD::authorizationStateClosed::ID:
debugLogA("Connection terminated, exiting");
LogOut();
break;
diff --git a/protocols/Telegram/src/mt_proto.cpp b/protocols/Telegram/src/mt_proto.cpp
index a0e90d8573..a99c91eb31 100644
--- a/protocols/Telegram/src/mt_proto.cpp
+++ b/protocols/Telegram/src/mt_proto.cpp
@@ -19,7 +19,6 @@ static int CompareUsers(const TG_USER *p1, const TG_USER *p2)
CMTProto::CMTProto(const char* protoName, const wchar_t* userName) :
PROTO<CMTProto>(protoName, userName),
m_impl(*this),
- m_pClientMmanager(std::make_unique<td::ClientManager>()),
m_arUsers(10, CompareUsers),
m_arRequests(10, CompareRequests),
m_szOwnPhone(this, "Phone"),
@@ -28,7 +27,6 @@ CMTProto::CMTProto(const char* protoName, const wchar_t* userName) :
m_bUsePopups(this, "UsePopups", true),
m_bHideGroupchats(this, "HideChats", true)
{
- m_iClientId = m_pClientMmanager->create_client_id();
m_iOwnId = _atoi64(getMStringA(DBKEY_ID));
CreateProtoService(PS_CREATEACCMGRUI, &CMTProto::SvcCreateAccMgrUI);
@@ -83,6 +81,9 @@ void CMTProto::OnShutdown()
void CMTProto::OnErase()
{
+ m_bUnregister = true;
+ ServerThread(0);
+
DeleteDirectoryTreeW(GetProtoFolder(), false);
}
@@ -135,19 +136,19 @@ int CMTProto::SetStatus(int iNewStatus)
}
if (m_iDesiredStatus == ID_STATUS_OFFLINE) {
- if (m_bRunning)
+ if (isRunning())
SendQuery(new TD::close());
m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
}
- else if (!m_bRunning && !IsStatusConnecting(m_iStatus)) {
+ else if (!isRunning() && !IsStatusConnecting(m_iStatus)) {
m_iStatus = ID_STATUS_CONNECTING;
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
ForkThread(&CMTProto::ServerThread);
}
- else if (m_bRunning) {
+ else if (isRunning()) {
m_iStatus = m_iDesiredStatus;
ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
}
diff --git a/protocols/Telegram/src/mt_proto.h b/protocols/Telegram/src/mt_proto.h
index 7f1011e996..5426ffaf6f 100644
--- a/protocols/Telegram/src/mt_proto.h
+++ b/protocols/Telegram/src/mt_proto.h
@@ -89,10 +89,14 @@ class CMTProto : public PROTO<CMTProto>
}
} m_impl;
+ bool __forceinline isRunning() const
+ { return m_pClientMmanager != nullptr;
+ }
+
std::unique_ptr<td::ClientManager> m_pClientMmanager;
TD::object_ptr<TD::AuthorizationState> pAuthState;
- bool m_bAuthorized, m_bRunning = false, m_bTerminated;
+ bool m_bAuthorized, m_bTerminated, m_bUnregister = false;
int32_t m_iClientId, m_iMsgId;
uint64_t m_iQueryId;
@@ -108,6 +112,7 @@ class CMTProto : public PROTO<CMTProto>
void OnUpdateAuth(td::ClientManager::Response &response);
void LogOut(void);
+ void OnEndSession(td::ClientManager::Response &response);
void OnLoggedIn(void);
void ProcessResponse(td::ClientManager::Response);
void SendKeepAlive(void);
diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp
index 8dede07c4c..8792000d59 100644
--- a/protocols/Telegram/src/server.cpp
+++ b/protocols/Telegram/src/server.cpp
@@ -17,18 +17,25 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
+void CMTProto::OnEndSession(td::ClientManager::Response&)
+{
+ m_bTerminated = true;
+}
+
void __cdecl CMTProto::ServerThread(void *)
{
- m_bRunning = true;
m_bTerminated = m_bAuthorized = false;
+ m_pClientMmanager = std::make_unique<td::ClientManager>();
+ m_iClientId = m_pClientMmanager->create_client_id();
+
SendQuery(new TD::getOption("version"));
while (!m_bTerminated) {
ProcessResponse(m_pClientMmanager->receive(1));
}
- m_bRunning = false;
+ m_pClientMmanager = std::move(nullptr);
}
void CMTProto::LogOut()
@@ -55,7 +62,11 @@ void CMTProto::OnLoggedIn()
ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)m_iStatus, m_iDesiredStatus);
m_iStatus = m_iDesiredStatus;
- SendQuery(new TD::getChats(td::tl::unique_ptr<TD::chatListMain>(), 1000));
+ if (m_bUnregister) {
+ SendQuery(new TD::terminateSession());
+ SendQuery(new TD::logOut(), &CMTProto::OnEndSession);
+ }
+ else SendQuery(new TD::getChats(td::tl::unique_ptr<TD::chatListMain>(), 1000));
}
///////////////////////////////////////////////////////////////////////////////
@@ -254,7 +265,6 @@ void CMTProto::ProcessGroups(TD::updateChatFilters *pObj)
Clist_GroupRename(oldGroup, wszFullGroup);
setWString(szSetting, wszNewValue);
}
-
}
}