diff options
-rw-r--r-- | protocols/Telegram/src/proto.cpp | 4 | ||||
-rw-r--r-- | protocols/Telegram/src/proto.h | 1 | ||||
-rw-r--r-- | protocols/Telegram/src/server.cpp | 26 | ||||
-rw-r--r-- | protocols/Telegram/src/utils.cpp | 4 |
4 files changed, 26 insertions, 9 deletions
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<CTelegramProto> 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<TD::chatListMain>(), 1000));
+ SendQuery(new TD::getChats(td::tl::unique_ptr<TD::chatListMain>(), 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;
|