diff options
author | George Hazan <ghazan@miranda.im> | 2020-11-30 18:18:29 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2020-11-30 18:18:29 +0300 |
commit | 0f3a22dbe582064529b455daa892f2743eb2edeb (patch) | |
tree | 5840e4d161a4ac0c72ce301b04e9b674e045ca0b /protocols | |
parent | e567cbd887f33004c3c3adab00b5d8e50e891a33 (diff) |
fixes #2635 (Facebook: duplicating messages)
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/Facebook/src/proto.h | 1 | ||||
-rw-r--r-- | protocols/Facebook/src/server.cpp | 51 | ||||
-rw-r--r-- | protocols/Facebook/src/version.h | 2 |
3 files changed, 35 insertions, 19 deletions
diff --git a/protocols/Facebook/src/proto.h b/protocols/Facebook/src/proto.h index 4c2a2310e0..6255e0b722 100644 --- a/protocols/Facebook/src/proto.h +++ b/protocols/Facebook/src/proto.h @@ -475,6 +475,7 @@ class FacebookProto : public PROTO<FacebookProto> FacebookUser* UserFromJson(const JSONNode &root, CMStringW &wszId, bool &bIsChat); + bool CheckOwnMessage(FacebookUser *pUser, __int64 offlineId, const char *pszMsgId); void FetchAttach(const CMStringA &mid, __int64 fbid, CMStringA &szBody); void NotifyDelivery(const CMStringA &msgid); diff --git a/protocols/Facebook/src/server.cpp b/protocols/Facebook/src/server.cpp index ce86f513ed..1bbdb95b8d 100644 --- a/protocols/Facebook/src/server.cpp +++ b/protocols/Facebook/src/server.cpp @@ -700,6 +700,10 @@ void FacebookProto::OnPublishPrivateMessage(const JSONNode &root) CMStringW wszActorFbId(metadata["actorFbId"].as_mstring()); CMStringA szId(metadata["messageId"].as_mstring()); + if (CheckOwnMessage(pUser, offlineId, szId)) { + debugLogA("own message <%s> skipped", szId.c_str()); + return; + } // messages sent with attachments are returning as deltaNewMessage, not deltaSentMessage __int64 actorFbId = _wtoi64(wszActorFbId); @@ -890,12 +894,38 @@ void FacebookProto::OnPublishReadReceipt(const JSONNode &root) } // my own message was sent +bool FacebookProto::CheckOwnMessage(FacebookUser *pUser, __int64 offlineId, const char *pszMsgId) +{ + COwnMessage tmp; + if (!ExtractOwnMessage(offlineId, tmp)) + return false; + + if (pUser->bIsChat) { + CMStringW wszId(FORMAT, L"%lld", m_uid); + tmp.wszText.Replace(L"%", L"%%"); + + wchar_t userId[100]; + _i64tow_s(pUser->id, userId, _countof(userId), 10); + + GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; + gce.pszID.w = userId; + gce.dwFlags = GCEF_ADDTOLOG; + gce.pszUID.w = wszId; + gce.pszText.w = tmp.wszText; + gce.time = time(0); + gce.bIsMe = true; + Chat_Event(&gce); + } + else ProtoBroadcastAck(pUser->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)tmp.reqId, (LPARAM)pszMsgId); + + return true; +} + void FacebookProto::OnPublishSentMessage(const JSONNode &root) { auto &metadata = root["messageMetadata"]; __int64 offlineId = _wtoi64(metadata["offlineThreadingId"].as_mstring()); - std::string szId(metadata["messageId"].as_string()); CMStringW wszUserId; bool bIsChat; @@ -905,21 +935,6 @@ void FacebookProto::OnPublishSentMessage(const JSONNode &root) return; } - COwnMessage tmp; - if (ExtractOwnMessage(offlineId, tmp)) { - if (pUser->bIsChat) { - CMStringW wszId(FORMAT, L"%lld", m_uid); - tmp.wszText.Replace(L"%", L"%%"); - - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; - gce.pszID.w = wszUserId; - gce.dwFlags = GCEF_ADDTOLOG; - gce.pszUID.w = wszId; - gce.pszText.w = tmp.wszText; - gce.time = time(0); - gce.bIsMe = true; - Chat_Event(&gce); - } - else ProtoBroadcastAck(pUser->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)tmp.reqId, (LPARAM)szId.c_str()); - } + std::string szMsgId(metadata["messageId"].as_string()); + CheckOwnMessage(pUser, offlineId, szMsgId.c_str()); } diff --git a/protocols/Facebook/src/version.h b/protocols/Facebook/src/version.h index 8e1daa5642..fbca217963 100644 --- a/protocols/Facebook/src/version.h +++ b/protocols/Facebook/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 1 #define __RELEASE_NUM 0 -#define __BUILD_NUM 8 +#define __BUILD_NUM 9 #include <stdver.h> |