summaryrefslogtreecommitdiff
path: root/protocols/WhatsAppWeb/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-10-03 20:00:41 +0300
committerGeorge Hazan <ghazan@miranda.im>2022-10-03 20:00:41 +0300
commitcc0cde8d87358738bcad304e8bdc9c944d55cdaa (patch)
treec6615f01402c324e349437ebd3575c94d48ddaf6 /protocols/WhatsAppWeb/src
parentf23e1a5e267d9feec25b3a8a2f26017d03963f25 (diff)
WhatsApp:
- nick name added to all options dialogs; - added error popups;
Diffstat (limited to 'protocols/WhatsAppWeb/src')
-rw-r--r--protocols/WhatsAppWeb/src/options.cpp9
-rw-r--r--protocols/WhatsAppWeb/src/proto.cpp9
-rw-r--r--protocols/WhatsAppWeb/src/proto.h11
-rw-r--r--protocols/WhatsAppWeb/src/resource.h6
-rw-r--r--protocols/WhatsAppWeb/src/server.cpp9
-rw-r--r--protocols/WhatsAppWeb/src/utils.cpp48
6 files changed, 83 insertions, 9 deletions
diff --git a/protocols/WhatsAppWeb/src/options.cpp b/protocols/WhatsAppWeb/src/options.cpp
index 9270afd3d1..46b4d8da97 100644
--- a/protocols/WhatsAppWeb/src/options.cpp
+++ b/protocols/WhatsAppWeb/src/options.cpp
@@ -12,16 +12,18 @@ Copyright © 2019-22 George Hazan
class COptionsDlg : public CProtoDlgBase<WhatsAppProto>
{
CCtrlCheck chkHideChats;
- CCtrlEdit edtGroup;
+ CCtrlEdit edtGroup, edtNick;
ptrW m_wszOldGroup;
public:
COptionsDlg(WhatsAppProto *ppro, int iDlgID, bool bFullDlg) :
CProtoDlgBase<WhatsAppProto>(ppro, iDlgID),
chkHideChats(this, IDC_HIDECHATS),
+ edtNick(this, IDC_NICK),
edtGroup(this, IDC_DEFGROUP),
m_wszOldGroup(mir_wstrdup(ppro->m_wszDefaultGroup))
{
+ CreateLink(edtNick, ppro->m_wszNick);
CreateLink(edtGroup, ppro->m_wszDefaultGroup);
if (bFullDlg)
@@ -30,6 +32,11 @@ public:
bool OnApply() override
{
+ if (mir_wstrlen(m_proto->m_wszNick)) {
+ SetFocus(edtNick.GetHwnd());
+ return false;
+ }
+
if (mir_wstrcmp(m_proto->m_wszDefaultGroup, m_wszOldGroup))
Clist_GroupCreate(0, m_proto->m_wszDefaultGroup);
return true;
diff --git a/protocols/WhatsAppWeb/src/proto.cpp b/protocols/WhatsAppWeb/src/proto.cpp
index c29a7d60d9..1aa6117446 100644
--- a/protocols/WhatsAppWeb/src/proto.cpp
+++ b/protocols/WhatsAppWeb/src/proto.cpp
@@ -36,7 +36,9 @@ WhatsAppProto::WhatsAppProto(const char *proto_name, const wchar_t *username) :
m_arOwnMsgs(1, CompareOwnMsgs),
m_arPersistent(1),
m_arPacketQueue(10),
+ m_wszNick(this, "Nick"),
m_wszDefaultGroup(this, "DefaultGroup", L"WhatsApp"),
+ m_bUsePopups(this, "UsePopups", true),
m_bHideGroupchats(this, "HideChats", true)
{
db_set_resident(m_szModuleName, "StatusMsg");
@@ -50,6 +52,7 @@ WhatsAppProto::WhatsAppProto(const char *proto_name, const wchar_t *username) :
HookProtoEvent(ME_OPT_INITIALISE, &WhatsAppProto::OnOptionsInit);
+ InitPopups();
InitPersistentHandlers();
// Create standard network connection
@@ -136,8 +139,12 @@ int WhatsAppProto::SetStatus(int new_status)
if (m_iDesiredStatus == new_status)
return 0;
+ if (!mir_wstrlen(m_wszNick)) {
+ Popup(0, LPGENW("You need to specify nick name in the Options dialog"), LPGENW("Error"));
+ return 0;
+ }
+
int oldStatus = m_iStatus;
- debugLogA("===== Beginning SetStatus process");
// Routing statuses not supported by WhatsApp
switch (new_status) {
diff --git a/protocols/WhatsAppWeb/src/proto.h b/protocols/WhatsAppWeb/src/proto.h
index 14ef70bd94..18f2eded6b 100644
--- a/protocols/WhatsAppWeb/src/proto.h
+++ b/protocols/WhatsAppWeb/src/proto.h
@@ -197,6 +197,14 @@ class WhatsAppProto : public PROTO<WhatsAppProto>
void SendKeepAlive();
void SetServerStatus(int iStatus);
+ /// Popups /////////////////////////////////////////////////////////////////////////////
+
+ HANDLE m_hPopupClass;
+ CMOption<bool> m_bUsePopups;
+
+ void InitPopups(void);
+ void Popup(MCONTACT hContact, const wchar_t *szMsg, const wchar_t *szTitle);
+
/// Request handlers ///////////////////////////////////////////////////////////////////
void OnGetAvatarInfo(const JSONNode &node, void*);
@@ -213,7 +221,7 @@ class WhatsAppProto : public PROTO<WhatsAppProto>
void OnStreamError(const WANode &node);
void OnSuccess(const WANode &node);
- // binary packets
+ // Binary packets
void ProcessBinaryPacket(const void *pData, size_t cbLen);
/// Avatars ////////////////////////////////////////////////////////////////////////////
@@ -263,6 +271,7 @@ public:
// Options /////////////////////////////////////////////////////////////////////////////
+ CMOption<wchar_t*> m_wszNick; // your nick name in presence
CMOption<wchar_t*> m_wszDefaultGroup; // clist group to store contacts
CMOption<bool> m_bHideGroupchats; // do not open chat windows on creation
diff --git a/protocols/WhatsAppWeb/src/resource.h b/protocols/WhatsAppWeb/src/resource.h
index 0326ab6d8f..c09b549e42 100644
--- a/protocols/WhatsAppWeb/src/resource.h
+++ b/protocols/WhatsAppWeb/src/resource.h
@@ -1,6 +1,6 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
-// Used by w:\miranda-ng\protocols\WhatsAppWeb\res\whatsapp.rc
+// Used by W:\miranda-ng\protocols\WhatsAppWeb\res\whatsapp.rc
//
#define IDI_WHATSAPP 100
#define IDD_ACCMGRUI 101
@@ -9,8 +9,10 @@
#define IDC_HIDECHATS 1000
#define IDC_DEFGROUP 1001
#define IDC_QRPIC 1002
+#define IDC_DEFGROUP2 1002
#define IDC_CLIST 1003
#define IDC_NEWJID 1004
+#define IDC_NICK 1005
// Next default values for new objects
//
@@ -18,7 +20,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 104
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1005
+#define _APS_NEXT_CONTROL_VALUE 1006
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/protocols/WhatsAppWeb/src/server.cpp b/protocols/WhatsAppWeb/src/server.cpp
index 1ac49b6037..9b534af176 100644
--- a/protocols/WhatsAppWeb/src/server.cpp
+++ b/protocols/WhatsAppWeb/src/server.cpp
@@ -273,12 +273,13 @@ void WhatsAppProto::SendKeepAlive()
void WhatsAppProto::SetServerStatus(int iStatus)
{
- WANode iq("presence");
- iq << CHAR_PARAM("name", getMStringA("Nick")) << CHAR_PARAM("type", (iStatus == ID_STATUS_ONLINE) ? "available" : "unavailable");
- WSSendNode(iq);
+ if (mir_wstrlen(m_wszNick)) {
+ WANode iq("presence");
+ iq << CHAR_PARAM("name", T2Utf(m_wszNick)) << CHAR_PARAM("type", (iStatus == ID_STATUS_ONLINE) ? "available" : "unavailable");
+ WSSendNode(iq);
+ }
}
-
/////////////////////////////////////////////////////////////////////////////////////////
void WhatsAppProto::ShutdownSession()
diff --git a/protocols/WhatsAppWeb/src/utils.cpp b/protocols/WhatsAppWeb/src/utils.cpp
index 01e299aca3..127ec33a45 100644
--- a/protocols/WhatsAppWeb/src/utils.cpp
+++ b/protocols/WhatsAppWeb/src/utils.cpp
@@ -293,3 +293,51 @@ unsigned char* HKDF(const EVP_MD *evp_md,
return ret;
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Popups
+
+void WhatsAppProto::InitPopups(void)
+{
+ g_plugin.addPopupOption(CMStringW(FORMAT, TranslateT("%s error notifications"), m_tszUserName), m_bUsePopups);
+
+ char name[256];
+ mir_snprintf(name, "%s_%s", m_szModuleName, "Error");
+
+ wchar_t desc[256];
+ mir_snwprintf(desc, L"%s/%s", m_tszUserName, TranslateT("Errors"));
+
+ POPUPCLASS ppc = {};
+ ppc.flags = PCF_UNICODE;
+ ppc.pszName = name;
+ ppc.pszDescription.w = desc;
+ ppc.hIcon = IcoLib_GetIconByHandle(m_hProtoIcon);
+ ppc.colorBack = RGB(191, 0, 0); //Red
+ ppc.colorText = RGB(255, 245, 225); //Yellow
+ ppc.iSeconds = 60;
+ m_hPopupClass = Popup_RegisterClass(&ppc);
+
+ IcoLib_ReleaseIcon(ppc.hIcon);
+}
+
+void WhatsAppProto::Popup(MCONTACT hContact, const wchar_t *szMsg, const wchar_t *szTitle)
+{
+ if (!m_bUsePopups)
+ return;
+
+ char name[256];
+ mir_snprintf(name, "%s_%s", m_szModuleName, "Error");
+
+ CMStringW wszTitle(szTitle);
+ if (hContact == 0) {
+ wszTitle.Insert(0, L": ");
+ wszTitle.Insert(0, m_tszUserName);
+ }
+
+ POPUPDATACLASS ppd = {};
+ ppd.szTitle.w = wszTitle;
+ ppd.szText.w = szMsg;
+ ppd.pszClassName = name;
+ ppd.hContact = hContact;
+ Popup_AddClass(&ppd);
+}