summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-10-21 18:17:12 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-10-21 18:17:12 +0300
commitee868b7339322e7222cb62741f397d97180c96cb (patch)
tree6e19aa7aaea69cd9e39e4896a29cc495514a4617 /protocols
parentf81db767c1caeb7749faa95e509c6c6d4b0c940d (diff)
VK: remote read support for NewStory
Diffstat (limited to 'protocols')
-rw-r--r--protocols/VKontakte/src/main.cpp4
-rw-r--r--protocols/VKontakte/src/misc.cpp20
-rw-r--r--protocols/VKontakte/src/vk.h1
-rw-r--r--protocols/VKontakte/src/vk_messages.cpp2
-rw-r--r--protocols/VKontakte/src/vk_pollserver.cpp12
-rw-r--r--protocols/VKontakte/src/vk_proto.h3
6 files changed, 26 insertions, 16 deletions
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 <http://www.gnu.org/licenses/>.
#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 <http://www.gnu.org/licenses/>.
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<CVkProto>
{
CMPlugin();
+ bool hasMessageState = false, hasNewStory = false;
+
int Load() override;
};