diff options
author | George Hazan <george.hazan@gmail.com> | 2015-02-09 21:23:16 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-02-09 21:23:16 +0000 |
commit | 7e1c726175d39a6fa069d10fb0fdc88b0ec81b0b (patch) | |
tree | 9fa9017de02c5dbd8352ec2693c2a0a5948f18e4 /protocols/WhatsApp | |
parent | 8e6d90e5ce900f627c1303c35ff42ae7f70e2e80 (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')
-rw-r--r-- | protocols/WhatsApp/src/chat.cpp | 5 | ||||
-rw-r--r-- | protocols/WhatsApp/src/connection.cpp | 14 | ||||
-rw-r--r-- | protocols/WhatsApp/src/contacts.cpp | 36 | ||||
-rw-r--r-- | protocols/WhatsApp/src/proto.cpp | 22 | ||||
-rw-r--r-- | protocols/WhatsApp/src/proto.h | 4 |
5 files changed, 39 insertions, 42 deletions
diff --git a/protocols/WhatsApp/src/chat.cpp b/protocols/WhatsApp/src/chat.cpp index 28c20c80e8..020773f37a 100644 --- a/protocols/WhatsApp/src/chat.cpp +++ b/protocols/WhatsApp/src/chat.cpp @@ -345,6 +345,11 @@ void WhatsAppProto::onGroupInfo(const std::string &jid, const std::string &owner pInfo = InitChat(jid, subject);
pInfo->bActive = true;
}
+ else {
+ GCDEST gcd = { m_szModuleName, pInfo->tszJid, GC_EVENT_CONTROL };
+ GCEVENT gce = { sizeof(gce), &gcd };
+ CallServiceSync(MS_GC_EVENT, SESSION_ONLINE, (LPARAM)&gce);
+ }
if (!subject.empty()) {
pInfo->tszOwner = str2t(owner);
diff --git a/protocols/WhatsApp/src/connection.cpp b/protocols/WhatsApp/src/connection.cpp index 90c56a4973..33152e4098 100644 --- a/protocols/WhatsApp/src/connection.cpp +++ b/protocols/WhatsApp/src/connection.cpp @@ -34,16 +34,16 @@ void WhatsAppProto::stayConnectedLoop(void*) Mutex writerMutex;
bool error = false;
- this->conn = NULL;
+ m_pSocket = NULL;
while (true) {
if (m_pConnection != NULL) {
delete m_pConnection;
m_pConnection = NULL;
}
- if (this->conn != NULL) {
- delete this->conn;
- this->conn = NULL;
+ if (m_pSocket != NULL) {
+ delete m_pSocket;
+ m_pSocket = NULL;
}
if (m_iDesiredStatus == ID_STATUS_OFFLINE || error) {
@@ -68,8 +68,8 @@ void WhatsAppProto::stayConnectedLoop(void*) else
portNumber = 5222, resource += "-5222";
- this->conn = new WASocketConnection("c.whatsapp.net", portNumber);
- m_pConnection = new WAConnection(m_szPhoneNumber, resource, &this->connMutex, &writerMutex, this->conn, this, this);
+ m_pSocket = new WASocketConnection("c.whatsapp.net", portNumber);
+ m_pConnection = new WAConnection(m_szPhoneNumber, resource, &connMutex, &writerMutex, m_pSocket, this, this);
{
WALogin login(m_pConnection, password);
@@ -84,7 +84,7 @@ void WhatsAppProto::stayConnectedLoop(void*) debugLogA("Set status to online");
m_iStatus = m_iDesiredStatus;
ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus);
- this->ToggleStatusMenuItems(true);
+ ToggleStatusMenuItems(true);
ForkThread(&WhatsAppProto::ProcessBuddyList, NULL);
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 ¶mString, 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 ¶mString1, int paramInt, const string ¶mString2)
{
- 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");
}
diff --git a/protocols/WhatsApp/src/proto.cpp b/protocols/WhatsApp/src/proto.cpp index 93847e1747..b09c81fc68 100644 --- a/protocols/WhatsApp/src/proto.cpp +++ b/protocols/WhatsApp/src/proto.cpp @@ -128,16 +128,16 @@ int WhatsAppProto::SetStatus(int new_status) }
if (m_iDesiredStatus == ID_STATUS_OFFLINE) {
- if (this->conn != NULL) {
+ if (m_pSocket != NULL) {
SetEvent(update_loop_lock_);
- this->conn->forceShutdown();
+ m_pSocket->forceShutdown();
debugLogA("Forced shutdown");
}
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)) {
+ else if (m_pSocket == 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);
@@ -272,7 +272,7 @@ bool WhatsAppProto::Register(int state, const string &cc, const string &number, const TCHAR *ptszTitle = TranslateT("Registration");
if (pnlhr == NULL) {
- this->NotifyEvent(ptszTitle, TranslateT("Registration failed. Invalid server response."), NULL, WHATSAPP_EVENT_CLIENT);
+ NotifyEvent(ptszTitle, TranslateT("Registration failed. Invalid server response."), NULL, WHATSAPP_EVENT_CLIENT);
return false;
}
@@ -280,7 +280,7 @@ bool WhatsAppProto::Register(int state, const string &cc, const string &number, JSONROOT resp(pnlhr->pData);
if (resp == NULL) {
- this->NotifyEvent(ptszTitle, TranslateT("Registration failed. Invalid server response."), NULL, WHATSAPP_EVENT_CLIENT);
+ NotifyEvent(ptszTitle, TranslateT("Registration failed. Invalid server response."), NULL, WHATSAPP_EVENT_CLIENT);
return false;
}
@@ -289,14 +289,14 @@ bool WhatsAppProto::Register(int state, const string &cc, const string &number, if (!mir_tstrcmp(ptrT(json_as_string(val)), _T("fail"))) {
JSONNODE *tmpVal = json_get(resp, "reason");
if (!mir_tstrcmp(ptrT(json_as_string(tmpVal)), _T("stale")))
- this->NotifyEvent(ptszTitle, TranslateT("Registration failed due to stale code. Please request a new code"), NULL, WHATSAPP_EVENT_CLIENT);
+ NotifyEvent(ptszTitle, TranslateT("Registration failed due to stale code. Please request a new code"), NULL, WHATSAPP_EVENT_CLIENT);
else
- this->NotifyEvent(ptszTitle, TranslateT("Registration failed."), NULL, WHATSAPP_EVENT_CLIENT);
+ NotifyEvent(ptszTitle, TranslateT("Registration failed."), NULL, WHATSAPP_EVENT_CLIENT);
tmpVal = json_get(resp, "retry_after");
if (tmpVal != NULL) {
CMString tmp(FORMAT, TranslateT("Please try again in %i seconds"), json_as_int(tmpVal));
- this->NotifyEvent(ptszTitle, tmp, NULL, WHATSAPP_EVENT_OTHER);
+ NotifyEvent(ptszTitle, tmp, NULL, WHATSAPP_EVENT_OTHER);
}
return false;
}
@@ -307,7 +307,7 @@ bool WhatsAppProto::Register(int state, const string &cc, const string &number, if (val != NULL)
ret = _T2A(ptrT(json_as_string(val)));
else if (!mir_tstrcmp(ptrT(json_as_string(val)), _T("sent")))
- this->NotifyEvent(ptszTitle, TranslateT("Registration code has been sent to your phone."), NULL, WHATSAPP_EVENT_OTHER);
+ NotifyEvent(ptszTitle, TranslateT("Registration code has been sent to your phone."), NULL, WHATSAPP_EVENT_OTHER);
return true;
}
@@ -318,7 +318,7 @@ bool WhatsAppProto::Register(int state, const string &cc, const string &number, ret = _T2A(ptrT(json_as_string(val)));
return true;
}
- this->NotifyEvent(ptszTitle, TranslateT("Registration failed."), NULL, WHATSAPP_EVENT_CLIENT);
+ NotifyEvent(ptszTitle, TranslateT("Registration failed."), NULL, WHATSAPP_EVENT_CLIENT);
}
return false;
@@ -387,7 +387,7 @@ void WhatsAppProto::NotifyEvent(const string& title, const string& info, MCONTAC {
TCHAR *rawTitle = mir_a2t_cp(title.c_str(), CP_UTF8);
TCHAR *rawInfo = mir_a2t_cp(info.c_str(), CP_UTF8);
- this->NotifyEvent(rawTitle, rawInfo, contact, flags, url);
+ NotifyEvent(rawTitle, rawInfo, contact, flags, url);
mir_free(rawTitle);
mir_free(rawInfo);
}
diff --git a/protocols/WhatsApp/src/proto.h b/protocols/WhatsApp/src/proto.h index 1c1ddb3192..4c1b936840 100644 --- a/protocols/WhatsApp/src/proto.h +++ b/protocols/WhatsApp/src/proto.h @@ -172,7 +172,7 @@ private: HANDLE update_loop_lock_;
- WASocketConnection *conn;
+ WASocketConnection *m_pSocket;
WAConnection *m_pConnection;
Mutex connMutex;
time_t m_tLastWriteTime;
@@ -180,7 +180,7 @@ private: std::vector<unsigned char> m_Challenge;
std::string m_szPhoneNumber;
std::string m_szJid, m_szNick;
- std::map<string, MCONTACT> hContactByJid;
+ std::map<string, MCONTACT> m_hContactByJid;
map<MCONTACT, map<MCONTACT, bool>> isMemberByGroupContact;
protected:
|