summaryrefslogtreecommitdiff
path: root/protocols/WhatsApp/src/contacts.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-02-09 21:23:16 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-02-09 21:23:16 +0000
commit7e1c726175d39a6fa069d10fb0fdc88b0ec81b0b (patch)
tree9fa9017de02c5dbd8352ec2693c2a0a5948f18e4 /protocols/WhatsApp/src/contacts.cpp
parent8e6d90e5ce900f627c1303c35ff42ae7f70e2e80 (diff)
- fix for returning chats online after going offline
- code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@12076 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/WhatsApp/src/contacts.cpp')
-rw-r--r--protocols/WhatsApp/src/contacts.cpp36
1 files changed, 14 insertions, 22 deletions
diff --git a/protocols/WhatsApp/src/contacts.cpp b/protocols/WhatsApp/src/contacts.cpp
index 8ee4c0318c..7c58d64707 100644
--- a/protocols/WhatsApp/src/contacts.cpp
+++ b/protocols/WhatsApp/src/contacts.cpp
@@ -53,25 +53,17 @@ MCONTACT WhatsAppProto::AddToContactList(const std::string &jid, const char *new
MCONTACT WhatsAppProto::ContactIDToHContact(const std::string &phoneNumber)
{
// Cache
- std::map<string, MCONTACT>::iterator it = this->hContactByJid.find(phoneNumber);
- if (it != this->hContactByJid.end())
+ std::map<string, MCONTACT>::iterator it = m_hContactByJid.find(phoneNumber);
+ if (it != m_hContactByJid.end())
return it->second;
- const char* idForContact = "ID";
- const char* idForChat = "ChatRoomID";
-
for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
- const char* id = isChatRoom(hContact) ? idForChat : idForContact;
-
- DBVARIANT dbv;
- if (!getString(hContact, id, &dbv)) {
- if (strcmp(phoneNumber.c_str(), dbv.pszVal) == 0) {
- db_free(&dbv);
- this->hContactByJid[phoneNumber] = hContact;
- return hContact;
- }
+ const char *id = isChatRoom(hContact) ? "ChatRoomID" : WHATSAPP_KEY_ID;
- db_free(&dbv);
+ ptrA szId(getStringA(hContact, id));
+ if (!mir_strcmp(phoneNumber.c_str(), szId)) {
+ m_hContactByJid[phoneNumber] = hContact;
+ return hContact;
}
}
@@ -118,26 +110,26 @@ void WhatsAppProto::ProcessBuddyList(void*)
void WhatsAppProto::onAvailable(const std::string &paramString, bool paramBoolean)
{
- MCONTACT hContact = this->AddToContactList(paramString);
+ MCONTACT hContact = AddToContactList(paramString);
if (hContact != NULL) {
if (paramBoolean)
setWord(hContact, "Status", ID_STATUS_ONLINE);
else {
setWord(hContact, "Status", ID_STATUS_OFFLINE);
- this->UpdateStatusMsg(hContact);
+ UpdateStatusMsg(hContact);
}
}
setDword(hContact, WHATSAPP_KEY_LAST_SEEN, 0);
- this->UpdateStatusMsg(hContact);
+ UpdateStatusMsg(hContact);
}
void WhatsAppProto::onLastSeen(const std::string &paramString1, int paramInt, const string &paramString2)
{
- MCONTACT hContact = this->AddToContactList(paramString1);
+ MCONTACT hContact = AddToContactList(paramString1);
setDword(hContact, WHATSAPP_KEY_LAST_SEEN, paramInt);
- this->UpdateStatusMsg(hContact);
+ UpdateStatusMsg(hContact);
}
void WhatsAppProto::UpdateStatusMsg(MCONTACT hContact)
@@ -167,7 +159,7 @@ void WhatsAppProto::onPictureChanged(const std::string &jid, const std::string &
void WhatsAppProto::onSendGetPicture(const std::string &jid, const std::vector<unsigned char>& data, const std::string &id)
{
- MCONTACT hContact = this->ContactIDToHContact(jid);
+ MCONTACT hContact = ContactIDToHContact(jid);
if (hContact) {
debugLogA("Updating avatar for jid %s", jid.c_str());
@@ -196,6 +188,6 @@ void WhatsAppProto::onSendGetPicture(const std::string &jid, const std::vector<u
TCHAR* WhatsAppProto::GetContactDisplayName(const string& jid)
{
- MCONTACT hContact = this->ContactIDToHContact(jid);
+ MCONTACT hContact = ContactIDToHContact(jid);
return (hContact) ? pcli->pfnGetContactDisplayName(hContact, 0) : _T("none");
}