summaryrefslogtreecommitdiff
path: root/protocols/WhatsAppWeb/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-10-03 21:38:50 +0300
committerGeorge Hazan <ghazan@miranda.im>2022-10-03 21:38:50 +0300
commit238864687b25697a4ed1bae937daf375d48ef777 (patch)
tree7f2ef4cf644291c0aae2b7bd9a528e7466bf57a4 /protocols/WhatsAppWeb/src
parent1394d503041125fd2d75fae80af404e2cd476eeb (diff)
WhatsApp: block list & privacy settings
Diffstat (limited to 'protocols/WhatsAppWeb/src')
-rw-r--r--protocols/WhatsAppWeb/src/iq.cpp20
-rw-r--r--protocols/WhatsAppWeb/src/proto.h2
-rw-r--r--protocols/WhatsAppWeb/src/server.cpp23
-rw-r--r--protocols/WhatsAppWeb/src/utils.h9
4 files changed, 43 insertions, 11 deletions
diff --git a/protocols/WhatsAppWeb/src/iq.cpp b/protocols/WhatsAppWeb/src/iq.cpp
index e20befe5a5..e9d93ae53a 100644
--- a/protocols/WhatsAppWeb/src/iq.cpp
+++ b/protocols/WhatsAppWeb/src/iq.cpp
@@ -7,6 +7,16 @@ Copyright © 2019-22 George Hazan
#include "stdafx.h"
+void WhatsAppProto::OnIqBlockList(const WANode &node)
+{
+ for (auto &it : node.getChild("list")->getChildren()) {
+ auto *pUser = AddUser(it->getAttr("jid"), false);
+ Contact::Hide(pUser->hContact);
+ }
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
static int sttEnumPrekeys(const char *szSetting, void *param)
{
std::vector<int> *list = (std::vector<int> *)param;
@@ -26,7 +36,7 @@ void WhatsAppProto::OnIqCountPrekeys(const WANode &node)
return;
}
- WANodeIq iq(IQ::SET, "encrypt"); iq << CHAR_PARAM("id", generateMessageId());
+ WANodeIq iq(IQ::SET, "encrypt");
auto regId = encodeBigEndian(getDword(DBKEY_REG_ID));
iq.addChild("registration")->content.append(regId.c_str(), regId.size());
@@ -50,7 +60,13 @@ void WhatsAppProto::OnIqCountPrekeys(const WANode &node)
skey->addChild("value")->content.append(m_noise->preKey.pub);
skey->addChild("signature")->content.append(m_noise->preKey.signature);
- WSSendNode(iq);
+ WSSendNode(iq, &WhatsAppProto::OnIqDoNothing);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+void WhatsAppProto::OnIqDoNothing(const WANode &)
+{
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/WhatsAppWeb/src/proto.h b/protocols/WhatsAppWeb/src/proto.h
index 18f2eded6b..fdafe61568 100644
--- a/protocols/WhatsAppWeb/src/proto.h
+++ b/protocols/WhatsAppWeb/src/proto.h
@@ -214,7 +214,9 @@ class WhatsAppProto : public PROTO<WhatsAppProto>
void OnProcessHandshake(const void *pData, int cbLen);
void InitPersistentHandlers();
+ void OnIqBlockList(const WANode &node);
void OnIqCountPrekeys(const WANode &node);
+ void OnIqDoNothing(const WANode &node);
void OnIqPairDevice(const WANode &node);
void OnIqPairSuccess(const WANode &node);
void OnIqResult(const WANode &node);
diff --git a/protocols/WhatsAppWeb/src/server.cpp b/protocols/WhatsAppWeb/src/server.cpp
index bd87da1533..e6f1dd20f8 100644
--- a/protocols/WhatsAppWeb/src/server.cpp
+++ b/protocols/WhatsAppWeb/src/server.cpp
@@ -80,9 +80,9 @@ void WhatsAppProto::ServerThreadWorker()
if (!WSReadPacket(hdr, netbuf))
break;
- debugLogA("Got packet: buffer = %d, opcode = %d, headerSize = %d, payloadSize = %d, final = %d, masked = %d",
- netbuf.length(), hdr.opCode, hdr.headerSize, hdr.payloadSize, hdr.bIsFinal, hdr.bIsMasked);
- Netlib_Dump(m_hServerConn, netbuf.data(), netbuf.length(), false, 0);
+ // debugLogA("Got packet: buffer = %d, opcode = %d, headerSize = %d, payloadSize = %d, final = %d, masked = %d",
+ // netbuf.length(), hdr.opCode, hdr.headerSize, hdr.payloadSize, hdr.bIsFinal, hdr.bIsMasked);
+ // Netlib_Dump(m_hServerConn, netbuf.data(), netbuf.length(), false, 0);
m_lastRecvTime = time(0);
@@ -238,10 +238,19 @@ void WhatsAppProto::OnLoggedIn()
m_impl.m_keepAlive.Start(1000);
- // retrieve loaded prekeys
+ // retrieve loaded prekeys count
WSSendNode(
WANodeIq(IQ::GET, "encrypt") << XCHILD("count"),
&WhatsAppProto::OnIqCountPrekeys);
+
+ // retrieve initial info
+ WSSendNode(
+ WANodeIq(IQ::GET, "blocklist"),
+ &WhatsAppProto::OnIqBlockList);
+
+ WSSendNode(
+ WANodeIq(IQ::GET, "privacy") << XCHILD("privacy"),
+ &WhatsAppProto::OnIqDoNothing);
}
void WhatsAppProto::OnLoggedOut(void)
@@ -261,7 +270,7 @@ void WhatsAppProto::SendKeepAlive()
{
time_t now = time(0);
if (now - m_lastRecvTime > 20) {
- WSSendNode(WANodeIq(IQ::GET, "w:p") << CHAR_PARAM("id", generateMessageId()) << XCHILD("ping"));
+ WSSendNode(WANodeIq(IQ::GET, "w:p") << XCHILD("ping"), &WhatsAppProto::OnIqDoNothing);
m_lastRecvTime = now;
}
@@ -270,7 +279,9 @@ void WhatsAppProto::SendKeepAlive()
void WhatsAppProto::SetServerStatus(int iStatus)
{
if (mir_wstrlen(m_wszNick))
- WSSendNode(WANode("presence") << CHAR_PARAM("name", T2Utf(m_wszNick)) << CHAR_PARAM("type", (iStatus == ID_STATUS_ONLINE) ? "available" : "unavailable"));
+ WSSendNode(
+ WANode("presence") << CHAR_PARAM("name", T2Utf(m_wszNick)) << CHAR_PARAM("type", (iStatus == ID_STATUS_ONLINE) ? "available" : "unavailable"),
+ &WhatsAppProto::OnIqDoNothing);
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/WhatsAppWeb/src/utils.h b/protocols/WhatsAppWeb/src/utils.h
index cd98fe8749..ae97df0bfe 100644
--- a/protocols/WhatsAppWeb/src/utils.h
+++ b/protocols/WhatsAppWeb/src/utils.h
@@ -44,9 +44,12 @@ public:
CMStringA getBody() const;
- WANode* addChild(const char *pszName);
- WANode* getChild(const char *pszName) const;
- WANode* getFirstChild(void) const;
+ WANode *addChild(const char *pszName);
+ WANode *getChild(const char *pszName) const;
+ WANode *getFirstChild(void) const;
+ const OBJLIST<WANode> &getChildren(void) const
+ { return children;
+ }
void print(CMStringA &dest, int level = 0) const;