summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-11-23 21:17:43 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-11-23 21:17:43 +0300
commitc8aa8dbfc81a52727783831e6278fcf332fbcaf0 (patch)
tree6ec2a0f153a01008317ddcf1f6701d261ebd911b /protocols
parent3c12982c6099bb782ffa1738894465b7ab8d58e1 (diff)
Telegram: "Leave chat" contact menu item for channels & groups
Diffstat (limited to 'protocols')
-rw-r--r--protocols/Telegram/src/groupchat.cpp29
-rw-r--r--protocols/Telegram/src/proto.cpp2
-rw-r--r--protocols/Telegram/src/proto.h2
3 files changed, 23 insertions, 10 deletions
diff --git a/protocols/Telegram/src/groupchat.cpp b/protocols/Telegram/src/groupchat.cpp
index c456f05558..4962a1ac85 100644
--- a/protocols/Telegram/src/groupchat.cpp
+++ b/protocols/Telegram/src/groupchat.cpp
@@ -224,20 +224,29 @@ void CTelegramProto::Chat_LogMenu(GCHOOK *gch)
{
switch (gch->dwData) {
case IDM_LEAVE:
- int64_t id = GetId(gch->si->hContact);
- if (auto *pUser = FindUser(id)) {
- pUser->m_si = nullptr;
- SendQuery(new TD::leaveChat(pUser->chatId));
- }
-
- Contact::Hide(gch->si->hContact);
- Contact::RemoveFromList(gch->si->hContact);
-
- Chat_Terminate(gch->si);
+ SvcLeaveChat(gch->si->hContact, 0);
break;
}
}
+INT_PTR CTelegramProto::SvcLeaveChat(WPARAM hContact, LPARAM)
+{
+ int64_t id = GetId(hContact);
+ if (auto *pUser = FindUser(id)) {
+ pUser->m_si = nullptr;
+ SendQuery(new TD::leaveChat(pUser->chatId));
+ }
+
+ Contact::Hide(hContact);
+ Contact::RemoveFromList(hContact);
+
+ wchar_t wszId[100];
+ _i64tow(id, wszId, 10);
+ if (auto *si = Chat_Find(wszId, m_szModuleName))
+ Chat_Terminate(si);
+ return 0;
+}
+
void CTelegramProto::Chat_SendPrivateMessage(GCHOOK *gch)
{
MCONTACT hContact;
diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp
index f3ea4f43e5..c842a623aa 100644
--- a/protocols/Telegram/src/proto.cpp
+++ b/protocols/Telegram/src/proto.cpp
@@ -96,6 +96,8 @@ CTelegramProto::CTelegramProto(const char* protoName, const wchar_t* userName) :
gcr.pszModule = m_szModuleName;
Chat_Register(&gcr);
+ CreateProtoService(PS_LEAVECHAT, &CTelegramProto::SvcLeaveChat);
+
HookProtoEvent(ME_GC_MUTE, &CTelegramProto::GcMuteHook);
HookProtoEvent(ME_GC_EVENT, &CTelegramProto::GcEventHook);
HookProtoEvent(ME_GC_BUILDMENU, &CTelegramProto::GcMenuHook);
diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h
index b0c68e3834..3620ff78f0 100644
--- a/protocols/Telegram/src/proto.h
+++ b/protocols/Telegram/src/proto.h
@@ -276,6 +276,8 @@ class CTelegramProto : public PROTO<CTelegramProto>
OBJLIST<TG_BASIC_GROUP> m_arBasicGroups;
OBJLIST<TG_SUPER_GROUP> m_arSuperGroups;
+ INT_PTR __cdecl SvcLeaveChat(WPARAM, LPARAM);
+
void InitGroupChat(TG_USER *pUser, const TD::chat *pChat);
void StartGroupChat(td::ClientManager::Response &response, void *pUserData);