summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2023-03-22 17:46:49 +0300
committerGeorge Hazan <ghazan@miranda.im>2023-03-22 17:46:49 +0300
commited54464972bcea62c617e1ade88722454b037ee0 (patch)
treedd20ac95a60aecd523676eef852f5fcda3f80b3b
parenta7ef6936c39f27ae844712c549ad5d5bc5a19015 (diff)
fixes #3448 (Telegram: настройка глушения чатов синхронизируется лишь в одну сторону (от сервера к нам)
-rw-r--r--include/m_chat.h10
-rw-r--r--protocols/Telegram/src/groupchat.cpp26
-rw-r--r--protocols/Telegram/src/proto.cpp3
-rw-r--r--protocols/Telegram/src/proto.h2
-rw-r--r--protocols/Telegram/src/server.cpp2
-rw-r--r--src/mir_app/src/chat_svc.cpp17
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
@@ -559,9 +559,19 @@ 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<TD::chatNotificationSettings>();
+ 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);