summaryrefslogtreecommitdiff
path: root/protocols/WhatsApp/src/proto.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-01-26 00:17:21 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-01-26 00:17:21 +0000
commit0072a0880c077fc0a21fd57214e6c5bf8497402a (patch)
treea4c4a2667fbca02b195ebc5c268752ab3a407aea /protocols/WhatsApp/src/proto.cpp
parentd32c7402ad63175d48579a2779d47800a2dd74c2 (diff)
first version that logs in
git-svn-id: http://svn.miranda-ng.org/main/trunk@11913 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/WhatsApp/src/proto.cpp')
-rw-r--r--protocols/WhatsApp/src/proto.cpp41
1 files changed, 33 insertions, 8 deletions
diff --git a/protocols/WhatsApp/src/proto.cpp b/protocols/WhatsApp/src/proto.cpp
index d4eda7f973..e889854871 100644
--- a/protocols/WhatsApp/src/proto.cpp
+++ b/protocols/WhatsApp/src/proto.cpp
@@ -86,6 +86,10 @@ DWORD_PTR WhatsAppProto::GetCaps(int type, MCONTACT hContact)
int WhatsAppProto::SetStatus(int new_status)
{
+ if (m_iDesiredStatus == new_status)
+ return 0;
+
+ int oldStatus = m_iStatus;
debugLogA("===== Beginning SetStatus process");
// Routing statuses not supported by WhatsApp
@@ -106,17 +110,38 @@ int WhatsAppProto::SetStatus(int new_status)
break;
}
- if (m_iStatus == ID_STATUS_CONNECTING) {
- debugLogA("===== Status is connecting, no change");
- return 0;
- }
+ if (m_iDesiredStatus == ID_STATUS_OFFLINE) {
+ if (this->conn != NULL) {
+ SetEvent(update_loop_lock_);
+ this->conn->forceShutdown();
+ debugLogA("Forced shutdown");
+ }
- if (m_iStatus == m_iDesiredStatus) {
- debugLogA("===== Statuses are same, no change");
- return 0;
+ m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
+ ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
}
+ else if (this->conn == NULL && !(m_iStatus >= ID_STATUS_CONNECTING && m_iStatus < ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES)) {
+ m_iStatus = ID_STATUS_CONNECTING;
+ ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
- ForkThread(&WhatsAppProto::ChangeStatus, this);
+ ResetEvent(update_loop_lock_);
+ ForkThread(&WhatsAppProto::sentinelLoop, this);
+ ForkThread(&WhatsAppProto::stayConnectedLoop, this);
+ }
+ else if (this->connection != NULL) {
+ if (m_iDesiredStatus == ID_STATUS_ONLINE) {
+ this->connection->sendAvailableForChat();
+ m_iStatus = ID_STATUS_ONLINE;
+ ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
+ }
+ else if (m_iStatus == ID_STATUS_ONLINE && m_iDesiredStatus == ID_STATUS_INVISIBLE) {
+ this->connection->sendClose();
+ m_iStatus = ID_STATUS_INVISIBLE;
+ SetAllContactStatuses(ID_STATUS_OFFLINE, true);
+ ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
+ }
+ }
+ else ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
return 0;
}