summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/Facebook/src/proto.cpp1
-rw-r--r--protocols/Facebook/src/proto.h22
-rw-r--r--protocols/Facebook/src/server.cpp13
3 files changed, 27 insertions, 9 deletions
diff --git a/protocols/Facebook/src/proto.cpp b/protocols/Facebook/src/proto.cpp
index 1138300e1a..d3c1355fe3 100644
--- a/protocols/Facebook/src/proto.cpp
+++ b/protocols/Facebook/src/proto.cpp
@@ -38,6 +38,7 @@ static int CompareMessages(const COwnMessage *p1, const COwnMessage *p2)
FacebookProto::FacebookProto(const char *proto_name, const wchar_t *username) :
PROTO<FacebookProto>(proto_name, username),
+ m_impl(*this),
m_users(50, CompareUsers),
arOwnMessages(1, CompareMessages),
m_bUseBigAvatars(this, "UseBigAvatars", true),
diff --git a/protocols/Facebook/src/proto.h b/protocols/Facebook/src/proto.h
index f94d097818..58328ed310 100644
--- a/protocols/Facebook/src/proto.h
+++ b/protocols/Facebook/src/proto.h
@@ -368,6 +368,28 @@ struct COwnMessage
class FacebookProto : public PROTO<FacebookProto>
{
+ class FacebookImpl
+ {
+ friend class FacebookProto;
+
+ FacebookProto &m_proto;
+ CTimer m_heartBeat;
+
+ void OnHeartBeat(CTimer *)
+ {
+ m_proto.MqttPing();
+ }
+
+ FacebookImpl(FacebookProto &pro) :
+ m_proto(pro),
+ m_heartBeat(Miranda_GetSystemWindow(), (UINT_PTR)this)
+ {
+ m_heartBeat.OnEvent = Callback(this, &FacebookImpl::OnHeartBeat);
+ }
+ };
+
+ FacebookImpl m_impl;
+
uint8_t *doZip(size_t cbData, const void *pData, size_t &cbRes);
uint8_t *doUnzip(size_t cbData, const void *pData, size_t &cbRes);
diff --git a/protocols/Facebook/src/server.cpp b/protocols/Facebook/src/server.cpp
index f7bde04362..8f6ac2cbcb 100644
--- a/protocols/Facebook/src/server.cpp
+++ b/protocols/Facebook/src/server.cpp
@@ -31,7 +31,6 @@ void FacebookProto::ConnectionFailed()
void FacebookProto::OnLoggedIn()
{
- m_bOnline = true;
m_mid = 0;
MqttPublish("/foreground_state", "{\"foreground\":true, \"keepalive_timeout\":60}");
@@ -58,8 +57,11 @@ void FacebookProto::OnLoggedIn()
m_iUnread = n["unread_count"].as_int();
}
+ // point of no return;
ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)m_iStatus, m_iDesiredStatus);
m_iStatus = m_iDesiredStatus;
+ m_bOnline = true;
+ m_impl.m_heartBeat.Start(60000);
// connect message queue
JSONNode query;
@@ -86,6 +88,7 @@ void FacebookProto::OnLoggedOut()
{
OnShutdown();
+ m_impl.m_heartBeat.Stop();
m_bOnline = false;
setAllContactStatuses(ID_STATUS_OFFLINE);
}
@@ -220,8 +223,6 @@ LBL_Begin:
// send initial packet
MqttLogin();
- __int64 startTime = GetTickCount64();
-
while (!Miranda_IsTerminated()) {
NETLIBSELECT nls = {};
nls.hReadConns[0] = m_mqttConn;
@@ -232,12 +233,6 @@ LBL_Begin:
break;
}
- __int64 currTime = GetTickCount64();
- if (currTime - startTime > 60000) {
- startTime = currTime;
- MqttPing();
- }
-
// no data, continue waiting
if (ret == 0)
continue;