From 138ef5cc83e69cb37632c8f039d5a4e8dbb0ed45 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 7 Feb 2023 20:23:35 +0300 Subject: Telegram: ability to send messages to group chats --- protocols/Telegram/src/groupchat.cpp | 57 ++++++++++++++++++++++++++++++++++++ protocols/Telegram/src/proto.cpp | 4 +-- protocols/Telegram/src/proto.h | 5 +++- protocols/Telegram/src/stdafx.h | 2 +- 4 files changed, 64 insertions(+), 4 deletions(-) (limited to 'protocols/Telegram/src') diff --git a/protocols/Telegram/src/groupchat.cpp b/protocols/Telegram/src/groupchat.cpp index c0f815aa8a..fdcb45faa7 100644 --- a/protocols/Telegram/src/groupchat.cpp +++ b/protocols/Telegram/src/groupchat.cpp @@ -123,3 +123,60 @@ void CTelegramProto::StartGroupChat(td::ClientManager::Response &response, void Chat_Control(pUser->m_si, m_bHideGroupchats ? WINDOW_HIDDEN : SESSION_INITDONE); Chat_Control(pUser->m_si, SESSION_ONLINE); } + +///////////////////////////////////////////////////////////////////////////////////////// + +int CTelegramProto::GcEventHook(WPARAM, LPARAM lParam) +{ + GCHOOK *gch = (GCHOOK *)lParam; + if (gch == nullptr) + return 0; + + if (mir_strcmpi(gch->si->pszModule, m_szModuleName)) + return 0; + + auto userId = _wtoi64(gch->si->ptszID); + + switch (gch->iType) { + case GC_USER_MESSAGE: + if (gch->ptszText && mir_wstrlen(gch->ptszText) > 0) { + rtrimw(gch->ptszText); + Chat_UnescapeTags(gch->ptszText); + SendTextMessage(-userId, T2Utf(gch->ptszText)); + } + break; + + case GC_USER_PRIVMESS: + break; + + case GC_USER_LOGMENU: + break; + + case GC_USER_NICKLISTMENU: + break; + } + + return 1; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +int CTelegramProto::GcMenuHook(WPARAM, LPARAM lParam) +{ + GCMENUITEMS *gcmi = (GCMENUITEMS *)lParam; + if (gcmi == nullptr) + return 0; + + if (mir_strcmpi(gcmi->pszModule, m_szModuleName)) + return 0; + + auto *pUser = FindUser(T2Utf(gcmi->pszID)); + if (pUser == nullptr) + return 0; + + if (gcmi->Type == MENU_ON_LOG) { + } + else if (gcmi->Type == MENU_ON_NICKLIST) { + } + return 0; +} diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp index 06ac895087..9762c3c316 100644 --- a/protocols/Telegram/src/proto.cpp +++ b/protocols/Telegram/src/proto.cpp @@ -80,8 +80,8 @@ CTelegramProto::CTelegramProto(const char* protoName, const wchar_t* userName) : gcr.pszModule = m_szModuleName; Chat_Register(&gcr); - // HookProtoEvent(ME_GC_EVENT, &WhatsAppProto::GcEventHook); - // HookProtoEvent(ME_GC_BUILDMENU, &WhatsAppProto::GcMenuHook); + HookProtoEvent(ME_GC_EVENT, &CTelegramProto::GcEventHook); + HookProtoEvent(ME_GC_BUILDMENU, &CTelegramProto::GcMenuHook); } CTelegramProto::~CTelegramProto() diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index 476deea871..bb0238d494 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -248,12 +248,15 @@ public: // Services ////////////////////////////////////////////////////////////////////////// INT_PTR __cdecl SvcCreateAccMgrUI(WPARAM, LPARAM); - + // Events //////////////////////////////////////////////////////////////////////////// int __cdecl OnOptionsInit(WPARAM, LPARAM); int __cdecl OnDbMarkedRead(WPARAM, LPARAM); + int __cdecl GcMenuHook(WPARAM, LPARAM); + int __cdecl GcEventHook(WPARAM, LPARAM); + // Options /////////////////////////////////////////////////////////////////////////// CMOption m_iCountry; // set this status to m_iStatus1 after this interval of secs diff --git a/protocols/Telegram/src/stdafx.h b/protocols/Telegram/src/stdafx.h index 47564f1ee3..bce763709d 100644 --- a/protocols/Telegram/src/stdafx.h +++ b/protocols/Telegram/src/stdafx.h @@ -14,7 +14,7 @@ #include #include -#include +#include #include #include #include -- cgit v1.2.3