diff options
author | George Hazan <ghazan@miranda.im> | 2022-11-27 16:30:58 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-11-27 16:30:58 +0300 |
commit | 6ff0fc99fc3b35f5d11e40a0143ce70e7a1469fc (patch) | |
tree | 05c2f361b7b5321b9fd93cf5be1c4e1ff1433b0b /protocols | |
parent | 2736fc87cc5fb5329f7d5b3a100560da1fd84a1b (diff) |
fixes #3237 (WhatsApp: при удалении учётной записи из Миранды разрывать и сопряжение с телефоном)
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/WhatsApp/res/whatsapp.rc | 1 | ||||
-rw-r--r-- | protocols/WhatsApp/src/options.cpp | 15 | ||||
-rw-r--r-- | protocols/WhatsApp/src/proto.cpp | 28 | ||||
-rw-r--r-- | protocols/WhatsApp/src/proto.h | 6 | ||||
-rw-r--r-- | protocols/WhatsApp/src/resource.h | 4 | ||||
-rw-r--r-- | protocols/WhatsApp/src/server.cpp | 42 |
6 files changed, 67 insertions, 29 deletions
diff --git a/protocols/WhatsApp/res/whatsapp.rc b/protocols/WhatsApp/res/whatsapp.rc index 77ecf497e9..e72fd8542c 100644 --- a/protocols/WhatsApp/res/whatsapp.rc +++ b/protocols/WhatsApp/res/whatsapp.rc @@ -63,6 +63,7 @@ BEGIN CONTROL "Do not open chat windows on creation",IDC_HIDECHATS, "Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,64,294,10 CONTROL "Use BBCode",IDC_USEBBCODES,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,78,294,10 + PUSHBUTTON "Unregister",IDC_UNREGISTER,222,170,77,14 END IDD_GROUPCHAT_INVITE DIALOGEX 0, 0, 215, 170 diff --git a/protocols/WhatsApp/src/options.cpp b/protocols/WhatsApp/src/options.cpp index 0df8e005b1..3df8e69343 100644 --- a/protocols/WhatsApp/src/options.cpp +++ b/protocols/WhatsApp/src/options.cpp @@ -13,6 +13,7 @@ class COptionsDlg : public CProtoDlgBase<WhatsAppProto> { CCtrlCheck chkHideChats, chkBbcodes; CCtrlEdit edtGroup, edtNick, edtDevName; + CCtrlButton btnUnregister; ptrW m_wszOldGroup; public: @@ -23,6 +24,7 @@ public: edtNick(this, IDC_NICK), edtGroup(this, IDC_DEFGROUP), edtDevName(this, IDC_DEVICE_NAME), + btnUnregister(this, IDC_UNREGISTER), m_wszOldGroup(mir_wstrdup(ppro->m_wszDefaultGroup)) { CreateLink(edtNick, ppro->m_wszNick); @@ -33,6 +35,8 @@ public: CreateLink(chkHideChats, ppro->m_bHideGroupchats); CreateLink(chkBbcodes, ppro->m_bUseBbcodes); } + + btnUnregister.OnClick = Callback(this, &COptionsDlg::onClick_Unregister); } bool OnInitDialog() override @@ -53,6 +57,17 @@ public: Clist_GroupCreate(0, m_proto->m_wszDefaultGroup); return true; } + + void onClick_Unregister(CCtrlButton *) + { + if (IDYES != MessageBoxW(0, TranslateT("Do you really want to unregister Miranda?"), m_proto->m_tszUserName, MB_ICONQUESTION | MB_YESNO)) + return; + + if (m_proto->isOnline()) + m_proto->SendUnregister(); + else + m_proto->OnErase(); + } }; ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/WhatsApp/src/proto.cpp b/protocols/WhatsApp/src/proto.cpp index 235b610817..61a50cbf79 100644 --- a/protocols/WhatsApp/src/proto.cpp +++ b/protocols/WhatsApp/src/proto.cpp @@ -113,9 +113,37 @@ WhatsAppProto::~WhatsAppProto() ///////////////////////////////////////////////////////////////////////////////////////// // OnErase - remove temporary folder for account +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::OnErase() { + m_bUnregister = true; + ServerThreadWorker(); + + // 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); + } + DeleteDirectoryTreeW(CMStringW(VARSW(L"%miranda_userdata%")) + L"\\" + _A2T(m_szModuleName), false); + + m_szJid.Empty(); } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/WhatsApp/src/proto.h b/protocols/WhatsApp/src/proto.h index 0d4fd624a0..29f198e298 100644 --- a/protocols/WhatsApp/src/proto.h +++ b/protocols/WhatsApp/src/proto.h @@ -258,6 +258,7 @@ class WhatsAppProto : public PROTO<WhatsAppProto> { friend class WANoise; friend class CWhatsAppQRDlg; + friend class COptionsDlg; class CWhatsAppProtoImpl { @@ -284,7 +285,7 @@ class WhatsAppProto : public PROTO<WhatsAppProto> } } m_impl; - bool m_bTerminated, m_bRespawn, m_bUpdatedPrekeys; + bool m_bTerminated, m_bRespawn, m_bUpdatedPrekeys, m_bUnregister; ptrW m_tszDefaultGroup; CMStringA m_szJid; @@ -371,8 +372,9 @@ class WhatsAppProto : public PROTO<WhatsAppProto> void SendAck(const WANode &node); void SendReceipt(const char *pszTo, const char *pszParticipant, const char *pszId, const char *pszType); - void SendKeepAlive(); + void SendKeepAlive(void); int SendTextMessage(const char *jid, const char *pszMsg); + void SendUnregister(void); void SendUsync(const LIST<char> &jids, void *pUserInfo); void SetServerStatus(int iStatus); diff --git a/protocols/WhatsApp/src/resource.h b/protocols/WhatsApp/src/resource.h index 8464ab3d8a..da0a77bf73 100644 --- a/protocols/WhatsApp/src/resource.h +++ b/protocols/WhatsApp/src/resource.h @@ -15,6 +15,8 @@ #define IDC_NICK 1005 #define IDC_DEVICE_NAME 1006 #define IDC_USEBBCODES 1007 +#define IDC_BUTTON1 1008 +#define IDC_UNREGISTER 1008 // Next default values for new objects // @@ -22,7 +24,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 104 #define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1007 +#define _APS_NEXT_CONTROL_VALUE 1009 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/protocols/WhatsApp/src/server.cpp b/protocols/WhatsApp/src/server.cpp index 8e211535e7..0745c08aad 100644 --- a/protocols/WhatsApp/src/server.cpp +++ b/protocols/WhatsApp/src/server.cpp @@ -13,7 +13,7 @@ Copyright 2019-22 George Hazan void WhatsAppProto::ServerThread(void *) { do { - m_bRespawn = false; + m_bRespawn = m_bUnregister = false; ServerThreadWorker(); } while (m_bRespawn); @@ -222,21 +222,6 @@ 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) { @@ -244,16 +229,6 @@ void WhatsAppProto::ProcessFailure(int code) debugLogA("Connection logged out from another device, exiting"); Popup(0, TranslateT("This account was logged out from mobile phone, you need to link 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; @@ -286,6 +261,12 @@ void WhatsAppProto::OnLoggedIn() { debugLogA("WhatsAppProto::OnLoggedIn"); + if (m_bUnregister) { + SendUnregister(); + m_bTerminated = true; + return; + } + SetServerStatus(m_iDesiredStatus); ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)m_iStatus, m_iDesiredStatus); @@ -399,6 +380,15 @@ void WhatsAppProto::SetServerStatus(int iStatus) &WhatsAppProto::OnIqDoNothing); } +void WhatsAppProto::SendUnregister() +{ + WANodeIq iq(IQ::SET, "md"); + *iq.addChild("remove-companion-device") << CHAR_PARAM("jid", WAJid(m_szJid, getDword(DBKEY_DEVICE_ID)).toString()) << CHAR_PARAM("reason", "user's decision"); + WSSendNode(iq, &WhatsAppProto::OnIqDoNothing); + + m_bTerminated = true; +} + void WhatsAppProto::SendUsync(const LIST<char> &jids, void *pUserInfo) { WANodeIq iq(IQ::GET, "usync"); |