From 6ff0fc99fc3b35f5d11e40a0143ce70e7a1469fc Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 27 Nov 2022 16:30:58 +0300 Subject: =?UTF-8?q?fixes=20#3237=20(WhatsApp:=20=D0=BF=D1=80=D0=B8=20?= =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B8=20=D1=83=D1=87?= =?UTF-8?q?=D1=91=D1=82=D0=BD=D0=BE=D0=B9=20=D0=B7=D0=B0=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B8=20=D0=B8=D0=B7=20=D0=9C=D0=B8=D1=80=D0=B0=D0=BD=D0=B4?= =?UTF-8?q?=D1=8B=20=D1=80=D0=B0=D0=B7=D1=80=D1=8B=D0=B2=D0=B0=D1=82=D1=8C?= =?UTF-8?q?=20=D0=B8=20=D1=81=D0=BE=D0=BF=D1=80=D1=8F=D0=B6=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=81=20=D1=82=D0=B5=D0=BB=D0=B5=D1=84=D0=BE?= =?UTF-8?q?=D0=BD=D0=BE=D0=BC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/WhatsApp/res/whatsapp.rc | 1 + protocols/WhatsApp/src/options.cpp | 15 ++++++++++++++ protocols/WhatsApp/src/proto.cpp | 28 +++++++++++++++++++++++++ protocols/WhatsApp/src/proto.h | 6 ++++-- protocols/WhatsApp/src/resource.h | 4 +++- protocols/WhatsApp/src/server.cpp | 42 +++++++++++++++----------------------- 6 files changed, 67 insertions(+), 29 deletions(-) (limited to 'protocols') 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 { 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*)param; + pList->insert(mir_strdup(szSetting)); + return 0; +} + void WhatsAppProto::OnErase() { + m_bUnregister = true; + ServerThreadWorker(); + + // remove all temporary data from database & disk folder + LIST 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 { friend class WANoise; friend class CWhatsAppQRDlg; + friend class COptionsDlg; class CWhatsAppProtoImpl { @@ -284,7 +285,7 @@ class WhatsAppProto : public PROTO } } 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 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 &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 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*)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 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 &jids, void *pUserInfo) { WANodeIq iq(IQ::GET, "usync"); -- cgit v1.2.3