summaryrefslogtreecommitdiff
path: root/protocols/WhatsAppWeb
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2021-04-19 12:13:43 +0300
committerGeorge Hazan <ghazan@miranda.im>2021-04-19 12:13:43 +0300
commita3702d87bdfaecff251b7be56d880eac95ad176e (patch)
treedd492d365f500953c3d37ef96413c2b1cfa934ee /protocols/WhatsAppWeb
parentb78ff7e78e16a0ec2e674d750a73df71909e3a8b (diff)
WhatsApp: contact list processing
Diffstat (limited to 'protocols/WhatsAppWeb')
-rw-r--r--protocols/WhatsAppWeb/src/proto.h3
-rw-r--r--protocols/WhatsAppWeb/src/server.cpp35
2 files changed, 37 insertions, 1 deletions
diff --git a/protocols/WhatsAppWeb/src/proto.h b/protocols/WhatsAppWeb/src/proto.h
index 93d2c075fb..896c99bab4 100644
--- a/protocols/WhatsAppWeb/src/proto.h
+++ b/protocols/WhatsAppWeb/src/proto.h
@@ -101,8 +101,11 @@ class WhatsAppProto : public PROTO<WhatsAppProto>
void OnRestoreSession2(const JSONNode &node);
void OnStartSession(const JSONNode &node);
+ // binary packets
void ProcessBinaryPacket(const MBinBuffer &buf);
+ void ProcessContacts(const JSONNode &node);
+ // text packets
void ProcessPacket(const JSONNode &node);
void ProcessBlocked(const JSONNode &node);
void ProcessCmd(const JSONNode &node);
diff --git a/protocols/WhatsAppWeb/src/server.cpp b/protocols/WhatsAppWeb/src/server.cpp
index ad3b94a64f..5231b80fe5 100644
--- a/protocols/WhatsAppWeb/src/server.cpp
+++ b/protocols/WhatsAppWeb/src/server.cpp
@@ -356,7 +356,7 @@ bool WhatsAppProto::ServerThreadWorker()
break;
}
- Netlib_Dump(m_hServerConn, dest.data(), dest.length(), false, 0);
+ // Netlib_Dump(m_hServerConn, dest.data(), dest.length(), false, 0);
ProcessBinaryPacket(dest);
}
else {
@@ -431,6 +431,39 @@ void WhatsAppProto::ProcessBinaryPacket(const MBinBuffer &buf)
return;
debugLogA("packed JSON: %s", root.write().c_str());
+
+ CMStringA szType = root["type"].as_mstring();
+ if (szType == "contacts")
+ ProcessContacts(root["$list$"]);
+}
+
+void WhatsAppProto::ProcessContacts(const JSONNode &list)
+{
+ for (auto &it : list) {
+ CMStringW jid(it["jid"].as_mstring());
+ auto *pUser = AddUser(T2Utf(jid), false);
+
+ CMStringW wszNick(it["notify"].as_mstring());
+ if (wszNick.IsEmpty()) {
+ int idx = jid.Find('@');
+ wszNick = (idx == -1) ? jid : jid.Left(idx);
+ }
+ setWString(pUser->hContact, "Nick", wszNick);
+
+ CMStringW wszFullName(it["name"].as_mstring());
+ wszFullName.TrimRight();
+ if (!wszFullName.IsEmpty()) {
+ setWString(pUser->hContact, "FullName", wszFullName);
+
+ CMStringW wszShort(it["short"].as_mstring());
+ wszShort.TrimRight();
+ if (!wszShort.IsEmpty()) {
+ setWString(pUser->hContact, "FirstName", wszShort);
+ if (wszShort.GetLength()+1 < wszFullName.GetLength())
+ setWString(pUser->hContact, "LastName", wszFullName.c_str() + 1 + wszShort.GetLength());
+ }
+ }
+ }
}
/////////////////////////////////////////////////////////////////////////////////////////