Index: contacts.cpp =================================================================== --- contacts.cpp (revision 15326) +++ contacts.cpp (working copy) @@ -104,43 +104,44 @@ CODE_BLOCK_CATCH_ALL } -void WhatsAppProto::onAvailable(const std::string ¶mString, bool paramBoolean) +void WhatsAppProto::onAvailable(const std::string ¶mString, bool paramBoolean, int lastSeenTime) { MCONTACT hContact = AddToContactList(paramString); if (hContact != NULL) { - if (paramBoolean) + if (paramBoolean) { setWord(hContact, "Status", ID_STATUS_ONLINE); + setDword(hContact, WHATSAPP_KEY_LAST_SEEN, time(NULL)); + } else { setWord(hContact, "Status", ID_STATUS_OFFLINE); - UpdateStatusMsg(hContact); + setDword(hContact, WHATSAPP_KEY_LAST_SEEN, lastSeenTime); } + UpdateStatusMsg(hContact); } - - setDword(hContact, WHATSAPP_KEY_LAST_SEEN, time(NULL)); - UpdateStatusMsg(hContact); } -void WhatsAppProto::onLastSeen(const std::string ¶mString1, int paramInt, const string ¶mString2) -{ - MCONTACT hContact = AddToContactList(paramString1); - setDword(hContact, WHATSAPP_KEY_LAST_SEEN, time(NULL) - paramInt); - - UpdateStatusMsg(hContact); -} - void WhatsAppProto::UpdateStatusMsg(MCONTACT hContact) { std::wstringstream ss; int lastSeen = getDword(hContact, WHATSAPP_KEY_LAST_SEEN, -1); - if (lastSeen != -1) { + // TODO define these somewhere + // lastSeen -1: no time available in DB + // lastSeen -2: last seen denied by user + // lastSeen >= 0: timestamp + if (lastSeen >= 0) { time_t ts = lastSeen; TCHAR stzLastSeen[MAX_PATH]; _tcsftime(stzLastSeen, _countof(stzLastSeen), TranslateT("Last seen on %x at %X"), localtime(&ts)); ss << stzLastSeen; } + else if (lastSeen == -2) { + ss << L"Last seen denied"; + } db_set_ws(hContact, "CList", "StatusMsg", ss.str().c_str()); + + } void WhatsAppProto::onContactChanged(const std::string &jid, bool added) Index: proto.cpp =================================================================== --- proto.cpp (revision 15326) +++ proto.cpp (working copy) @@ -177,7 +177,6 @@ if (!(flags & PALF_TEMPORARY)) db_unset(hContact, "CList", "NotOnList"); - m_pConnection->sendQueryLastOnline(jid.c_str()); m_pConnection->sendPresenceSubscriptionRequest(jid.c_str()); return hContact; } @@ -320,7 +319,6 @@ { ptrA jid(getStringA(hContact, WHATSAPP_KEY_ID)); if (jid && isOnline()) { - m_pConnection->sendQueryLastOnline((char*)jid); m_pConnection->sendGetPicture((char*)jid, "image"); m_pConnection->sendPresenceSubscriptionRequest((char*)jid); } @@ -335,7 +333,6 @@ ptrA jid(getStringA(hContact, WHATSAPP_KEY_ID)); if (jid) { - m_pConnection->sendQueryLastOnline((char*)jid); m_pConnection->sendPresenceSubscriptionRequest((char*)jid); } } Index: proto.h =================================================================== --- proto.h (revision 15326) +++ proto.h (working copy) @@ -165,9 +165,8 @@ virtual void onMessageError(const FMessage &message, int paramInt) { ; } virtual void onPing(const std::string &id) throw (WAException); virtual void onPingResponseReceived() { } - virtual void onAvailable(const std::string ¶mString, bool paramBoolean); + virtual void onAvailable(const std::string ¶mString, bool paramBoolean, int lastSeenTime); virtual void onClientConfigReceived(const std::string ¶mString) { } - virtual void onLastSeen(const std::string ¶mString1, int paramInt, const std::string ¶mString2); virtual void onIsTyping(const std::string ¶mString, bool paramBoolean); virtual void onAccountChange(int paramInt, time_t expire_date) { } virtual void onPrivacyBlockListAdd(const std::string ¶mString) { } Index: WhatsAPI++/WAConnection.cpp =================================================================== --- WhatsAPI++/WAConnection.cpp (revision 15326) +++ WhatsAPI++/WAConnection.cpp (working copy) @@ -586,10 +586,18 @@ if (m_pEventHandler != NULL) { const string &type = node->getAttributeValue("type"); - if (type == "unavailable") - m_pEventHandler->onAvailable(from, false); + if (type == "unavailable") { + const string &lastSeen = node->getAttributeValue("last"); + int time; + if (lastSeen == "deny") + time = -2; + else + time = atoi(lastSeen.c_str()); + + m_pEventHandler->onAvailable(from, false, time); + } else if (type == "available" || type == "") - m_pEventHandler->onAvailable(from, true); + m_pEventHandler->onAvailable(from, true,-1); } } @@ -962,18 +970,6 @@ out.write(ProtocolTreeNode("presence") << XATTR("type", "subscribe") << XATTR("to", to)); } -void WAConnection::sendQueryLastOnline(const std::string &jid) throw (WAException) -{ - if (jid == "Server@s.whatsapp.net") // to avoid error 405 - return; - - std::string id = makeId("iq_"); - this->pending_server_requests[id] = new IqResultQueryLastOnlineHandler(this); - - out.write(ProtocolTreeNode("iq", new ProtocolTreeNode("query")) - << XATTR("id", id) << XATTR("type", "get") << XATTR("to", jid) << XATTR("xmlns", "jabber:iq:last")); -} - void WAConnection::sendSetPicture(const char *jid, std::vector* data, std::vector* preview) throw (WAException) { std::string id = this->makeId("set_photo_"); Index: WhatsAPI++/WAConnection.h =================================================================== --- WhatsAPI++/WAConnection.h (revision 15326) +++ WhatsAPI++/WAConnection.h (working copy) @@ -36,9 +36,8 @@ virtual void onMessageError(const FMessage &message, int paramInt) = 0; virtual void onPing(const std::string ¶mString) throw (WAException) = 0; virtual void onPingResponseReceived() = 0; - virtual void onAvailable(const std::string ¶mString, bool paramBoolean) = 0; + virtual void onAvailable(const std::string ¶mString, bool paramBoolean, int lastSeenTime) = 0; virtual void onClientConfigReceived(const std::string ¶mString) = 0; - virtual void onLastSeen(const std::string ¶mString1, int paramInt, const string ¶mString2) = 0; virtual void onIsTyping(const std::string ¶mString, bool paramBoolean) = 0; virtual void onAccountChange(int paramInt, time_t paramLong) = 0; virtual void onPrivacyBlockListAdd(const std::string ¶mString) = 0; @@ -219,20 +218,6 @@ } }; - class IqResultQueryLastOnlineHandler: public IqResultHandler { - public: - IqResultQueryLastOnlineHandler(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode* node, const std::string &from) throw (WAException) { - ProtocolTreeNode* firstChild = node->getChild(0); - ProtocolTreeNode::require(firstChild, "query"); - const string &seconds = firstChild->getAttributeValue("seconds"); - const string &status = firstChild->getDataAsString(); - if (!seconds.empty() && !from.empty()) - if (this->con->m_pEventHandler != NULL) - this->con->m_pEventHandler->onLastSeen(from, atoi(seconds.c_str()), status); - } - }; - class IqResultGetPhotoHandler: public IqResultHandler { private: std::string jid; @@ -399,7 +384,6 @@ void sendAck(ProtocolTreeNode * node, const char *classType); void sendPing() throw(WAException); - void sendQueryLastOnline(const std::string &jid) throw (WAException); void sendPong(const std::string &id) throw(WAException); void sendComposing(const std::string &to) throw(WAException); void sendActive() throw(WAException);