summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/ICQ-WIM/src/main.cpp10
-rw-r--r--protocols/ICQ-WIM/src/proto.cpp20
-rw-r--r--protocols/ICQ-WIM/src/proto.h29
-rw-r--r--protocols/ICQ-WIM/src/server.cpp10
-rw-r--r--protocols/ICQ-WIM/src/stdafx.h1
5 files changed, 38 insertions, 32 deletions
diff --git a/protocols/ICQ-WIM/src/main.cpp b/protocols/ICQ-WIM/src/main.cpp
index 9c66166a60..0cf2cd2674 100644
--- a/protocols/ICQ-WIM/src/main.cpp
+++ b/protocols/ICQ-WIM/src/main.cpp
@@ -22,8 +22,6 @@
bool g_bSecureIM, g_bMessageState;
-HWND g_hwndHeartbeat;
-
IconItem iconList[] =
{
{ LPGEN("E-mail"), "icq_email", IDI_INBOX },
@@ -95,8 +93,6 @@ int CMPlugin::Load()
// register the second instance of this plugin as MRA
g_pluginMra.Register();
- g_hwndHeartbeat = CreateWindowEx(0, L"STATIC", nullptr, 0, 0, 0, 0, 0, nullptr, nullptr, nullptr, nullptr);
-
registerIcon("Protocols/ICQ", iconList, "ICQ");
HookEvent(ME_SYSTEM_MODULELOAD, ModuleLoad);
@@ -104,9 +100,3 @@ int CMPlugin::Load()
HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
return 0;
}
-
-int CMPlugin::Unload()
-{
- DestroyWindow(g_hwndHeartbeat);
- return 0;
-}
diff --git a/protocols/ICQ-WIM/src/proto.cpp b/protocols/ICQ-WIM/src/proto.cpp
index 786b29e8d8..cfc28506f9 100644
--- a/protocols/ICQ-WIM/src/proto.cpp
+++ b/protocols/ICQ-WIM/src/proto.cpp
@@ -40,6 +40,7 @@ static int CompareCache(const IcqCacheItem *p1, const IcqCacheItem *p2)
CIcqProto::CIcqProto(const char *aProtoName, const wchar_t *aUserName) :
PROTO<CIcqProto>(aProtoName, aUserName),
+ m_impl(*this),
m_arHttpQueue(10),
m_arOwnIds(1, PtrKeySortT),
m_arCache(20, &CompareCache),
@@ -292,24 +293,21 @@ INT_PTR CIcqProto::GotoInbox(WPARAM, LPARAM)
/////////////////////////////////////////////////////////////////////////////////////////
-void CIcqProto::MarkReadTimerProc(HWND hwnd, UINT, UINT_PTR id, DWORD)
+void CIcqProto::SendMarkRead()
{
- CIcqProto *ppro = (CIcqProto*)id;
-
- mir_cslock lck(ppro->m_csMarkReadQueue);
- while (ppro->m_arMarkReadQueue.getCount()) {
- IcqCacheItem *pUser = ppro->m_arMarkReadQueue[0];
+ mir_cslock lck(m_csMarkReadQueue);
+ while (m_arMarkReadQueue.getCount()) {
+ IcqCacheItem *pUser = m_arMarkReadQueue[0];
auto *pReq = new AsyncHttpRequest(CONN_RAPI, REQUEST_POST, ICQ_ROBUST_SERVER);
JSONNode request, params; params.set_name("params");
- params << WCHAR_PARAM("sn", ppro->GetUserId(pUser->m_hContact)) << INT64_PARAM("lastRead", ppro->getId(pUser->m_hContact, DB_KEY_LASTMSGID));
+ params << WCHAR_PARAM("sn", GetUserId(pUser->m_hContact)) << INT64_PARAM("lastRead", getId(pUser->m_hContact, DB_KEY_LASTMSGID));
request << CHAR_PARAM("method", "setDlgStateWim") << CHAR_PARAM("reqId", pReq->m_reqId) << params;
pReq->m_szParam = ptrW(json_write(&request));
- ppro->Push(pReq);
+ Push(pReq);
- ppro->m_arMarkReadQueue.remove(0);
+ m_arMarkReadQueue.remove(0);
}
- KillTimer(hwnd, id);
}
int CIcqProto::OnDbEventRead(WPARAM, LPARAM hDbEvent)
@@ -324,7 +322,7 @@ int CIcqProto::OnDbEventRead(WPARAM, LPARAM hDbEvent)
return 0;
if (m_bOnline) {
- SetTimer(g_hwndHeartbeat, UINT_PTR(this), 200, &CIcqProto::MarkReadTimerProc);
+ m_impl.m_markRead.Start(200);
IcqCacheItem *pCache = FindContactByUIN(GetUserId(hContact));
if (pCache) {
diff --git a/protocols/ICQ-WIM/src/proto.h b/protocols/ICQ-WIM/src/proto.h
index 6d528f615b..e4cc21cd08 100644
--- a/protocols/ICQ-WIM/src/proto.h
+++ b/protocols/ICQ-WIM/src/proto.h
@@ -177,6 +177,32 @@ struct IcqFileTransfer : public MZeroedObject
class CIcqProto : public PROTO<CIcqProto>
{
+ class CIcqProtoImpl
+ {
+ friend class CIcqProto;
+
+ CIcqProto &m_proto;
+ CTimer m_heartBeat, m_markRead;
+
+ void OnHeartBeat(CTimer *) {
+ m_proto.CheckStatus();
+ }
+
+ void OnMarkRead(CTimer *pTimer) {
+ m_proto.SendMarkRead();
+ pTimer->Stop();
+ }
+
+ CIcqProtoImpl(CIcqProto &pro) :
+ m_proto(pro),
+ m_markRead(Miranda_GetSystemWindow(), UINT_PTR(this)),
+ m_heartBeat(Miranda_GetSystemWindow(), UINT_PTR(this) + 1)
+ {
+ m_markRead.OnEvent = Callback(this, &CIcqProtoImpl::OnMarkRead);
+ m_heartBeat.OnEvent = Callback(this, &CIcqProtoImpl::OnHeartBeat);
+ }
+ } m_impl;
+
friend struct CIcqRegistrationDlg;
friend class CGroupchatInviteDlg;
friend class CEditIgnoreListDlg;
@@ -215,7 +241,7 @@ class CIcqProto : public PROTO<CIcqProto>
mir_cs m_csMarkReadQueue;
LIST<IcqCacheItem> m_arMarkReadQueue;
- static void CALLBACK MarkReadTimerProc(HWND hwnd, UINT, UINT_PTR id, DWORD);
+ void SendMarkRead();
AsyncHttpRequest* UserInfoRequest(MCONTACT);
@@ -403,7 +429,6 @@ struct CMPlugin : public ACCPROTOPLUGIN<CIcqProto>
CMPlugin();
int Load() override;
- int Unload() override;
};
#endif
diff --git a/protocols/ICQ-WIM/src/server.cpp b/protocols/ICQ-WIM/src/server.cpp
index 31829902e2..4bf8ab7385 100644
--- a/protocols/ICQ-WIM/src/server.cpp
+++ b/protocols/ICQ-WIM/src/server.cpp
@@ -182,18 +182,12 @@ void CIcqProto::MoveContactToGroup(MCONTACT hContact, const wchar_t *pwszGroup,
/////////////////////////////////////////////////////////////////////////////////////////
-static void CALLBACK CheckStatusTimerProc(HWND, UINT, UINT_PTR id, DWORD)
-{
- CIcqProto *ppro = (CIcqProto*)(id - 1);
- ppro->CheckStatus();
-}
-
void CIcqProto::OnLoggedIn()
{
debugLogA("CIcqProto::OnLoggedIn");
m_bOnline = true;
+ m_impl.m_heartBeat.Start(1000);
- ::SetTimer(g_hwndHeartbeat, UINT_PTR(this)+1, 1000, CheckStatusTimerProc);
for (auto &it : m_arCache)
it->m_timer1 = it->m_timer2 = 0;
@@ -208,8 +202,8 @@ void CIcqProto::OnLoggedOut()
{
debugLogA("CIcqProto::OnLoggedOut");
m_bOnline = false;
+ m_impl.m_heartBeat.Stop();
- ::KillTimer(g_hwndHeartbeat, UINT_PTR(this)+1);
for (auto &it : m_arCache)
it->m_timer1 = it->m_timer2 = 0;
diff --git a/protocols/ICQ-WIM/src/stdafx.h b/protocols/ICQ-WIM/src/stdafx.h
index c9baaa8286..66fe049022 100644
--- a/protocols/ICQ-WIM/src/stdafx.h
+++ b/protocols/ICQ-WIM/src/stdafx.h
@@ -104,6 +104,5 @@ void RefreshGroups(void);
int StatusFromString(const CMStringW&);
char* time2text(time_t time);
-extern HWND g_hwndHeartbeat;
extern bool g_bSecureIM, g_bMessageState;
extern IconItem iconList[];