summaryrefslogtreecommitdiff
path: root/protocols/Facebook
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-12-27 16:06:35 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-12-27 16:06:35 +0300
commit16972f022733285ca95c14b829f1f982924de727 (patch)
treecf392fb4b935855238b4028c79690a0a6c9a9c76 /protocols/Facebook
parent225583a16f1a3b5ca5f4fccc6d8f3708c8c2d125 (diff)
Facebook: private message reader
Diffstat (limited to 'protocols/Facebook')
-rw-r--r--protocols/Facebook/src/proto.h4
-rw-r--r--protocols/Facebook/src/server.cpp84
-rw-r--r--protocols/Facebook/src/version.h4
3 files changed, 73 insertions, 19 deletions
diff --git a/protocols/Facebook/src/proto.h b/protocols/Facebook/src/proto.h
index 5acca32c74..3e14326a14 100644
--- a/protocols/Facebook/src/proto.h
+++ b/protocols/Facebook/src/proto.h
@@ -373,8 +373,8 @@ class FacebookProto : public PROTO<FacebookProto>
void MqttSend(const MqttMessage &payload);
void OnPublish(const char *str, const uint8_t *payLoad, size_t cbLen);
+ void OnPublishMessage(FbThriftReader &rdr);
void OnPublishPresence(FbThriftReader &rdr);
- void OnPublishQueueCreated(FbThriftReader &rdr);
void OnPublishUtn(FbThriftReader &rdr);
HNETLIBCONN m_mqttConn;
@@ -417,6 +417,8 @@ public:
return m_szModuleName;
}
+ void OnPublishPrivateMessage(const JSONNode &json);
+
//////////////////////////////////////////////////////////////////////////////////////
// options
diff --git a/protocols/Facebook/src/server.cpp b/protocols/Facebook/src/server.cpp
index 8710263dcd..5c440808b1 100644
--- a/protocols/Facebook/src/server.cpp
+++ b/protocols/Facebook/src/server.cpp
@@ -269,7 +269,7 @@ void FacebookProto::OnPublish(const char *topic, const uint8_t *p, size_t cbLen)
if (!strcmp(topic, "/t_p"))
OnPublishPresence(rdr);
else if (!strcmp(topic, "/t_ms"))
- OnPublishQueueCreated(rdr);
+ OnPublishMessage(rdr);
else if (!strcmp(topic, "/orca_typing_notifications"))
OnPublishUtn(rdr);
}
@@ -337,21 +337,6 @@ void FacebookProto::OnPublishPresence(FbThriftReader &rdr)
assert(fieldType == FB_THRIFT_TYPE_STOP);
}
-void FacebookProto::OnPublishQueueCreated(FbThriftReader &rdr)
-{
- auto *pszJson = (const char *)rdr.data();
- if (*pszJson == 0)
- pszJson++;
-
- JSONNode root = JSONNode::parse(pszJson);
- m_szSyncToken = root["syncToken"].as_mstring();
- setString(DBKEY_SYNC_TOKEN, m_szSyncToken);
-
- CMStringW wszSid = root["firstDeltaSeqId"].as_mstring();
- setWString(DBKEY_SID, wszSid);
- m_sid = _wtoi64(wszSid);
-}
-
void FacebookProto::OnPublishUtn(FbThriftReader &rdr)
{
JSONNode root = JSONNode::parse((const char *)rdr.data());
@@ -361,3 +346,70 @@ void FacebookProto::OnPublishUtn(FbThriftReader &rdr)
CallService(MS_PROTO_CONTACTISTYPING, pUser->hContact, length);
}
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+struct
+{
+ const char *messageType;
+ void (FacebookProto:: *pFunc)(const JSONNode &);
+}
+static MsgHandlers[] =
+{
+ { "deltaNewMessage", &FacebookProto::OnPublishPrivateMessage }
+};
+
+void FacebookProto::OnPublishMessage(FbThriftReader &rdr)
+{
+ CMStringA szJson((const char *)rdr.data(), (int)rdr.size());
+ if (szJson[0] == 0)
+ szJson.Delete(0);
+
+ debugLogA("MS: <%s>", szJson.c_str());
+ JSONNode root = JSONNode::parse(szJson);
+
+ CMStringW str = root["lastIssuedSeqId"].as_mstring();
+ if (!str.IsEmpty()) {
+ setWString(DBKEY_SID, str);
+ m_sid = _wtoi64(str);
+ }
+
+ str = root["syncToken"].as_mstring();
+ if (!str.IsEmpty()) {
+ m_szSyncToken = str;
+ setString(DBKEY_SYNC_TOKEN, m_szSyncToken);
+ return;
+ }
+
+ for (auto &it : root["deltas"]) {
+ for (auto &handler : MsgHandlers) {
+ auto &json = it[handler.messageType];
+ if (json) {
+ (this->*(handler.pFunc))(json);
+ break;
+ }
+ }
+ }
+}
+
+// new message arrived
+void FacebookProto::OnPublishPrivateMessage(const JSONNode &root)
+{
+ auto &metadata = root["messageMetadata"];
+
+ CMStringA wszUserId(metadata["actorFbId"].as_mstring());
+ auto *pUser = FindUser(_atoi64(wszUserId));
+ if (pUser == nullptr) {
+ debugLogA("Message from unknown contact %s, ignored", wszUserId.c_str());
+ return;
+ }
+
+ std::string szBody(root["body"].as_string());
+ std::string szId(metadata["messageId"].as_string());
+
+ PROTORECVEVENT pre = {};
+ pre.timestamp = DWORD(_wtoi64(metadata["timestamp"].as_mstring()) / 1000);
+ pre.szMessage = (char *)szBody.c_str();
+ pre.szMsgId = (char *)szId.c_str();
+ ProtoChainRecvMsg(pUser->hContact, &pre);
+}
diff --git a/protocols/Facebook/src/version.h b/protocols/Facebook/src/version.h
index d9f70ae508..a1141f5a00 100644
--- a/protocols/Facebook/src/version.h
+++ b/protocols/Facebook/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 0
-#define __RELEASE_NUM 0
-#define __BUILD_NUM 1
+#define __RELEASE_NUM 1
+#define __BUILD_NUM 0
#include <stdver.h>