From f5040450314c4b4ab23ab3b93ab93e0dcb2ebba8 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 27 Jan 2015 22:01:19 +0000 Subject: WhatsApp: - fix for the ping thread; - fix for message notifications git-svn-id: http://svn.miranda-ng.org/main/trunk@11932 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp | 5 ++++- protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp | 8 ++------ protocols/WhatsApp/src/connection.cpp | 8 ++------ protocols/WhatsApp/src/constants.h | 2 +- protocols/WhatsApp/src/messages.cpp | 2 +- protocols/WhatsApp/src/proto.cpp | 4 ++-- 6 files changed, 12 insertions(+), 17 deletions(-) (limited to 'protocols/WhatsApp/src') diff --git a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp index e9b6377879..0dea74a6ac 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp @@ -266,7 +266,10 @@ void BinTreeNodeWriter::write(const ProtocolTreeNode &node, bool needsFlush) this->realOut->log(tmp.c_str()); } #endif - writeInternal(node); + if (node.tag.empty()) + this->out->write(0); + else + writeInternal(node); flushBuffer(needsFlush); } catch (exception& ex) { diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp index c7ce6648c8..961c3ea544 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp @@ -778,7 +778,7 @@ void WAConnection::sendMessageReceived(FMessage* message) throw(WAException) << XATTR("xmlns", "urn:xmpp:receipts"); this->out->write(ProtocolTreeNode("message", receivedNode) - << XATTR("to", message->key->remote_jid) << XATTR("type", "chat") << XATTR("id", message->key->id)); + << XATTR("to", message->key->remote_jid) << XATTR("type", "text") << XATTR("id", message->key->id)); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -798,11 +798,7 @@ void WAConnection::sendPaused(const std::string& to) throw(WAException) void WAConnection::sendPing() throw(WAException) { - std::string id = makeId("ping_"); - this->pending_server_requests[id] = new IqResultPingHandler(this); - - ProtocolTreeNode *pingNode = new ProtocolTreeNode("ping") << XATTR("xmlns", "w:p"); - this->out->write(ProtocolTreeNode("iq", pingNode) << XATTR("id", id) << XATTR("type", "get")); + this->out->write(ProtocolTreeNode("")); } void WAConnection::sendPong(const std::string& id) throw(WAException) diff --git a/protocols/WhatsApp/src/connection.cpp b/protocols/WhatsApp/src/connection.cpp index 1f6b6647ec..e53d7848e8 100644 --- a/protocols/WhatsApp/src/connection.cpp +++ b/protocols/WhatsApp/src/connection.cpp @@ -129,12 +129,10 @@ void WhatsAppProto::stayConnectedLoop(void*) void WhatsAppProto::sentinelLoop(void*) { - int delay = MAX_SILENT_INTERVAL; - int quietInterval; - while (WaitForSingleObjectEx(update_loop_lock_, delay * 1000, true) == WAIT_TIMEOUT) { + while (WaitForSingleObjectEx(update_loop_lock_, 1000, true) == WAIT_TIMEOUT) { 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); + int quietInterval = difftime(time(NULL), this->lastPongTime); if (quietInterval >= MAX_SILENT_INTERVAL) { try { debugLogA("send ping"); @@ -145,9 +143,7 @@ void WhatsAppProto::sentinelLoop(void*) debugLogA("Exception: %s", e.what()); } } - else delay = MAX_SILENT_INTERVAL - quietInterval; } - else delay = MAX_SILENT_INTERVAL; } ResetEvent(update_loop_lock_); debugLogA("Exiting sentinel loop"); diff --git a/protocols/WhatsApp/src/constants.h b/protocols/WhatsApp/src/constants.h index ccb9c9a332..ade54cd5e3 100644 --- a/protocols/WhatsApp/src/constants.h +++ b/protocols/WhatsApp/src/constants.h @@ -47,7 +47,7 @@ #define WHATSAPP_RECV_MESSAGE 1 #define WHATSAPP_SEND_MESSAGE 2 -#define MAX_SILENT_INTERVAL 210 +#define MAX_SILENT_INTERVAL 55 // Event flags #define WHATSAPP_EVENT_CLIENT 0x10000000 // WhatsApp error or info message diff --git a/protocols/WhatsApp/src/messages.cpp b/protocols/WhatsApp/src/messages.cpp index af077934d0..b359616b89 100644 --- a/protocols/WhatsApp/src/messages.cpp +++ b/protocols/WhatsApp/src/messages.cpp @@ -32,7 +32,7 @@ void WhatsAppProto::onMessageForMe(FMessage* paramFMessage, bool paramBoolean) PROTORECVEVENT recv = { 0 }; recv.flags = PREF_UTF; recv.szMessage = const_cast(msg->c_str()); - recv.timestamp = paramFMessage->timestamp; //time(NULL); + recv.timestamp = paramFMessage->timestamp; ProtoChainRecvMsg(hContact, &recv); m_pConnection->sendMessageReceived(paramFMessage); diff --git a/protocols/WhatsApp/src/proto.cpp b/protocols/WhatsApp/src/proto.cpp index 76197975d1..cd251762c3 100644 --- a/protocols/WhatsApp/src/proto.cpp +++ b/protocols/WhatsApp/src/proto.cpp @@ -129,8 +129,8 @@ int WhatsAppProto::SetStatus(int new_status) ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); ResetEvent(update_loop_lock_); - ForkThread(&WhatsAppProto::sentinelLoop, this); - ForkThread(&WhatsAppProto::stayConnectedLoop, this); + ForkThread(&WhatsAppProto::sentinelLoop, 0); + ForkThread(&WhatsAppProto::stayConnectedLoop, 0); } else if (m_pConnection != NULL) { if (m_iDesiredStatus == ID_STATUS_ONLINE) { -- cgit v1.2.3