summaryrefslogtreecommitdiff
path: root/protocols/WhatsApp/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-01-26 23:21:25 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-01-26 23:21:25 +0000
commit88d6662a12f18844e5487c3d35155d3fbbff85a5 (patch)
tree2090b9d565feb3c0004c3373313cf1ebb7c33c3a /protocols/WhatsApp/src
parente64e17858c88e0b8302a34cebc02be0019422947 (diff)
fix for going offline in WhatsApp
git-svn-id: http://svn.miranda-ng.org/main/trunk@11921 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/WhatsApp/src')
-rw-r--r--protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp5
-rw-r--r--protocols/WhatsApp/src/connection.cpp14
-rw-r--r--protocols/WhatsApp/src/messages.cpp13
-rw-r--r--protocols/WhatsApp/src/proto.cpp5
4 files changed, 21 insertions, 16 deletions
diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp
index 7ae18a30d5..1abcd431dd 100644
--- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp
+++ b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp
@@ -278,7 +278,7 @@ void WAConnection::parseAck(ProtocolTreeNode *node) throw(WAException)
const string &id = node->getAttributeValue("id");
const string &ts = node->getAttributeValue("t");
- if (this->event_handler != NULL) {
+ if (cls == "message" && this->event_handler != NULL) {
FMessage msg(new Key(from, true, id));
msg.status = FMessage::STATUS_RECEIVED_BY_SERVER;
this->event_handler->onMessageStatusUpdate(&msg);
@@ -346,9 +346,10 @@ void WAConnection::parseMessage(ProtocolTreeNode *messageNode) throw (WAExceptio
if (receiptRequested)
sendSubjectReceived(from, id);
}
- else if (typeAttribute == "chat") {
+ else if (typeAttribute == "chat" || typeAttribute == "text") {
FMessage* fmessage = new FMessage();
fmessage->wants_receipt = false;
+ fmessage->timestamp = atoi(attribute_t.c_str());
bool duplicate = false;
std::vector<ProtocolTreeNode*> messageChildren(messageNode->getAllChildren());
diff --git a/protocols/WhatsApp/src/connection.cpp b/protocols/WhatsApp/src/connection.cpp
index c4ed44c7dd..1f6b6647ec 100644
--- a/protocols/WhatsApp/src/connection.cpp
+++ b/protocols/WhatsApp/src/connection.cpp
@@ -46,7 +46,6 @@ void WhatsAppProto::stayConnectedLoop(void*)
// -----------------------------
Mutex writerMutex;
- int desiredStatus;
bool error = false;
this->conn = NULL;
@@ -61,13 +60,12 @@ void WhatsAppProto::stayConnectedLoop(void*)
this->conn = NULL;
}
- desiredStatus = this->m_iDesiredStatus;
- if (desiredStatus == ID_STATUS_OFFLINE || error) {
+ if (m_iDesiredStatus == ID_STATUS_OFFLINE || error) {
debugLogA("Set status to offline");
SetAllContactStatuses(ID_STATUS_OFFLINE, true);
this->ToggleStatusMenuItems(false);
- int prevStatus = this->m_iStatus;
- this->m_iStatus = ID_STATUS_OFFLINE;
+ int prevStatus = m_iStatus;
+ m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)m_iStatus, prevStatus);
break;
}
@@ -95,11 +93,11 @@ void WhatsAppProto::stayConnectedLoop(void*)
}
m_pConnection->nick = this->nick;
m_pConnection->setVerboseId(true);
- if (desiredStatus != ID_STATUS_INVISIBLE)
+ if (m_iDesiredStatus != ID_STATUS_INVISIBLE)
m_pConnection->sendAvailableForChat();
debugLogA("Set status to online");
- this->m_iStatus = desiredStatus;
+ m_iStatus = m_iDesiredStatus;
ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)m_iStatus, ID_STATUS_CONNECTING);
this->ToggleStatusMenuItems(true);
@@ -134,7 +132,7 @@ void WhatsAppProto::sentinelLoop(void*)
int delay = MAX_SILENT_INTERVAL;
int quietInterval;
while (WaitForSingleObjectEx(update_loop_lock_, delay * 1000, true) == WAIT_TIMEOUT) {
- if (this->m_iStatus != ID_STATUS_OFFLINE && m_pConnection != NULL && this->m_iDesiredStatus == this->m_iStatus) {
+ if (m_iStatus != ID_STATUS_OFFLINE && m_pConnection != NULL && m_iDesiredStatus == m_iStatus) {
// #TODO Quiet after pong or tree read?
quietInterval = difftime(time(NULL), this->lastPongTime);
if (quietInterval >= MAX_SILENT_INTERVAL) {
diff --git a/protocols/WhatsApp/src/messages.cpp b/protocols/WhatsApp/src/messages.cpp
index 9fe33b121c..8d774a47d0 100644
--- a/protocols/WhatsApp/src/messages.cpp
+++ b/protocols/WhatsApp/src/messages.cpp
@@ -44,7 +44,7 @@ int WhatsAppProto::SendMsg(MCONTACT hContact, int flags, const char *msg)
if (jid == NULL)
return 0;
- if (m_pConnection != NULL) {
+ if (m_pConnection == NULL) {
debugLogA("No connection");
return 0;
}
@@ -56,10 +56,11 @@ int WhatsAppProto::SendMsg(MCONTACT hContact, int flags, const char *msg)
int msgId = this->m_pConnection->msg_id++;
try {
- std::string id = "msg" + Utilities::intToStr(msgId);
+ time_t now = time(NULL);
+ std::string id = Utilities::intToStr(now) + "-" + Utilities::intToStr(msgId);
FMessage fmsg(new Key((const char*)jid, true, id));
+ fmsg.timestamp = now;
fmsg.data = msg;
- fmsg.timestamp = time(NULL);
m_pConnection->sendMessage(&fmsg);
}
@@ -121,7 +122,11 @@ void WhatsAppProto::onMessageStatusUpdate(FMessage* fmsg)
return;
if (fmsg->status == FMessage::STATUS_RECEIVED_BY_SERVER) {
- int msgId = atoi(fmsg->key->id.substr(3).c_str());
+ size_t delim = fmsg->key->id.find('-');
+ if (delim == string::npos)
+ return;
+
+ int msgId = atoi(fmsg->key->id.substr(delim+1).c_str());
ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)msgId, 0);
}
}
diff --git a/protocols/WhatsApp/src/proto.cpp b/protocols/WhatsApp/src/proto.cpp
index 1a423cc0f8..255417a277 100644
--- a/protocols/WhatsApp/src/proto.cpp
+++ b/protocols/WhatsApp/src/proto.cpp
@@ -30,10 +30,11 @@ WhatsAppProto::WhatsAppProto(const char* proto_name, const TCHAR* username) :
// Create standard network connection
TCHAR descr[512];
+ mir_sntprintf(descr, SIZEOF(descr), TranslateT("%s server connection"), m_tszUserName);
+
NETLIBUSER nlu = { sizeof(nlu) };
nlu.flags = NUF_INCOMING | NUF_OUTGOING | NUF_HTTPCONNS | NUF_TCHAR;
nlu.szSettingsModule = m_szModuleName;
- mir_sntprintf(descr, SIZEOF(descr), TranslateT("%s server connection"), m_tszUserName);
nlu.ptszDescriptiveName = descr;
m_hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
if (m_hNetlibUser == NULL)
@@ -74,7 +75,7 @@ DWORD_PTR WhatsAppProto::GetCaps(int type, MCONTACT hContact)
case PFLAGNUM_3:
return 0;
case PFLAGNUM_4:
- return PF4_NOCUSTOMAUTH | PF4_IMSENDUTF | PF4_FORCEADDED | PF4_NOAUTHDENYREASON | PF4_IMSENDOFFLINE | PF4_NOAUTHDENYREASON | PF4_SUPPORTTYPING | PF4_AVATARS;
+ return PF4_NOCUSTOMAUTH | PF4_IMSENDUTF | PF4_FORCEADDED | PF4_NOAUTHDENYREASON | PF4_IMSENDOFFLINE | PF4_SUPPORTTYPING | PF4_AVATARS;
case PFLAGNUM_5:
return 0;
case PFLAG_MAXLENOFMESSAGE: