summaryrefslogtreecommitdiff
path: root/protocols/Telegram
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2023-03-15 20:38:09 +0300
committerGeorge Hazan <ghazan@miranda.im>2023-03-15 20:38:09 +0300
commitc71cb8e1f735a198c33c63ee9bd92f65e94f6643 (patch)
tree68dfb1511c83ea4eba97192b45aa850c4563babe /protocols/Telegram
parentcf91db5000d4f11745e2fe8bb6e7f5c6c6ba162a (diff)
Telegram: ability to leave group chats / channels
Diffstat (limited to 'protocols/Telegram')
-rw-r--r--protocols/Telegram/src/groupchat.cpp31
-rw-r--r--protocols/Telegram/src/proto.h1
2 files changed, 31 insertions, 1 deletions
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<CTelegramProto>
void StartGroupChat(td::ClientManager::Response &response, void *pUserData);
void Chat_SendPrivateMessage(GCHOOK *gch);
+ void Chat_LogMenu(GCHOOK *gch);
// Search
TD::array<TD::int53> m_searchIds;