summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-12-09 18:45:50 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-12-09 18:45:50 +0300
commit4d29366657d2ee93db4913a5a07af0d26820c058 (patch)
treec57928b85446f7051d49f84f1e3299a6733442d1
parent49e7758046391bb9c49faf37020c27523f913b57 (diff)
Telegram: unused bots auto-remover
-rw-r--r--protocols/Telegram/src/proto.cpp4
-rw-r--r--protocols/Telegram/src/proto.h2
-rw-r--r--protocols/Telegram/src/server.cpp7
3 files changed, 9 insertions, 4 deletions
diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp
index c7836d4e03..e112712128 100644
--- a/protocols/Telegram/src/proto.cpp
+++ b/protocols/Telegram/src/proto.cpp
@@ -169,6 +169,10 @@ void CTelegramProto::OnModulesLoaded()
void CTelegramProto::OnShutdown()
{
m_bTerminated = true;
+
+ for (auto &cc : m_arUsers)
+ if (cc->isBot && !cc->chatId && cc->hContact != INVALID_CONTACT_ID)
+ Contact::RemoveFromList(cc->hContact);
}
int CTelegramProto::OnWindowEvent(WPARAM wParam, LPARAM lParam)
diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h
index 8cf525801a..4edce9f591 100644
--- a/protocols/Telegram/src/proto.h
+++ b/protocols/Telegram/src/proto.h
@@ -98,7 +98,7 @@ struct TG_USER : public MZeroedObject
int64_t id, chatId = -1;
MCONTACT hContact;
- bool isGroupChat, bLoadMembers, bStartChat;
+ bool isGroupChat, isBot, bLoadMembers, bStartChat;
CMStringA szAvatarHash;
CMStringW wszNick, wszFirstName, wszLastName;
time_t m_timer1 = 0, m_timer2 = 0;
diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp
index 4b91e3fae8..7965335227 100644
--- a/protocols/Telegram/src/server.cpp
+++ b/protocols/Telegram/src/server.cpp
@@ -976,10 +976,11 @@ void CTelegramProto::ProcessUser(TD::updateUser *pObj)
if (pUser->is_premium_)
ExtraIcon_SetIconByName(g_plugin.m_hIcon, pu->hContact, "tg_premium");
- else if (typeID == TD::userTypeBot::ID)
+ else if (typeID == TD::userTypeBot::ID) {
+ pu->isBot = true;
ExtraIcon_SetIconByName(g_plugin.m_hIcon, pu->hContact, "tg_bot");
- else
- ExtraIcon_SetIconByName(g_plugin.m_hIcon, pu->hContact, nullptr);
+ }
+ else ExtraIcon_SetIconByName(g_plugin.m_hIcon, pu->hContact, nullptr);
if (auto *pPhoto = pUser->profile_photo_.get()) {
if (auto *pSmall = pPhoto->small_.get()) {