summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/Facebook/src/proto.cpp2
-rw-r--r--protocols/Facebook/src/proto.h8
-rw-r--r--protocols/Facebook/src/server.cpp37
3 files changed, 34 insertions, 13 deletions
diff --git a/protocols/Facebook/src/proto.cpp b/protocols/Facebook/src/proto.cpp
index 8f0606042a..51d9f82ecd 100644
--- a/protocols/Facebook/src/proto.cpp
+++ b/protocols/Facebook/src/proto.cpp
@@ -192,7 +192,7 @@ int FacebookProto::SendMsg(MCONTACT hContact, int, const char *pszSrc)
JSONNode root; root << CHAR_PARAM("body", pszSrc) << INT64_PARAM("msgid", msgId) << INT64_PARAM("sender_fbid", m_uid) << CHAR_PARAM("to", userId);
MqttPublish("/send_message2", root);
- arOwnMessages.insert(new COwnMessage(msgId, m_mid));
+ arOwnMessages.insert(new COwnMessage(msgId, m_mid, hContact));
return m_mid;
}
diff --git a/protocols/Facebook/src/proto.h b/protocols/Facebook/src/proto.h
index 64060b04bc..ee81e02053 100644
--- a/protocols/Facebook/src/proto.h
+++ b/protocols/Facebook/src/proto.h
@@ -362,11 +362,13 @@ struct COwnMessage
{
__int64 msgId;
int reqId;
+ MCONTACT hContact;
CMStringW wszText;
- COwnMessage(__int64 _id, int _reqId) :
+ COwnMessage(__int64 _id, int _reqId, MCONTACT _hContact) :
msgId(_id),
- reqId(_reqId)
+ reqId(_reqId),
+ hContact(_hContact)
{
}
};
@@ -431,6 +433,7 @@ class FacebookProto : public PROTO<FacebookProto>
void MqttQueueConnect();
void OnPublish(const char *str, const uint8_t *payLoad, size_t cbLen);
+ void OnPublishDelivery(FbThriftReader &rdr);
void OnPublishMessage(FbThriftReader &rdr);
void OnPublishPresence(FbThriftReader &rdr);
void OnPublishUtn(FbThriftReader &rdr);
@@ -464,6 +467,7 @@ class FacebookProto : public PROTO<FacebookProto>
FacebookUser* UserFromJson(const JSONNode &root, CMStringW &wszId, bool &bIsChat);
void FetchAttach(const CMStringA &mid, __int64 fbid, CMStringA &szBody);
+ void NotifyDelivery(const CMStringA &msgid);
void OnLoggedIn();
void OnLoggedOut();
diff --git a/protocols/Facebook/src/server.cpp b/protocols/Facebook/src/server.cpp
index c21f48dd8e..4fb5c0608c 100644
--- a/protocols/Facebook/src/server.cpp
+++ b/protocols/Facebook/src/server.cpp
@@ -30,6 +30,19 @@ void FacebookProto::ConnectionFailed()
OnShutdown();
}
+void FacebookProto::NotifyDelivery(const CMStringA &szId)
+{
+ __int64 msgid = _atoi64(szId);
+ for (auto &it : arOwnMessages) {
+ if (it->msgId == msgid) {
+ ProtoBroadcastAck(it->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)it->reqId, (LPARAM)szId.c_str());
+ if (g_bMessageState)
+ CallService(MS_MESSAGESTATE_UPDATE, it->hContact, MRD_TYPE_DELIVERED);
+ arOwnMessages.removeItem(&it);
+ }
+ }
+}
+
void FacebookProto::OnLoggedIn()
{
m_mid = 0;
@@ -439,6 +452,17 @@ void FacebookProto::OnPublish(const char *topic, const uint8_t *p, size_t cbLen)
OnPublishMessage(rdr);
else if (!strcmp(topic, "/orca_typing_notifications"))
OnPublishUtn(rdr);
+ else if (!strcmp(topic, "/send_message_response"))
+ OnPublishDelivery(rdr);
+}
+
+void FacebookProto::OnPublishDelivery(FbThriftReader &rdr)
+{
+ JSONNode root = JSONNode::parse((const char *)rdr.data());
+ if (root["succeeded"].as_bool()) {
+ CMStringA msgId(root["msgid"].as_mstring());
+ NotifyDelivery(msgId);
+ }
}
void FacebookProto::OnPublishPresence(FbThriftReader &rdr)
@@ -646,19 +670,12 @@ void FacebookProto::OnPublishPrivateMessage(const JSONNode &root)
}
CMStringW wszActorFbId(metadata["actorFbId"].as_mstring());
- CMStringA szId(metadata["messageId"].as_string().c_str());
+ CMStringA szId(metadata["messageId"].as_mstring());
// messages sent with attachments are returning as deltaNewMessage, not deltaSentMessage
__int64 actorFbId = _wtoi64(wszActorFbId);
- if (m_uid == actorFbId) {
- for (auto& it : arOwnMessages) {
- if (it->msgId == offlineId) {
- ProtoBroadcastAck(pUser->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)it->reqId, (LPARAM)szId.c_str());
- arOwnMessages.removeItem(&it);
- break;
- }
- }
- }
+ if (m_uid == actorFbId)
+ NotifyDelivery(szId);
// parse message body
CMStringA szBody(root["body"].as_string().c_str());