summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2021-04-19 14:02:21 +0300
committerGeorge Hazan <ghazan@miranda.im>2021-04-19 14:02:21 +0300
commit99f8fd05b99fbe8df51ba05ee859a419962a535e (patch)
tree08b2e710e3d2e080801544f1d5b626fe9ad885b2
parentf41ad525b78a54d6b81472b98a9137f5a353c5a3 (diff)
WhatsApp:
- group chats are separated from contacts; - basic options dialog; - resource file cleaning
-rw-r--r--protocols/WhatsAppWeb/WhatsAppWeb.vcxproj1
-rw-r--r--protocols/WhatsAppWeb/WhatsAppWeb.vcxproj.filters3
-rw-r--r--protocols/WhatsAppWeb/res/whatsapp.rc65
-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
10 files changed, 145 insertions, 87 deletions
diff --git a/protocols/WhatsAppWeb/WhatsAppWeb.vcxproj b/protocols/WhatsAppWeb/WhatsAppWeb.vcxproj
index 0b03a0b17e..75bfef340d 100644
--- a/protocols/WhatsAppWeb/WhatsAppWeb.vcxproj
+++ b/protocols/WhatsAppWeb/WhatsAppWeb.vcxproj
@@ -43,6 +43,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="src\avatars.cpp" />
+ <ClCompile Include="src\chats.cpp" />
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\options.cpp" />
<ClCompile Include="src\proto.cpp" />
diff --git a/protocols/WhatsAppWeb/WhatsAppWeb.vcxproj.filters b/protocols/WhatsAppWeb/WhatsAppWeb.vcxproj.filters
index 24ccddb69d..57f42bbe7d 100644
--- a/protocols/WhatsAppWeb/WhatsAppWeb.vcxproj.filters
+++ b/protocols/WhatsAppWeb/WhatsAppWeb.vcxproj.filters
@@ -26,6 +26,9 @@
<ClCompile Include="src\utils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\chats.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\db.h">
diff --git a/protocols/WhatsAppWeb/res/whatsapp.rc b/protocols/WhatsAppWeb/res/whatsapp.rc
index 1cc1404662..b133c6d5f6 100644
--- a/protocols/WhatsAppWeb/res/whatsapp.rc
+++ b/protocols/WhatsAppWeb/res/whatsapp.rc
@@ -39,50 +39,21 @@ STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
EXSTYLE WS_EX_CONTROLPARENT
FONT 8, "MS Shell Dlg", 400, 0, 0x0
BEGIN
- LTEXT "Phone number",IDC_STATIC,4,7,55,10
- EDITTEXT IDC_CC,60,6,24,12,ES_AUTOHSCROLL
- EDITTEXT IDC_LOGIN,84,6,100,12,ES_AUTOHSCROLL
- LTEXT "Nickname",IDC_STATIC,4,23,55,10
- EDITTEXT IDC_NICK,60,22,124,12,ES_AUTOHSCROLL
- LTEXT "Default group:",IDC_STATIC,4,37,55,10
- EDITTEXT IDC_DEFGROUP,60,36,124,12,ES_AUTOHSCROLL
- CONTROL "Use SSL connection (port 443)",IDC_SSL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,52,180,10
- CONTROL "Use remote message timestamps",IDC_REMOTE_TIME,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,64,180,10
- CONTROL "Automatically open group chats",IDC_AUTORUN,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,76,180,10
- GROUPBOX "Registration",IDC_STATIC,4,92,184,48
- LTEXT "Enter code",IDC_STATIC,8,123,47,10
- EDITTEXT IDC_PW,45,121,20,12,ES_AUTOHSCROLL | ES_NUMBER
- CTEXT "-",IDC_STATIC,64,123,8,10
- EDITTEXT IDC_PW2,72,121,20,12,ES_AUTOHSCROLL | ES_NUMBER
- PUSHBUTTON "Request SMS code",IDC_BUTTON_REQUEST_SMS_CODE,12,104,80,14
- PUSHBUTTON "Request Voice code",IDC_BUTTON_REQUEST_VOICE_CODE,99,104,80,14
- PUSHBUTTON "Register code",IDC_BUTTON_REGISTER,100,120,80,14
+ LTEXT "Default group:",IDC_STATIC,4,5,55,10
+ EDITTEXT IDC_DEFGROUP,53,3,130,12,ES_AUTOHSCROLL
+ CONTROL "Do not open chat windows on creation",IDC_HIDECHATS,
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,0,21,182,10
END
-IDD_OPTIONS DIALOGEX 0, 0, 188, 164
+IDD_OPTIONS DIALOGEX 0, 0, 305, 188
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
EXSTYLE WS_EX_CONTROLPARENT
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
- LTEXT "Phone number",IDC_STATIC,4,7,55,10
- EDITTEXT IDC_CC,60,6,24,12,ES_AUTOHSCROLL
- EDITTEXT IDC_LOGIN,84,6,100,12,ES_AUTOHSCROLL
- LTEXT "Including country code, without '+' or '00'",IDC_STATIC,60,22,118,18
- LTEXT "Nickname",IDC_STATIC,4,43,55,10
- EDITTEXT IDC_NICK,60,42,124,12,ES_AUTOHSCROLL
- LTEXT "Default group:",IDC_STATIC,4,57,55,10
- EDITTEXT IDC_DEFGROUP,60,56,124,12,ES_AUTOHSCROLL
- CONTROL "Use SSL connection (port 443)",IDC_SSL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,72,180,10
- CONTROL "Use remote message timestamps",IDC_REMOTE_TIME,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,84,180,10
- CONTROL "Automatically open group chats",IDC_AUTORUN,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,96,180,10
- GROUPBOX "Registration",IDC_STATIC,4,112,184,48
- LTEXT "Enter code",IDC_STATIC,8,143,47,10
- EDITTEXT IDC_PW,45,141,20,12,ES_AUTOHSCROLL | ES_NUMBER
- CTEXT "-",IDC_STATIC,64,143,8,10
- EDITTEXT IDC_PW2,72,141,20,12,ES_AUTOHSCROLL | ES_NUMBER
- PUSHBUTTON "Request SMS code",IDC_BUTTON_REQUEST_SMS_CODE,12,124,80,14
- PUSHBUTTON "Request Voice code",IDC_BUTTON_REQUEST_VOICE_CODE,100,124,80,14
- PUSHBUTTON "Register code",IDC_BUTTON_REGISTER,100,140,80,14
+ LTEXT "Default group:",IDC_STATIC,5,8,79,10
+ EDITTEXT IDC_DEFGROUP,87,7,211,12,ES_AUTOHSCROLL
+ CONTROL "Do not open chat windows on creation",IDC_HIDECHATS,
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,29,294,10
END
IDD_GROUPCHAT_INVITE DIALOGEX 0, 0, 215, 170
@@ -147,6 +118,14 @@ BEGIN
BEGIN
BOTTOMMARGIN, 332
END
+
+ IDD_ACCMGRUI, DIALOG
+ BEGIN
+ END
+
+ IDD_OPTIONS, DIALOG
+ BEGIN
+ END
END
#endif // APSTUDIO_INVOKED
@@ -161,6 +140,16 @@ BEGIN
0
END
+IDD_ACCMGRUI AFX_DIALOG_LAYOUT
+BEGIN
+ 0
+END
+
+IDD_OPTIONS AFX_DIALOG_LAYOUT
+BEGIN
+ 0
+END
+
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
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>