From ee868b7339322e7222cb62741f397d97180c96cb Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 21 Oct 2024 18:17:12 +0300 Subject: VK: remote read support for NewStory --- protocols/VKontakte/src/main.cpp | 4 ++-- protocols/VKontakte/src/misc.cpp | 20 ++++++++++++++++++-- protocols/VKontakte/src/vk.h | 1 - protocols/VKontakte/src/vk_messages.cpp | 2 +- protocols/VKontakte/src/vk_pollserver.cpp | 12 ++---------- protocols/VKontakte/src/vk_proto.h | 3 +++ 6 files changed, 26 insertions(+), 16 deletions(-) (limited to 'protocols') diff --git a/protocols/VKontakte/src/main.cpp b/protocols/VKontakte/src/main.cpp index c00df3398d..036d1f5f21 100644 --- a/protocols/VKontakte/src/main.cpp +++ b/protocols/VKontakte/src/main.cpp @@ -19,7 +19,6 @@ along with this program. If not, see . #include "version.h" CMPlugin g_plugin; -bool g_bMessageState; ///////////////////////////////////////////////////////////////////////////////////////// @@ -52,7 +51,8 @@ extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PROTOC static int OnModuleLoaded(WPARAM, LPARAM) { - g_bMessageState = ServiceExists(MS_MESSAGESTATE_UPDATE) != 0; + g_plugin.hasNewStory = ServiceExists("NewStory/RemoteRead"); + g_plugin.hasMessageState = ServiceExists(MS_MESSAGESTATE_UPDATE); return 0; } diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index 2794cbee54..13f1beba81 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -834,7 +834,7 @@ void CVkProto::ContactTypingThread(void *p) Sleep(4500); CallService(MS_PROTO_CONTACTISTYPING, hContact); - if (!g_bMessageState) { + if (!g_plugin.hasMessageState) { Sleep(1500); SetSrmmReadStatus(hContact); } @@ -865,7 +865,7 @@ int CVkProto::OnProcessSrmmEvent(WPARAM uType, LPARAM lParam) if (szProto.IsEmpty() || szProto != m_szModuleName) return 0; - if (uType == MSG_WINDOW_EVT_OPENING && !g_bMessageState) + if (uType == MSG_WINDOW_EVT_OPENING && !g_plugin.hasMessageState) SetSrmmReadStatus(pDlg->m_hContact); if (uType == MSG_WINDOW_EVT_OPENING && m_vkOptions.bLoadLastMessageOnMsgWindowsOpen && IsHystoryMessageExist(pDlg->m_hContact) != 1) { @@ -915,6 +915,22 @@ void CVkProto::MarkDialogAsRead(MCONTACT hContact) } } +void CVkProto::MarkRemoteRead(MCONTACT hContact) +{ + MEVENT hEvent = db_event_last(hContact); + + setDword(hContact, "LastMsgReadTime", time(0)); + setDword(hContact, "RemoteRead", hEvent); + + if (g_plugin.hasNewStory) + NS_NotifyRemoteRead(hContact, hEvent); + + if (g_plugin.hasMessageState) + CallService(MS_MESSAGESTATE_UPDATE, hContact, MRD_TYPE_READ); + else + SetSrmmReadStatus(hContact); +} + char* CVkProto::GetStickerId(const char *szMsg, int &iStickerId) { iStickerId = 0; diff --git a/protocols/VKontakte/src/vk.h b/protocols/VKontakte/src/vk.h index 152f77c8eb..36a1800d0a 100644 --- a/protocols/VKontakte/src/vk.h +++ b/protocols/VKontakte/src/vk.h @@ -110,7 +110,6 @@ along with this program. If not, see . struct CVkProto; extern mir_cs csInstances; -extern bool g_bMessageState; bool wlstrstr(wchar_t *_s1, wchar_t *_s2); diff --git a/protocols/VKontakte/src/vk_messages.cpp b/protocols/VKontakte/src/vk_messages.cpp index 9f3aba3329..6190be65a4 100644 --- a/protocols/VKontakte/src/vk_messages.cpp +++ b/protocols/VKontakte/src/vk_messages.cpp @@ -610,7 +610,7 @@ void CVkProto::OnReceiveDlgs(MHttpResponse *reply, AsyncHttpRequest *pReq) hContact = FindChat(iChatId); } - if (g_bMessageState) { + if (g_plugin.hasMessageState) { bool bIsOut = jnLastMessage["out"].as_bool(); bool bIsRead = (jnLastMessage["id"].as_int() <= jnConversation["in_read"].as_int()); diff --git a/protocols/VKontakte/src/vk_pollserver.cpp b/protocols/VKontakte/src/vk_pollserver.cpp index 00c0928749..52a8b92f06 100644 --- a/protocols/VKontakte/src/vk_pollserver.cpp +++ b/protocols/VKontakte/src/vk_pollserver.cpp @@ -104,11 +104,7 @@ void CVkProto::PollUpdates(const JSONNode &jnUpdates) } if (hContact != 0 && (iFlags & VKFLAG_MSGUNREAD) && !IsMessageExist(iMessageId, vkIN)) { - setDword(hContact, "LastMsgReadTime", time(0)); - if (g_bMessageState) - CallService(MS_MESSAGESTATE_UPDATE, hContact, MRD_TYPE_READ); - else - SetSrmmReadStatus(hContact); + MarkRemoteRead(hContact); if (m_vkOptions.bUserForceInvisibleOnActivity) SetInvisible(hContact); @@ -177,11 +173,7 @@ void CVkProto::PollUpdates(const JSONNode &jnUpdates) iUserId = jnChild[1].as_int(); hContact = FindUser(iUserId); if (hContact != 0) { - setDword(hContact, "LastMsgReadTime", time(0)); - if (g_bMessageState) - CallService(MS_MESSAGESTATE_UPDATE, hContact, MRD_TYPE_READ); - else - SetSrmmReadStatus(hContact); + MarkRemoteRead(hContact); if (m_vkOptions.bUserForceInvisibleOnActivity) SetInvisible(hContact); diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index d20098a08c..1cdf42e861 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -386,6 +386,7 @@ private: void __cdecl ContactTypingThread(void *p); int IsHystoryMessageExist(MCONTACT hContact); void SetSrmmReadStatus(MCONTACT hContact); + void MarkRemoteRead(MCONTACT hContact); void MarkDialogAsRead(MCONTACT hContact); void CheckUpdate(); bool IsGroupUser(MCONTACT hContact); @@ -461,5 +462,7 @@ struct CMPlugin : public ACCPROTOPLUGIN { CMPlugin(); + bool hasMessageState = false, hasNewStory = false; + int Load() override; }; -- cgit v1.2.3