From b96cd0c6250570ec58eda0e7c534bd39c62418a1 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 9 Dec 2023 20:01:34 +0300 Subject: =?UTF-8?q?fixes=20#4029=20(Telegram:=20=D0=BF=D1=80=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BA=D0=B8=D0=B4=D0=B0=D0=BD=D0=B8=D0=B8=20=D0=B3?= =?UTF-8?q?=D1=80=D1=83=D0=BF=D0=BF=D1=8B=20=D0=BF=D1=83=D1=82=D1=91=D0=BC?= =?UTF-8?q?=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BD=D1=82=D0=B0=D0=BA=D1=82=D0=B0=20=D0=B8=D0=B7=20?= =?UTF-8?q?=D0=B1=D0=B0=D0=B7=D1=8B,=20=D0=B3=D1=80=D1=83=D0=BF=D0=BF?= =?UTF-8?q?=D0=B0=20=D0=BE=D1=81=D1=82=D0=B0=D1=91=D1=82=D1=81=D1=8F=20?= =?UTF-8?q?=D0=B2=D0=B8=D1=81=D0=B5=D1=82=D1=8C=20=D0=B2=20=D1=81=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D0=BA=D0=B5=20=D0=BA=D0=BE=D0=BD=D1=82=D0=B0=D0=BA?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=20=D1=81=D0=B5=D1=80=D0=BE=D0=B9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/Telegram/src/groupchat.cpp | 23 +++++++++++++++-------- protocols/Telegram/src/proto.cpp | 18 ++++++++++++------ protocols/Telegram/src/proto.h | 3 ++- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/protocols/Telegram/src/groupchat.cpp b/protocols/Telegram/src/groupchat.cpp index 99198d452e..e63f633b9c 100644 --- a/protocols/Telegram/src/groupchat.cpp +++ b/protocols/Telegram/src/groupchat.cpp @@ -244,20 +244,27 @@ void CTelegramProto::Chat_LogMenu(GCHOOK *gch) } } -INT_PTR CTelegramProto::SvcLeaveChat(WPARAM hContact, LPARAM) +///////////////////////////////////////////////////////////////////////////////////////// + +void CTelegramProto::OnLeaveChat(td::ClientManager::Response &, void *pUserInfo) { - int64_t id = GetId(hContact); - if (auto *pUser = FindUser(id)) { - pUser->m_si = nullptr; - SendQuery(new TD::leaveChat(pUser->chatId)); - } + auto *pUser = (TG_USER *)pUserInfo; wchar_t wszId[100]; - _i64tow(id, wszId, 10); + _i64tow(pUser->id, wszId, 10); if (auto *si = Chat_Find(wszId, m_szModuleName)) Chat_Terminate(si); - db_delete_contact(hContact); + db_delete_contact(pUser->hContact); +} + +INT_PTR CTelegramProto::SvcLeaveChat(WPARAM hContact, LPARAM) +{ + int64_t id = GetId(hContact); + if (auto *pUser = FindUser(id)) { + pUser->m_si = nullptr; + SendQuery(new TD::leaveChat(pUser->chatId), &CTelegramProto::OnLeaveChat, pUser); + } return 0; } diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp index e112712128..8d15a38f33 100644 --- a/protocols/Telegram/src/proto.cpp +++ b/protocols/Telegram/src/proto.cpp @@ -116,22 +116,28 @@ void CTelegramProto::OnContactAdded(MCONTACT hContact) } } -void CTelegramProto::OnContactDeleted(MCONTACT hContact) +bool CTelegramProto::OnContactDeleted(MCONTACT hContact) { TD::int53 id = GetId(hContact); if (id == 0) - return; - - TD::array ids; - ids.push_back(id); - SendQuery(new TD::removeContacts(std::move(ids))); + return false; if (auto *pUser = FindUser(id)) { + if (pUser->m_si) { + SvcLeaveChat(hContact, 0); + return false; + } + pUser->hContact = INVALID_CONTACT_ID; pUser->wszNick = getMStringW(hContact, "Nick"); pUser->wszFirstName = getMStringW(hContact, "FirstName"); pUser->wszLastName = getMStringW(hContact, "LastName"); } + + TD::array ids; + ids.push_back(id); + SendQuery(new TD::removeContacts(std::move(ids))); + return true; } int CTelegramProto::OnEmptyHistory(WPARAM hContact, LPARAM) diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index 4edce9f591..a4f8520abf 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -227,6 +227,7 @@ class CTelegramProto : public PROTO void OnGetHistory(td::ClientManager::Response &response, void *pUserInfo); void OnGetSessions(td::ClientManager::Response &response, void *pUserInfo); void OnKillSession(td::ClientManager::Response &response, void *pUserInfo); + void OnLeaveChat(td::ClientManager::Response &response, void *pUserInfo); void OnSendFile(td::ClientManager::Response &response, void *pUserInfo); void OnSendMessage(td::ClientManager::Response &response); void OnUpdateAuth(td::ClientManager::Response &response); @@ -366,7 +367,7 @@ public: void OnBuildProtoMenu() override; void OnContactAdded(MCONTACT hContact) override; - void OnContactDeleted(MCONTACT hContact) override; + bool OnContactDeleted(MCONTACT hContact) override; MWindow OnCreateAccMgrUI(MWindow hwndParent) override; void OnErase() override; void OnEventDeleted(MCONTACT, MEVENT) override; -- cgit v1.2.3