diff options
author | George Hazan <ghazan@miranda.im> | 2022-11-02 20:40:29 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-11-02 20:40:29 +0300 |
commit | 8576740bf5e710a9ceaf25b7fbe47aa94372c97c (patch) | |
tree | 298e3ff22d0b2ca8c0d0a5956769e9302ae77d41 | |
parent | afd405714c11d5ef63db82d752b2132d448fe0ca (diff) |
WhatsApp:
- fixes #3236 (WhatsApp: при первом запуске среди контактов загружается и мой собственный (с моим номером));
- fixes #3235 (WhatsApp: выдавать запрос на сопряжение (QR), если пользователь удалил привязанную Миранду в настройках мобильного приложения)
-rw-r--r-- | protocols/WhatsApp/src/iq.cpp | 42 | ||||
-rw-r--r-- | protocols/WhatsApp/src/proto.cpp | 3 | ||||
-rw-r--r-- | protocols/WhatsApp/src/proto.h | 2 | ||||
-rw-r--r-- | protocols/WhatsApp/src/server.cpp | 60 |
4 files changed, 78 insertions, 29 deletions
diff --git a/protocols/WhatsApp/src/iq.cpp b/protocols/WhatsApp/src/iq.cpp index dc20e034e3..7dede1f437 100644 --- a/protocols/WhatsApp/src/iq.cpp +++ b/protocols/WhatsApp/src/iq.cpp @@ -128,6 +128,8 @@ void WhatsAppProto::OnIqPairSuccess(const WANode &node) if (auto *pszJid = pDevice->getAttr("jid")) { WAJid jid(pszJid); m_szJid = jid.user + "@" + jid.server; + m_arUsers.insert(new WAUser(0, m_szJid, false)); + setUString(DBKEY_ID, m_szJid); setDword(DBKEY_DEVICE_ID, jid.device); } @@ -403,6 +405,15 @@ LBL_Error: ///////////////////////////////////////////////////////////////////////////////////////// +void WhatsAppProto::OnReceiveFailure(const WANode &node) +{ + m_bTerminated = true; + + ProcessFailure(node.getAttrInt("reason")); +} + +///////////////////////////////////////////////////////////////////////////////////////// + void WhatsAppProto::OnReceiveInfo(const WANode &node) { if (auto *pChild = node.getFirstChild()) { @@ -473,34 +484,8 @@ void WhatsAppProto::OnStreamError(const WANode &node) { m_bTerminated = true; - if (auto *pszCode = node.getAttr("code")) { - switch (atoi(pszCode)) { - case 401: - debugLogA("Connection logged out from another device, exiting"); - break; - - case 408: - debugLogA("Connection lost, exiting"); - break; - - case 411: - debugLogA("Conflict between two devices, exiting"); - break; - - case 428: - debugLogA("Connection forcibly closed by the server, exiting"); - break; - - case 440: - debugLogA("Connection replaced from another device, exiting"); - break; - - case 515: - debugLogA("Server required to restart immediately, leaving thread"); - m_bRespawn = true; - break; - } - } + if (auto *pszCode = node.getAttr("code")) + ProcessFailure(atoi(pszCode)); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -528,6 +513,7 @@ void WhatsAppProto::InitPersistentHandlers() m_arPersistent.insert(new WAPersistentHandler("ack", 0, 0, 0, &WhatsAppProto::OnReceiveAck)); m_arPersistent.insert(new WAPersistentHandler("ib", 0, 0, 0, &WhatsAppProto::OnReceiveInfo)); + m_arPersistent.insert(new WAPersistentHandler("failure", 0, 0, 0, &WhatsAppProto::OnReceiveFailure)); m_arPersistent.insert(new WAPersistentHandler("message", 0, 0, 0, &WhatsAppProto::OnReceiveMessage)); m_arPersistent.insert(new WAPersistentHandler("receipt", 0, 0, 0, &WhatsAppProto::OnReceiveReceipt)); m_arPersistent.insert(new WAPersistentHandler("chatstates", 0, 0, 0, &WhatsAppProto::OnReceiveChatState)); diff --git a/protocols/WhatsApp/src/proto.cpp b/protocols/WhatsApp/src/proto.cpp index 7a74dadba5..8d72d38af0 100644 --- a/protocols/WhatsApp/src/proto.cpp +++ b/protocols/WhatsApp/src/proto.cpp @@ -116,7 +116,8 @@ void WhatsAppProto::OnErase() void WhatsAppProto::OnModulesLoaded() { // initialize contacts cache - m_arUsers.insert(new WAUser(0, m_szJid, false)); + if (!m_szJid.IsEmpty()) + m_arUsers.insert(new WAUser(0, m_szJid, false)); for (auto &cc : AccContacts()) { bool bIsChat = isChatRoom(cc); diff --git a/protocols/WhatsApp/src/proto.h b/protocols/WhatsApp/src/proto.h index 521bea0f3c..57f980fb7a 100644 --- a/protocols/WhatsApp/src/proto.h +++ b/protocols/WhatsApp/src/proto.h @@ -323,6 +323,7 @@ class WhatsAppProto : public PROTO<WhatsAppProto> void OnLoggedIn(void); void OnLoggedOut(void); + void ProcessFailure(int code); void ServerThreadWorker(void); void ShutdownSession(void); @@ -363,6 +364,7 @@ class WhatsAppProto : public PROTO<WhatsAppProto> void OnNotifyPicture(const WANode &node); void OnReceiveAck(const WANode &node); void OnReceiveChatState(const WANode &node); + void OnReceiveFailure(const WANode &node); void OnReceiveInfo(const WANode &node); void OnReceiveMessage(const WANode &node); void OnReceiveReceipt(const WANode &node); diff --git a/protocols/WhatsApp/src/server.cpp b/protocols/WhatsApp/src/server.cpp index 6fe9981d5e..26a8015445 100644 --- a/protocols/WhatsApp/src/server.cpp +++ b/protocols/WhatsApp/src/server.cpp @@ -222,6 +222,66 @@ void WhatsAppProto::ProcessBinaryPacket(const uint8_t *pData, size_t cbDataLen) ///////////////////////////////////////////////////////////////////////////////////////// +const char *pszNeededItems[] = { + "AM_BaseProto", "DefaultGroup", "DeviceName", "HideChats", "NLlog", "Nick" +}; + +static int sttEnumFunc(const char *szSetting, void *param) +{ + for (auto &it : pszNeededItems) + if (!mir_strcmp(it, szSetting)) + return 0; + + auto *pList = (LIST<char>*)param; + pList->insert(mir_strdup(szSetting)); + return 0; +} + +void WhatsAppProto::ProcessFailure(int code) +{ + switch (code) { + case 401: + debugLogA("Connection logged out from another device, exiting"); + Popup(0, TranslateT("This account was logged out from another device, you need to register it again"), m_tszUserName); + + // remove all temporary data from database & disk folder + { + LIST<char> arSettings(50); + db_enum_settings(0, sttEnumFunc, m_szModuleName, &arSettings); + for (auto &it : arSettings) { + delSetting(it); + mir_free(it); + } + } + m_szJid.Empty(); + OnErase(); + break; + + case 408: + debugLogA("Connection lost, exiting"); + break; + + case 411: + debugLogA("Conflict between two devices, exiting"); + break; + + case 428: + debugLogA("Connection forcibly closed by the server, exiting"); + break; + + case 440: + debugLogA("Connection replaced from another device, exiting"); + break; + + case 515: + debugLogA("Server required to restart immediately, leaving thread"); + m_bRespawn = true; + break; + } +} + +///////////////////////////////////////////////////////////////////////////////////////// + void WhatsAppProto::OnLoggedIn() { debugLogA("WhatsAppProto::OnLoggedIn"); |