From 1c5f9fca3e84bcddff36a70fbce0c48d9eb78be3 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 14 Nov 2023 15:51:03 +0300 Subject: =?UTF-8?q?fixes=20#3771=20(Telegram:=20=D0=B4=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B1=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D0=B2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/Telegram/src/proto.cpp | 4 +--- protocols/Telegram/src/proto.h | 1 + protocols/Telegram/src/server.cpp | 26 ++++++++++++++++++++++++-- protocols/Telegram/src/utils.cpp | 4 ---- 4 files changed, 26 insertions(+), 9 deletions(-) (limited to 'protocols/Telegram/src') diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp index 9878ab5369..801c8eca7a 100644 --- a/protocols/Telegram/src/proto.cpp +++ b/protocols/Telegram/src/proto.cpp @@ -143,9 +143,7 @@ void CTelegramProto::OnModulesLoaded() auto *pUser = new TG_USER(id, cc, isGroupChat); pUser->szAvatarHash = getMStringA(cc, DBKEY_AVATAR_HASH); m_arUsers.insert(pUser); - if (!isGroupChat) - m_arChats.insert(pUser); - else if (iCompatLevel < 3) + if (isGroupChat && iCompatLevel < 3) _wremove(CMStringW(FORMAT, L"%s\\%d.json", cachePath.get(), cc)); } } diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index c5566472d8..225e7b7622 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -225,6 +225,7 @@ class CTelegramProto : public PROTO void OnSendFile(td::ClientManager::Response &response, void *pUserInfo); void OnSendMessage(td::ClientManager::Response &response); void OnUpdateAuth(td::ClientManager::Response &response); + void OnGetChats(td::ClientManager::Response &response); void LogOut(void); void OnLoggedIn(void); diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index e2eb723e68..3aad877837 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -57,6 +57,27 @@ void CTelegramProto::LogOut() it->m_si = nullptr; } +/////////////////////////////////////////////////////////////////////////////// + +void CTelegramProto::OnGetChats(td::ClientManager::Response &response) +{ + if (!response.object) + return; + + if (response.object->get_id() != TD::chats::ID) { + debugLogA("Gotten class ID %d instead of %d, exiting", response.object->get_id(), TD::chats::ID); + return; + } + + auto *pChats = (TD::chats *)response.object.get(); + for (auto &it : pChats->chat_ids_) { + if (auto *pUser = FindChat(it)) + Contact::PutOnList(pUser->hContact); + else + SendQuery(new TD::getChat(it)); + } +} + void CTelegramProto::OnLoggedIn() { m_bAuthorized = true; @@ -76,7 +97,7 @@ void CTelegramProto::OnLoggedIn() m_impl.m_keepAlive.Start(1000); setByte(DBKEY_AUTHORIZED, 1); - SendQuery(new TD::getChats(td::tl::unique_ptr(), 1000)); + SendQuery(new TD::getChats(td::tl::unique_ptr(), 1000), &CTelegramProto::OnGetChats); } } @@ -850,8 +871,9 @@ void CTelegramProto::ProcessUser(TD::updateUser *pObj) { auto *pUser = pObj->user_.get(); bool bIsMe = pUser->id_ == m_iOwnId; + auto typeID = (pUser->type_) ? pUser->type_->get_id() : 0; - if (!bIsMe && !pUser->is_contact_) { + if (!bIsMe && !pUser->is_contact_ && typeID == TD::userTypeRegular::ID) { auto *pu = AddFakeUser(pUser->id_, false); if (pu->hContact != INVALID_CONTACT_ID) Contact::RemoveFromList(pu->hContact); diff --git a/protocols/Telegram/src/utils.cpp b/protocols/Telegram/src/utils.cpp index 40fb649268..95cde5afb3 100644 --- a/protocols/Telegram/src/utils.cpp +++ b/protocols/Telegram/src/utils.cpp @@ -161,8 +161,6 @@ TG_USER* CTelegramProto::AddFakeUser(int64_t id, bool bIsChat) if (pu == nullptr) { pu = new TG_USER(id, INVALID_CONTACT_ID, bIsChat); m_arUsers.insert(pu); - if (!bIsChat) - m_arChats.insert(pu); } return pu; } @@ -189,8 +187,6 @@ TG_USER* CTelegramProto::AddUser(int64_t id, bool bIsChat) if (pUser == nullptr) { pUser = new TG_USER(id, hContact, bIsChat); m_arUsers.insert(pUser); - if (!bIsChat) - m_arChats.insert(pUser); } else { pUser->hContact = hContact; -- cgit v1.2.3