From ed54464972bcea62c617e1ade88722454b037ee0 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 22 Mar 2023 17:46:49 +0300 Subject: =?UTF-8?q?fixes=20#3448=20(Telegram:=20=D0=BD=D0=B0=D1=81=D1=82?= =?UTF-8?q?=D1=80=D0=BE=D0=B9=D0=BA=D0=B0=20=D0=B3=D0=BB=D1=83=D1=88=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D1=87=D0=B0=D1=82=D0=BE=D0=B2=20=D1=81?= =?UTF-8?q?=D0=B8=D0=BD=D1=85=D1=80=D0=BE=D0=BD=D0=B8=D0=B7=D0=B8=D1=80?= =?UTF-8?q?=D1=83=D0=B5=D1=82=D1=81=D1=8F=20=D0=BB=D0=B8=D1=88=D1=8C=20?= =?UTF-8?q?=D0=B2=20=D0=BE=D0=B4=D0=BD=D1=83=20=D1=81=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=BE=D0=BD=D1=83=20(=D0=BE=D1=82=20=D1=81=D0=B5=D1=80=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D0=B0=20=D0=BA=20=D0=BD=D0=B0=D0=BC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/m_chat.h | 10 ++++++++++ protocols/Telegram/src/groupchat.cpp | 26 ++++++++++++++++++++++++++ protocols/Telegram/src/proto.cpp | 3 ++- protocols/Telegram/src/proto.h | 2 ++ protocols/Telegram/src/server.cpp | 2 ++ src/mir_app/src/chat_svc.cpp | 17 +++++------------ 6 files changed, 47 insertions(+), 13 deletions(-) diff --git a/include/m_chat.h b/include/m_chat.h index 1c628bf8d6..96ddddf297 100644 --- a/include/m_chat.h +++ b/include/m_chat.h @@ -558,10 +558,20 @@ typedef struct { MIR_APP_DLL(void) Chat_AddMenuItems(HMENU hMenu, int nItems, const gc_item *Item, HPLUGIN pPlugin); +////////////////////////////////////////////////////////////////////////// +// Mute chat event +// called when a user manually changes mute mode for a group chat +// wParam = (MCONTACT)hContact +// lParam = new mute mode (one of CHATMUTE_* constants) + +#define ME_GC_MUTE "GChat/Mute" + ////////////////////////////////////////////////////////////////////////// // Get Chat ToolTip Text for buddy // wParam = (WPARAM)(wchar_t*) roomID parentdat->ptszID // lParam = (WPARAM)(wchar_t*) userID ui1->pszUID // result (int)(wchar_t*)mir_tstrdup("tooltip text") // returns pointer to text of tooltip and starts owns it + #define MS_GC_PROTO_GETTOOLTIPTEXT "/GetChatToolTipText" + diff --git a/protocols/Telegram/src/groupchat.cpp b/protocols/Telegram/src/groupchat.cpp index b32db4c13f..c0ea6165e8 100644 --- a/protocols/Telegram/src/groupchat.cpp +++ b/protocols/Telegram/src/groupchat.cpp @@ -130,6 +130,32 @@ void CTelegramProto::StartGroupChat(td::ClientManager::Response &response, void ///////////////////////////////////////////////////////////////////////////////////////// +int CTelegramProto::GcMuteHook(WPARAM hContact, LPARAM mode) +{ + if (Proto_IsProtoOnContact(hContact, m_szModuleName)) { + if (auto *pUser = FindUser(_atoi64(getMStringA(hContact, DBKEY_ID)))) { + auto settings = TD::make_object(); + memcpy(settings.get(), &pUser->notificationSettings, sizeof(pUser->notificationSettings)); + + switch (mode) { + case CHATMODE_MUTE: + settings->use_default_mute_for_ = false; + settings->mute_for_ = 45000000; + break; + + default: + settings->use_default_mute_for_ = true; + settings->mute_for_ = 0; + break; + } + SendQuery(new TD::setChatNotificationSettings(pUser->chatId, std::move(settings))); + } + } + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + enum { IDM_LEAVE = 1, diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp index d7cac65780..090619cc5d 100644 --- a/protocols/Telegram/src/proto.cpp +++ b/protocols/Telegram/src/proto.cpp @@ -61,7 +61,7 @@ CTelegramProto::CTelegramProto(const char* protoName, const wchar_t* userName) : HookProtoEvent(ME_HISTORY_EMPTY, &CTelegramProto::OnEmptyHistory); HookProtoEvent(ME_OPT_INITIALISE, &CTelegramProto::OnOptionsInit); - + // avatar CreateDirectoryTreeW(GetAvatarPath()); @@ -82,6 +82,7 @@ CTelegramProto::CTelegramProto(const char* protoName, const wchar_t* userName) : gcr.pszModule = m_szModuleName; Chat_Register(&gcr); + 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 657dce496a..af6c3d9851 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -93,6 +93,7 @@ struct TG_USER CMStringW wszNick, wszFirstName, wszLastName; time_t m_timer1 = 0, m_timer2 = 0; SESSION_INFO *m_si = nullptr; + TD::chatNotificationSettings notificationSettings; CMStringW getDisplayName() const; }; @@ -300,6 +301,7 @@ public: int __cdecl OnOptionsInit(WPARAM, LPARAM); int __cdecl GcMenuHook(WPARAM, LPARAM); + int __cdecl GcMuteHook(WPARAM, LPARAM); int __cdecl GcEventHook(WPARAM, LPARAM); // Services ////////////////////////////////////////////////////////////////////////// diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index 8641e202e9..2204be7de6 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -374,6 +374,8 @@ void CTelegramProto::ProcessChatNotification(TD::updateChatNotificationSettings Chat_Mute(pUser->hContact, CHATMODE_MUTE); else Chat_Mute(pUser->hContact, CHATMODE_NORMAL); + + memcpy(&pUser->notificationSettings, pSettings.get(), sizeof(pUser->notificationSettings)); } void CTelegramProto::ProcessChatPosition(TD::updateChatPosition *pObj) diff --git a/src/mir_app/src/chat_svc.cpp b/src/mir_app/src/chat_svc.cpp index c3c47430f9..0898e91402 100644 --- a/src/mir_app/src/chat_svc.cpp +++ b/src/mir_app/src/chat_svc.cpp @@ -55,17 +55,8 @@ mir_cs csChat; MWindowList g_hWindowList; HANDLE hevSendEvent, hevBuildMenuEvent; -static HANDLE - hServiceRegister = nullptr, - hServiceNewChat = nullptr, - hServiceAddEvent = nullptr, - hServiceGetAddEventPtr = nullptr, - hServiceGetInfo = nullptr, - hServiceGetCount = nullptr, - hEventPrebuildMenu = nullptr, - hEventDoubleclicked = nullptr, - hEventJoinChat = nullptr, - hEventLeaveChat = nullptr, +static HANDLE + hevMuteChat = nullptr, hHookEvent = nullptr; void SrmmModulesLoaded(); @@ -863,6 +854,7 @@ static int OnContactDeleted(WPARAM hContact, LPARAM) static INT_PTR MuteChat(WPARAM hContact, LPARAM param) { Chat_Mute(hContact, param); + NotifyEventHooks(hevMuteChat, hContact, param); return 0; } @@ -1002,9 +994,10 @@ int LoadChatModule(void) g_hWindowList = WindowList_Create(); hHookEvent = CreateHookableEvent(ME_GC_HOOK_EVENT); + hevMuteChat = CreateHookableEvent(ME_GC_MUTE); hevSendEvent = CreateHookableEvent(ME_GC_EVENT); hevBuildMenuEvent = CreateHookableEvent(ME_GC_BUILDMENU); - + g_chatApi.hevPreCreate = CreateHookableEvent(ME_MSG_PRECREATEEVENT); g_chatApi.hevWinPopup = CreateHookableEvent(ME_MSG_WINDOWPOPUP); -- cgit v1.2.3