From c71cb8e1f735a198c33c63ee9bd92f65e94f6643 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 15 Mar 2023 20:38:09 +0300 Subject: Telegram: ability to leave group chats / channels --- protocols/Telegram/src/groupchat.cpp | 31 ++++++++++++++++++++++++++++++- protocols/Telegram/src/proto.h | 1 + 2 files changed, 31 insertions(+), 1 deletion(-) (limited to 'protocols/Telegram') diff --git a/protocols/Telegram/src/groupchat.cpp b/protocols/Telegram/src/groupchat.cpp index 76fb694a5c..b32db4c13f 100644 --- a/protocols/Telegram/src/groupchat.cpp +++ b/protocols/Telegram/src/groupchat.cpp @@ -130,6 +130,11 @@ void CTelegramProto::StartGroupChat(td::ClientManager::Response &response, void ///////////////////////////////////////////////////////////////////////////////////////// +enum +{ + IDM_LEAVE = 1, +}; + int CTelegramProto::GcEventHook(WPARAM, LPARAM lParam) { GCHOOK *gch = (GCHOOK *)lParam; @@ -155,6 +160,7 @@ int CTelegramProto::GcEventHook(WPARAM, LPARAM lParam) break; case GC_USER_LOGMENU: + Chat_LogMenu(gch); break; case GC_USER_NICKLISTMENU: @@ -164,6 +170,23 @@ int CTelegramProto::GcEventHook(WPARAM, LPARAM lParam) return 1; } +void CTelegramProto::Chat_LogMenu(GCHOOK *gch) +{ + switch (gch->dwData) { + case IDM_LEAVE: + int64_t id(_atoi64(getMStringA(gch->si->hContact, DBKEY_ID))); + if (auto *pUser = FindUser(id)) { + pUser->m_si = nullptr; + SendQuery(new TD::leaveChat(pUser->chatId)); + } + + Chat_Terminate(gch->si); + Contact::Hide(gch->si->hContact); + Contact::RemoveFromList(gch->si->hContact); + break; + } +} + void CTelegramProto::Chat_SendPrivateMessage(GCHOOK *gch) { MCONTACT hContact; @@ -189,6 +212,11 @@ void CTelegramProto::Chat_SendPrivateMessage(GCHOOK *gch) ///////////////////////////////////////////////////////////////////////////////////////// +static gc_item sttLogListItems[] = +{ + { LPGENW("&Leave chat session"), IDM_LEAVE, MENU_ITEM } +}; + int CTelegramProto::GcMenuHook(WPARAM, LPARAM lParam) { GCMENUITEMS *gcmi = (GCMENUITEMS *)lParam; @@ -198,11 +226,12 @@ int CTelegramProto::GcMenuHook(WPARAM, LPARAM lParam) if (mir_strcmpi(gcmi->pszModule, m_szModuleName)) return 0; - auto *pUser = FindUser(T2Utf(gcmi->pszID)); + auto *pUser = FindUser(_wtoi64(gcmi->pszID)); if (pUser == nullptr) return 0; if (gcmi->Type == MENU_ON_LOG) { + Chat_AddMenuItems(gcmi->hMenu, _countof(sttLogListItems), sttLogListItems, &g_plugin); } else if (gcmi->Type == MENU_ON_NICKLIST) { } diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index 4431ebe232..fd08f08de2 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -234,6 +234,7 @@ class CTelegramProto : public PROTO void StartGroupChat(td::ClientManager::Response &response, void *pUserData); void Chat_SendPrivateMessage(GCHOOK *gch); + void Chat_LogMenu(GCHOOK *gch); // Search TD::array m_searchIds; -- cgit v1.2.3