From 3ea151ed7440be73dccc664c0464e0dfc8e72ad0 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 30 Sep 2024 13:40:14 +0300 Subject: fixes #4696 (MessageState: add Telegram support) --- protocols/Telegram/src/main.cpp | 18 +++++++++++++++++- protocols/Telegram/src/server.cpp | 3 +++ protocols/Telegram/src/stdafx.h | 4 +++- 3 files changed, 23 insertions(+), 2 deletions(-) (limited to 'protocols') diff --git a/protocols/Telegram/src/main.cpp b/protocols/Telegram/src/main.cpp index 411a286ffc..a6b8ff67e8 100644 --- a/protocols/Telegram/src/main.cpp +++ b/protocols/Telegram/src/main.cpp @@ -46,10 +46,26 @@ static IconItem iconList[] = { LPGEN("Bot"), "bot", IDI_BOT }, }; +static int OnModuleLoaded(WPARAM, LPARAM) +{ + g_plugin.hasMessageState = ServiceExists(MS_MESSAGESTATE_UPDATE); + return 0; +} + +static int OnModulesLoaded(WPARAM, LPARAM) +{ + HookEvent(ME_SYSTEM_MODULELOAD, OnModuleLoaded); + HookEvent(ME_SYSTEM_MODULEUNLOAD, OnModuleLoaded); + OnModuleLoaded(0, 0); + return 0; +} + int CMPlugin::Load() { registerIcon("Protocols/Telegram", iconList, "tg"); - + + HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); + m_hIcon = ExtraIcon_RegisterIcolib("tg_premium", LPGEN("Telegram Premium user"), getIconHandle(IDI_PREMIUM)); return 0; } diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index c2c8d3c1f2..b770fe42ef 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -880,6 +880,9 @@ void CTelegramProto::ProcessMarkRead(TD::updateChatReadInbox *pObj) db_event_markRead(pUser->hContact, hEvent, true); } + if (g_plugin.hasMessageState && pObj->unread_count_ == 0) + CallService(MS_MESSAGESTATE_UPDATE, GetRealContact(pUser), MRD_TYPE_READ); + if (Contact::IsGroupChat(pUser->hContact) && pObj->unread_count_ == 0) delSetting(pUser->hContact, "ApparentMode"); } diff --git a/protocols/Telegram/src/stdafx.h b/protocols/Telegram/src/stdafx.h index 45fbab04cf..11bfb43809 100644 --- a/protocols/Telegram/src/stdafx.h +++ b/protocols/Telegram/src/stdafx.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -51,7 +52,8 @@ struct CMPlugin : public ACCPROTOPLUGIN { CMPlugin(); - HANDLE m_hIcon; + bool hasMessageState = false; + HANDLE m_hIcon = 0; int Load() override; }; -- cgit v1.2.3