summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorTobias Weimer <wishmaster51@googlemail.com>2015-09-14 18:56:11 +0000
committerTobias Weimer <wishmaster51@googlemail.com>2015-09-14 18:56:11 +0000
commit25f87650dab37f5a7380ae2121c7529cb3ac801a (patch)
tree377f4ba9fd4d3528aeb05414157948c5abaf376f /protocols
parenta8c76fb1f7113f18fda981ae885066d04619571f (diff)
WhatsApp: Fixed reading/storing tiome in database
patch by Cassio: It should also now display the following in the contact list: "Last online TIMESTAMP"; When a user is online currently "Denied: last online TIMESTAMP"; When the user is offline and has blocked "last seen". The time the user was last online simultaneously is used "Last seen TIMESTAMP"; When a user is offline but "last seen" info is available. git-svn-id: http://svn.miranda-ng.org/main/trunk@15352 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r--protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp2
-rw-r--r--protocols/WhatsApp/src/WhatsAPI++/WAConnection.h2
-rw-r--r--protocols/WhatsApp/src/contacts.cpp29
-rw-r--r--protocols/WhatsApp/src/db.h1
-rw-r--r--protocols/WhatsApp/src/proto.h2
5 files changed, 20 insertions, 16 deletions
diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp
index 56c86c6806..524bb80f2a 100644
--- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp
+++ b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp
@@ -588,7 +588,7 @@ void WAConnection::parsePresense(ProtocolTreeNode *node) throw(WAException)
const string &type = node->getAttributeValue("type");
if (type == "unavailable") {
const string &lastSeen = node->getAttributeValue("last");
- m_pEventHandler->onAvailable(from, false, (lastSeen == "deny") ? -2 : atoi(lastSeen.c_str()));
+ m_pEventHandler->onAvailable(from, false, (lastSeen == "deny") ? 0 : stoul(lastSeen));
}
else if (type == "available" || type == "")
m_pEventHandler->onAvailable(from, true);
diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h
index 5b6970df60..e85ebbe5db 100644
--- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h
+++ b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h
@@ -36,7 +36,7 @@ public:
virtual void onMessageError(const FMessage &message, int paramInt) = 0;
virtual void onPing(const std::string &paramString) throw (WAException) = 0;
virtual void onPingResponseReceived() = 0;
- virtual void onAvailable(const std::string &paramString, bool paramBoolean, int lastSeenTime = -1) = 0;
+ virtual void onAvailable(const std::string &paramString, bool paramBoolean, DWORD lastSeenTime = 0) = 0;
virtual void onClientConfigReceived(const std::string &paramString) = 0;
virtual void onIsTyping(const std::string &paramString, bool paramBoolean) = 0;
virtual void onAccountChange(int paramInt, time_t paramLong) = 0;
diff --git a/protocols/WhatsApp/src/contacts.cpp b/protocols/WhatsApp/src/contacts.cpp
index 67f9a9a2aa..e657c1d00d 100644
--- a/protocols/WhatsApp/src/contacts.cpp
+++ b/protocols/WhatsApp/src/contacts.cpp
@@ -104,7 +104,7 @@ void WhatsAppProto::ProcessBuddyList(void*)
CODE_BLOCK_CATCH_ALL
}
-void WhatsAppProto::onAvailable(const std::string &paramString, bool paramBoolean, int lastSeenTime)
+void WhatsAppProto::onAvailable(const std::string &paramString, bool paramBoolean, DWORD lastSeenTime)
{
MCONTACT hContact = AddToContactList(paramString);
if (hContact != NULL) {
@@ -114,7 +114,12 @@ void WhatsAppProto::onAvailable(const std::string &paramString, bool paramBoolea
}
else {
setWord(hContact, "Status", ID_STATUS_OFFLINE);
- setDword(hContact, WHATSAPP_KEY_LAST_SEEN, lastSeenTime);
+ if (lastSeenTime != 0) {
+ setDword(hContact, WHATSAPP_KEY_LAST_SEEN, lastSeenTime);
+ setByte(hContact, WHATSAPP_KEY_LAST_SEEN_DENIED, 0);
+ }
+ else
+ setByte(hContact, WHATSAPP_KEY_LAST_SEEN_DENIED, 1);
}
UpdateStatusMsg(hContact);
}
@@ -123,21 +128,19 @@ void WhatsAppProto::onAvailable(const std::string &paramString, bool paramBoolea
void WhatsAppProto::UpdateStatusMsg(MCONTACT hContact)
{
std::wstringstream ss;
-
- int lastSeen = getDword(hContact, WHATSAPP_KEY_LAST_SEEN, -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) {
+ DWORD lastSeen = getDword(hContact, WHATSAPP_KEY_LAST_SEEN, 0);
+ WORD status = getWord(hContact, "Status", ID_STATUS_OFFLINE);
+ bool denied = getBool(hContact, WHATSAPP_KEY_LAST_SEEN_DENIED, false);
+ if (lastSeen > 0) {
time_t ts = lastSeen;
TCHAR stzLastSeen[MAX_PATH];
- _tcsftime(stzLastSeen, _countof(stzLastSeen), TranslateT("Last seen on %x at %X"), localtime(&ts));
+ if (status == ID_STATUS_ONLINE)
+ _tcsftime(stzLastSeen, _countof(stzLastSeen), TranslateT("Last online on %x at %X"), localtime(&ts));
+ else
+ _tcsftime(stzLastSeen, _countof(stzLastSeen), denied ? TranslateT("Denied: Last online on %x at %X") : 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/db.h b/protocols/WhatsApp/src/db.h
index c7f31eb703..22936d4f64 100644
--- a/protocols/WhatsApp/src/db.h
+++ b/protocols/WhatsApp/src/db.h
@@ -9,6 +9,7 @@
#define WHATSAPP_KEY_LOGGING_ENABLE "LoggingEnable"
#define WHATSAPP_KEY_NAME "RealName"
#define WHATSAPP_KEY_LAST_SEEN "LastSeen"
+#define WHATSAPP_KEY_LAST_SEEN_DENIED "LastSeenDenied"
#define WHATSAPP_KEY_AVATAR_ID "AvatarId"
#define WHATSAPP_KEY_SYSTRAY_NOTIFY "UseSystrayNotify"
#define WHATSAPP_KEY_DEF_GROUP "DefaultGroup"
diff --git a/protocols/WhatsApp/src/proto.h b/protocols/WhatsApp/src/proto.h
index 7e800cf21c..83c2824ae6 100644
--- a/protocols/WhatsApp/src/proto.h
+++ b/protocols/WhatsApp/src/proto.h
@@ -165,7 +165,7 @@ 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 &paramString, bool paramBoolean, int lastSeenTime);
+ virtual void onAvailable(const std::string &paramString, bool paramBoolean, DWORD lastSeenTime);
virtual void onClientConfigReceived(const std::string &paramString) { }
virtual void onIsTyping(const std::string &paramString, bool paramBoolean);
virtual void onAccountChange(int paramInt, time_t expire_date) { }