diff options
author | Tobias Weimer <wishmaster51@googlemail.com> | 2015-09-13 14:32:53 +0000 |
---|---|---|
committer | Tobias Weimer <wishmaster51@googlemail.com> | 2015-09-13 14:32:53 +0000 |
commit | cf0be00671d56bb18118e1491e7c1f0e131e7b3d (patch) | |
tree | 407d1760615f4cf22a4e664f242ae045a4cf8408 /protocols/WhatsApp/src | |
parent | 6f20ee4beb6b840ed81489358bca01ed41a0ea56 (diff) |
Patch by Cassio:
Another patch, which fixes last seen timestamps/presence due to a change in WA protocol:
There is no longer a last seen request/response as this info is now received within the presence response.
git-svn-id: http://svn.miranda-ng.org/main/trunk@15345 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/WhatsApp/src')
-rw-r--r-- | protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp | 18 | ||||
-rw-r--r-- | protocols/WhatsApp/src/WhatsAPI++/WAConnection.h | 18 | ||||
-rw-r--r-- | protocols/WhatsApp/src/contacts.cpp | 29 | ||||
-rw-r--r-- | protocols/WhatsApp/src/proto.cpp | 3 | ||||
-rw-r--r-- | protocols/WhatsApp/src/proto.h | 3 |
5 files changed, 20 insertions, 51 deletions
diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp index c271a83be2..56c86c6806 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp @@ -586,8 +586,10 @@ void WAConnection::parsePresense(ProtocolTreeNode *node) throw(WAException) 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");
+ m_pEventHandler->onAvailable(from, false, (lastSeen == "deny") ? -2 : atoi(lastSeen.c_str()));
+ }
else if (type == "available" || type == "")
m_pEventHandler->onAvailable(from, true);
}
@@ -962,18 +964,6 @@ void WAConnection::sendPresenceSubscriptionRequest(const std::string &to) throw( 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<unsigned char>* data, std::vector<unsigned char>* preview) throw (WAException)
{
std::string id = this->makeId("set_photo_");
diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h index a1a366c13e..5b6970df60 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h +++ b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h @@ -36,9 +36,8 @@ public: 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 = -1) = 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 WAConnection }
};
- 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 @@ public: 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);
diff --git a/protocols/WhatsApp/src/contacts.cpp b/protocols/WhatsApp/src/contacts.cpp index 2d94f0228b..67f9a9a2aa 100644 --- a/protocols/WhatsApp/src/contacts.cpp +++ b/protocols/WhatsApp/src/contacts.cpp @@ -104,28 +104,20 @@ void WhatsAppProto::ProcessBuddyList(void*) 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)
@@ -133,12 +125,19 @@ 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 << TranslateT("Last seen denied");
+ }
db_set_ws(hContact, "CList", "StatusMsg", ss.str().c_str());
}
diff --git a/protocols/WhatsApp/src/proto.cpp b/protocols/WhatsApp/src/proto.cpp index a5384be1c6..0db6f3fa84 100644 --- a/protocols/WhatsApp/src/proto.cpp +++ b/protocols/WhatsApp/src/proto.cpp @@ -177,7 +177,6 @@ MCONTACT WhatsAppProto::AddToList(int flags, PROTOSEARCHRESULT *psr) 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 @@ int WhatsAppProto::OnUserInfo(WPARAM, LPARAM hContact) {
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 @@ void WhatsAppProto::RequestFriendship(MCONTACT hContact) ptrA jid(getStringA(hContact, WHATSAPP_KEY_ID));
if (jid) {
- m_pConnection->sendQueryLastOnline((char*)jid);
m_pConnection->sendPresenceSubscriptionRequest((char*)jid);
}
}
diff --git a/protocols/WhatsApp/src/proto.h b/protocols/WhatsApp/src/proto.h index 0f7000fc5c..7e800cf21c 100644 --- a/protocols/WhatsApp/src/proto.h +++ b/protocols/WhatsApp/src/proto.h @@ -165,9 +165,8 @@ protected: 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) { }
|