summaryrefslogtreecommitdiff
path: root/protocols/WhatsAppWeb/src
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/WhatsAppWeb/src')
-rw-r--r--protocols/WhatsAppWeb/src/chats.cpp19
-rw-r--r--protocols/WhatsAppWeb/src/options.cpp53
-rw-r--r--protocols/WhatsAppWeb/src/proto.cpp30
-rw-r--r--protocols/WhatsAppWeb/src/proto.h9
-rw-r--r--protocols/WhatsAppWeb/src/resource.h43
-rw-r--r--protocols/WhatsAppWeb/src/server.cpp5
-rw-r--r--protocols/WhatsAppWeb/src/stdafx.h4
7 files changed, 114 insertions, 49 deletions
diff --git a/protocols/WhatsAppWeb/src/chats.cpp b/protocols/WhatsAppWeb/src/chats.cpp
new file mode 100644
index 0000000000..d8837aff43
--- /dev/null
+++ b/protocols/WhatsAppWeb/src/chats.cpp
@@ -0,0 +1,19 @@
+/*
+
+WhatsAppWeb plugin for Miranda NG
+Copyright © 2019 George Hazan
+
+*/
+
+#include "stdafx.h"
+
+void WhatsAppProto::InitChat(WAUser *pUser, const JSONNode &pRoot)
+{
+ CMStringW wszId(pRoot["jid"].as_mstring()), wszNick(pRoot["name"].as_mstring());
+
+ setWString(pUser->hContact, "Nick", wszNick);
+
+ pUser->si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, wszId, wszNick);
+ Chat_Control(m_szModuleName, wszId, m_bHideGroupchats ? WINDOW_HIDDEN : SESSION_INITDONE);
+ Chat_Control(m_szModuleName, wszId, SESSION_ONLINE);
+}
diff --git a/protocols/WhatsAppWeb/src/options.cpp b/protocols/WhatsAppWeb/src/options.cpp
index 44f1cc8458..c3a5c5b875 100644
--- a/protocols/WhatsAppWeb/src/options.cpp
+++ b/protocols/WhatsAppWeb/src/options.cpp
@@ -6,3 +6,56 @@ Copyright © 2019-21 George Hazan
*/
#include "stdafx.h"
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+class COptionsDlg : public CProtoDlgBase<WhatsAppProto>
+{
+ CCtrlCheck chkHideChats;
+ CCtrlEdit edtGroup;
+ ptrW m_wszOldGroup;
+
+public:
+ COptionsDlg(WhatsAppProto *ppro, int iDlgID, bool bFullDlg) :
+ CProtoDlgBase<WhatsAppProto>(ppro, iDlgID),
+ chkHideChats(this, IDC_HIDECHATS),
+ edtGroup(this, IDC_DEFGROUP),
+ m_wszOldGroup(mir_wstrdup(ppro->m_wszDefaultGroup))
+ {
+ CreateLink(edtGroup, ppro->m_wszDefaultGroup);
+
+ if (bFullDlg)
+ CreateLink(chkHideChats, ppro->m_bHideGroupchats);
+ }
+
+ bool OnApply() override
+ {
+ if (mir_wstrcmp(m_proto->m_wszDefaultGroup, m_wszOldGroup))
+ Clist_GroupCreate(0, m_proto->m_wszDefaultGroup);
+ return true;
+ }
+};
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+INT_PTR WhatsAppProto::SvcCreateAccMgrUI(WPARAM, LPARAM hwndParent)
+{
+ auto *pDlg = new COptionsDlg(this, IDD_ACCMGRUI, false);
+ pDlg->SetParent((HWND)hwndParent);
+ pDlg->Create();
+ return (INT_PTR)pDlg->GetHwnd();
+}
+
+int WhatsAppProto::OnOptionsInit(WPARAM wParam, LPARAM)
+{
+ OPTIONSDIALOGPAGE odp = {};
+ odp.szTitle.w = m_tszUserName;
+ odp.flags = ODPF_UNICODE;
+ odp.szGroup.w = LPGENW("Network");
+
+ odp.position = 1;
+ odp.szTab.w = LPGENW("Account");
+ odp.pDialog = new COptionsDlg(this, IDD_OPTIONS, true);
+ g_plugin.addOptions(wParam, &odp);
+ return 0;
+}
diff --git a/protocols/WhatsAppWeb/src/proto.cpp b/protocols/WhatsAppWeb/src/proto.cpp
index 41491f3e95..447496d090 100644
--- a/protocols/WhatsAppWeb/src/proto.cpp
+++ b/protocols/WhatsAppWeb/src/proto.cpp
@@ -27,19 +27,19 @@ WhatsAppProto::WhatsAppProto(const char *proto_name, const wchar_t *username) :
m_tszDefaultGroup(getWStringA(DBKEY_DEF_GROUP)),
m_arUsers(10, CompareUsers),
m_arPacketQueue(10, NumericKeySortT),
- m_wszDefaultGroup(this, "DefaultGroup", L"WhatsApp")
+ m_wszDefaultGroup(this, "DefaultGroup", L"WhatsApp"),
+ m_bHideGroupchats(this, "HideChats", true)
{
db_set_resident(m_szModuleName, "StatusMsg");
- // CreateProtoService(PS_CREATEACCMGRUI, &WhatsAppProto::SvcCreateAccMgrUI);
+ CreateProtoService(PS_CREATEACCMGRUI, &WhatsAppProto::SvcCreateAccMgrUI);
CreateProtoService(PS_GETAVATARINFO, &WhatsAppProto::GetAvatarInfo);
CreateProtoService(PS_GETAVATARCAPS, &WhatsAppProto::GetAvatarCaps);
CreateProtoService(PS_GETMYAVATAR, &WhatsAppProto::GetMyAvatar);
CreateProtoService(PS_SETMYAVATAR, &WhatsAppProto::SetMyAvatar);
- // HookProtoEvent(ME_OPT_INITIALISE, &WhatsAppProto::OnOptionsInit);
- // HookProtoEvent(ME_CLIST_PREBUILDSTATUSMENU, &WhatsAppProto::OnBuildStatusMenu);
+ HookProtoEvent(ME_OPT_INITIALISE, &WhatsAppProto::OnOptionsInit);
// Client id generation
m_szClientId = getMStringA(DBKEY_CLIENT_ID);
@@ -71,9 +71,17 @@ WhatsAppProto::WhatsAppProto(const char *proto_name, const wchar_t *username) :
if (dwAttributes == 0xffffffff || (dwAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
CreateDirectoryTreeW(m_tszAvatarFolder.c_str());
+ // default contacts group
if (m_tszDefaultGroup == NULL)
m_tszDefaultGroup = mir_wstrdup(L"WhatsApp");
Clist_GroupCreate(0, m_tszDefaultGroup);
+
+ // groupchat initialization
+ GCREGISTER gcr = {};
+ gcr.dwFlags = GC_TYPNOTIF;
+ gcr.ptszDispName = m_tszUserName;
+ gcr.pszModule = m_szModuleName;
+ Chat_Register(&gcr);
}
WhatsAppProto::~WhatsAppProto()
@@ -96,19 +104,15 @@ void WhatsAppProto::OnModulesLoaded()
/////////////////////////////////////////////////////////////////////////////////////////
// PROTO_INTERFACE implementation
-MCONTACT WhatsAppProto::AddToList(int, PROTOSEARCHRESULT *psr)
+MCONTACT WhatsAppProto::AddToList(int flags, PROTOSEARCHRESULT *psr)
{
if (psr->id.w == nullptr)
return NULL;
- std::string phone(T2Utf(psr->id.w));
- std::string jid(phone + "@c.us");
-
- /* MCONTACT hContact = AddToContactList(jid, phone.c_str());
- if (!(flags & PALF_TEMPORARY))
- db_unset(hContact, "CList", "NotOnList");
-
- return hContact;*/
+ auto *pUser = AddUser(T2Utf(psr->id.w), (flags & PALF_TEMPORARY) != 0);
+ db_unset(pUser->hContact, "CList", "NotOnList");
+
+ return pUser->hContact;
}
INT_PTR WhatsAppProto::GetCaps(int type, MCONTACT)
diff --git a/protocols/WhatsAppWeb/src/proto.h b/protocols/WhatsAppWeb/src/proto.h
index 896c99bab4..1f83c8683d 100644
--- a/protocols/WhatsAppWeb/src/proto.h
+++ b/protocols/WhatsAppWeb/src/proto.h
@@ -37,7 +37,8 @@ struct WAUser
WAUser(MCONTACT _1, const char *_2) :
hContact(_1),
szId(mir_strdup(_2))
- {}
+ {
+ }
~WAUser()
{
@@ -46,6 +47,7 @@ struct WAUser
MCONTACT hContact;
char *szId;
+ SESSION_INFO *si = 0;
};
class WhatsAppProto : public PROTO<WhatsAppProto>
@@ -68,6 +70,10 @@ class WhatsAppProto : public PROTO<WhatsAppProto>
WAUser* FindUser(const char *szId);
WAUser* AddUser(const char *szId, bool bTemporary);
+ // Group chats /////////////////////////////////////////////////////////////////////////
+
+ void InitChat(WAUser *pUser, const JSONNode &chat);
+
// UI //////////////////////////////////////////////////////////////////////////////////
void CloseQrDialog();
@@ -160,6 +166,7 @@ public:
// Options /////////////////////////////////////////////////////////////////////////////
CMOption<wchar_t*> m_wszDefaultGroup; // clist group to store contacts
+ CMOption<bool> m_bHideGroupchats; // do not open chat windows on creation
// Processing Threads //////////////////////////////////////////////////////////////////
diff --git a/protocols/WhatsAppWeb/src/resource.h b/protocols/WhatsAppWeb/src/resource.h
index 42d8bf91fd..0326ab6d8f 100644
--- a/protocols/WhatsAppWeb/src/resource.h
+++ b/protocols/WhatsAppWeb/src/resource.h
@@ -2,44 +2,23 @@
// Microsoft Visual C++ generated include file.
// Used by w:\miranda-ng\protocols\WhatsAppWeb\res\whatsapp.rc
//
-#define IDD_INPUTBOX 102
-#define IDR_REGISTERUTILITY 103
-#define IDD_ACCMGRUI 104
-#define IDD_GROUPCHAT_INVITE 105
-#define IDD_OPTIONS 106
-#define IDD_SHOWQR 107
-#define IDI_WHATSAPP 203
-#define IDI_ADD_GROUP 206
-#define IDI_RENAME_GROUP 208
-#define IDC_CLIST 1001
-#define IDC_NEWJID 1002
-#define IDC_LOGIN 1003
-#define IDC_PW 1004
-#define IDC_SSL 1005
-#define IDC_NICK 1006
-#define IDC_BUTTON_REQUEST_SMS_CODE 1007
-#define IDC_BUTTON_REGISTER 1008
-#define IDC_CC 1009
-#define IDC_VALUE 1010
-#define IDC_SSL2 1010
-#define IDC_CANCEL 1011
-#define IDC_OK 1012
-#define IDC_PW2 1013
-#define IDC_TEXT 1014
-#define IDC_INVITE 1015
-#define IDC_AUTORUN 1016
-#define IDC_DEFGROUP 1017
-#define IDC_REMOTE_TIME 1018
-#define IDC_BUTTON_REQUEST_VOICE_CODE 1019
-#define IDC_QRPIC 1020
+#define IDI_WHATSAPP 100
+#define IDD_ACCMGRUI 101
+#define IDD_OPTIONS 102
+#define IDD_SHOWQR 103
+#define IDC_HIDECHATS 1000
+#define IDC_DEFGROUP 1001
+#define IDC_QRPIC 1002
+#define IDC_CLIST 1003
+#define IDC_NEWJID 1004
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 109
+#define _APS_NEXT_RESOURCE_VALUE 104
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1021
+#define _APS_NEXT_CONTROL_VALUE 1005
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/protocols/WhatsAppWeb/src/server.cpp b/protocols/WhatsAppWeb/src/server.cpp
index 5231b80fe5..08285815c8 100644
--- a/protocols/WhatsAppWeb/src/server.cpp
+++ b/protocols/WhatsAppWeb/src/server.cpp
@@ -443,6 +443,11 @@ void WhatsAppProto::ProcessContacts(const JSONNode &list)
CMStringW jid(it["jid"].as_mstring());
auto *pUser = AddUser(T2Utf(jid), false);
+ if (strstr(pUser->szId, "@g.us")) {
+ InitChat(pUser, it);
+ continue;
+ }
+
CMStringW wszNick(it["notify"].as_mstring());
if (wszNick.IsEmpty()) {
int idx = jid.Find('@');
diff --git a/protocols/WhatsAppWeb/src/stdafx.h b/protocols/WhatsAppWeb/src/stdafx.h
index 4434f9ba8c..a89e28976e 100644
--- a/protocols/WhatsAppWeb/src/stdafx.h
+++ b/protocols/WhatsAppWeb/src/stdafx.h
@@ -6,9 +6,7 @@ Copyright © 2019-21 George Hazan
*/
#pragma once
-
-#pragma warning(disable:4996)
-#pragma warning(disable:4290)
+#pragma warning(disable:4996 4290 4200)
#include <malloc.h>
#include <time.h>