summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-01-07 13:35:25 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-01-07 13:35:25 +0300
commit2f19b814d2658666ecdf2106768a88d5b2ee286b (patch)
treecc9de394d816dbb18335202bd2f39d69f05bee10
parent79db2025e68ad0639ad5842365048512963b63f8 (diff)
Facebook: support for inline attachments
-rw-r--r--protocols/Facebook/src/http.cpp12
-rw-r--r--protocols/Facebook/src/proto.h2
-rw-r--r--protocols/Facebook/src/server.cpp23
3 files changed, 28 insertions, 9 deletions
diff --git a/protocols/Facebook/src/http.cpp b/protocols/Facebook/src/http.cpp
index b22198a16a..cc892ffb5f 100644
--- a/protocols/Facebook/src/http.cpp
+++ b/protocols/Facebook/src/http.cpp
@@ -96,9 +96,10 @@ JsonReply::~JsonReply()
/////////////////////////////////////////////////////////////////////////////////////////
-AsyncHttpRequest* FacebookProto::CreateRequest(const char *szName, const char *szMethod)
+AsyncHttpRequest* FacebookProto::CreateRequest(const char *szUrl, const char *szName, const char *szMethod)
{
AsyncHttpRequest *pReq = new AsyncHttpRequest();
+ pReq->m_szUrl = szUrl;
pReq->requestType = REQUEST_POST;
pReq << CHAR_PARAM("api_key", FB_API_KEY)
<< CHAR_PARAM("device_id", m_szDeviceID)
@@ -111,8 +112,10 @@ AsyncHttpRequest* FacebookProto::CreateRequest(const char *szName, const char *s
szLocale = "en";
pReq << CHAR_PARAM("locale", szLocale);
- if (!m_szAuthToken.IsEmpty())
+ if (!m_szAuthToken.IsEmpty()) {
+ pReq->flags |= NLHRF_NODUMPHEADERS;
pReq->AddHeader("Authorization", "OAuth " + m_szAuthToken);
+ }
pReq->AddHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
return pReq;
@@ -151,11 +154,8 @@ AsyncHttpRequest* FacebookProto::CreateRequestGQL(int64_t query_id) {
return nullptr;
}
- AsyncHttpRequest* pReq = CreateRequest(szName, "get");
-
- pReq->m_szUrl = FB_API_URL_GQL;
+ AsyncHttpRequest* pReq = CreateRequest(FB_API_URL_GQL, szName, "get");
pReq << INT64_PARAM("query_id", query_id);
-
return pReq;
}
diff --git a/protocols/Facebook/src/proto.h b/protocols/Facebook/src/proto.h
index 8f1673cb63..f2b96edcac 100644
--- a/protocols/Facebook/src/proto.h
+++ b/protocols/Facebook/src/proto.h
@@ -393,7 +393,7 @@ class FacebookProto : public PROTO<FacebookProto>
void ConnectionFailed();
- AsyncHttpRequest *CreateRequest(const char *szName, const char *szMethod);
+ AsyncHttpRequest *CreateRequest(const char *szUrl, const char *szName, const char *szMethod);
AsyncHttpRequest *CreateRequestGQL(int64_t id);
NETLIBHTTPREQUEST *ExecuteRequest(AsyncHttpRequest *pReq);
diff --git a/protocols/Facebook/src/server.cpp b/protocols/Facebook/src/server.cpp
index 8a0369014b..84457e512d 100644
--- a/protocols/Facebook/src/server.cpp
+++ b/protocols/Facebook/src/server.cpp
@@ -167,9 +167,8 @@ int FacebookProto::RefreshContacts()
bool FacebookProto::RefreshToken()
{
- auto *pReq = CreateRequest("authenticate", "auth.login");
+ auto *pReq = CreateRequest(FB_API_URL_AUTH, "authenticate", "auth.login");
pReq->flags |= NLHRF_NODUMP;
- pReq->m_szUrl = FB_API_URL_AUTH;
pReq << CHAR_PARAM("email", getMStringA(DBKEY_LOGIN));
pReq << CHAR_PARAM("password", getMStringA(DBKEY_PASS));
pReq->CalcSig();
@@ -520,6 +519,26 @@ void FacebookProto::OnPublishPrivateMessage(const JSONNode &root)
for (auto &it : root["attachments"]) {
// madness... json inside json
CMStringA szJson(it["xmaGraphQL"].as_mstring());
+ if (szJson.IsEmpty()) {
+ __int64 fbid = _wtoi64(it["fbid"].as_mstring());
+ if (fbid == 0) {
+ debugLogA("Neither a GQL nor an inline attachment, nothing to do");
+ continue;
+ }
+
+ // inline attachment, request its description
+ auto *pReq = CreateRequest(FB_API_URL_ATTACH, "getAttachment", "messaging.getAttachment");
+ pReq << CHAR_PARAM("mid", szId) << INT64_PARAM("aid", fbid);
+ pReq->CalcSig();
+
+ JsonReply reply(ExecuteRequest(pReq));
+ if (!reply.error()) {
+ CMStringA str = reply.data()["redirect_uri"].as_mstring();
+ if (!str.IsEmpty())
+ szBody.AppendFormat("\r\nPicture attachment: %s", str.c_str());
+ }
+ continue;
+ }
JSONROOT nBody(szJson);
if (!nBody)
continue;