From db8d126a7b973b38c52f646748c866ba9fe32eb3 Mon Sep 17 00:00:00 2001
From: George Hazan <ghazan@miranda.im>
Date: Thu, 17 Jan 2019 18:27:16 +0300
Subject: related to #1773 - messageState support for ICQ-WIM

---
 protocols/ICQ-WIM/src/main.cpp   |  5 +++--
 protocols/ICQ-WIM/src/server.cpp | 17 +++++++++++++++--
 protocols/ICQ-WIM/src/stdafx.h   |  4 +++-
 3 files changed, 21 insertions(+), 5 deletions(-)

(limited to 'protocols/ICQ-WIM')

diff --git a/protocols/ICQ-WIM/src/main.cpp b/protocols/ICQ-WIM/src/main.cpp
index 0f1888952d..3de14ce81f 100644
--- a/protocols/ICQ-WIM/src/main.cpp
+++ b/protocols/ICQ-WIM/src/main.cpp
@@ -20,7 +20,7 @@
 
 #include "stdafx.h"
 
-bool g_bPopupService;
+bool g_bPopupService, g_bMessageState;
 
 HWND g_hwndHeartbeat;
 
@@ -57,6 +57,7 @@ CMPlugin g_plugin;
 int ModuleLoad(WPARAM, LPARAM)
 {
 	g_bPopupService = ServiceExists(MS_POPUP_ADDPOPUPT);
+	g_bMessageState = ServiceExists(MS_MESSAGESTATE_UPDATE);
 	return 0;
 }
 
@@ -66,7 +67,7 @@ int CMPlugin::Load()
 
 	HookEvent(ME_SYSTEM_MODULELOAD, ModuleLoad);
 	HookEvent(ME_SYSTEM_MODULEUNLOAD, ModuleLoad);
-	ModuleLoad(0, 0);
+	HookEvent(ME_SYSTEM_MODULESLOADED, ModuleLoad);
 	return 0;
 };
 
diff --git a/protocols/ICQ-WIM/src/server.cpp b/protocols/ICQ-WIM/src/server.cpp
index d77daf4075..73676491e2 100644
--- a/protocols/ICQ-WIM/src/server.cpp
+++ b/protocols/ICQ-WIM/src/server.cpp
@@ -755,7 +755,14 @@ void CIcqProto::ProcessHistData(const JSONNode &ev)
 			else LoadChatInfo(si);
 		}
 	}
-	else hContact = CreateContact(_wtol(wszId), true);
+	else {
+		hContact = CreateContact(_wtol(wszId), true);
+
+		if (g_bMessageState) {
+			MessageReadData data(time(0), MRD_TYPE_READTIME);
+			CallService(MS_MESSAGESTATE_UPDATE, hContact, (LPARAM)&data);
+		}
+	}
 		
 	__int64 lastMsgId = getId(hContact, DB_KEY_LASTMSGID);
 	__int64 srvLastId = _wtoi64(ev["lastMsgId"].as_mstring());
@@ -782,8 +789,14 @@ void CIcqProto::ProcessImState(const JSONNode &ev)
 		CMStringA reqId(it["sendReqId"].as_mstring());
 		CMStringA msgId(it["histMsgId"].as_mstring());
 		MCONTACT hContact = CheckOwnMessage(reqId, msgId, false);
-		if (hContact)
+		if (hContact) {
 			CheckLastId(hContact, ev);
+
+			if (g_bMessageState) {
+				MessageReadData data(it["ts"].as_int(), MRD_TYPE_MESSAGETIME);
+				CallService(MS_MESSAGESTATE_UPDATE, hContact, (LPARAM)&data);
+			}
+		}
 	}
 }
 
diff --git a/protocols/ICQ-WIM/src/stdafx.h b/protocols/ICQ-WIM/src/stdafx.h
index 929854990c..8351f37ef6 100644
--- a/protocols/ICQ-WIM/src/stdafx.h
+++ b/protocols/ICQ-WIM/src/stdafx.h
@@ -54,6 +54,7 @@
 #include <m_json.h>
 #include <m_langpack.h>
 #include <m_message.h>
+#include <m_messagestate.h>
 #include <m_netlib.h>
 #include <m_protocols.h>
 #include <m_protosvc.h>
@@ -92,4 +93,5 @@ bool IsChat(const CMStringW &aimid);
 
 int StatusFromString(const CMStringW&);
 
-extern HWND g_hwndHeartbeat;
\ No newline at end of file
+extern HWND g_hwndHeartbeat;
+extern bool g_bMessageState;
-- 
cgit v1.2.3