From 4bab8b2f2fc446ff23b2c94aa1c7de9947db0ed4 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 10 Jan 2017 17:35:39 +0300 Subject: more thorough fix for duplicate messages --- protocols/Discord/src/server.cpp | 12 +++++++++++- protocols/Discord/src/version.h | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'protocols/Discord/src') diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp index a8a44b500a..82b6113dfc 100644 --- a/protocols/Discord/src/server.cpp +++ b/protocols/Discord/src/server.cpp @@ -243,11 +243,21 @@ void CDiscordProto::OnReceiveGuilds(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest* void CDiscordProto::OnReceiveMessageAck(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pReq) { + MCONTACT hContact = (MCONTACT)pReq->pUserInfo; + bool bSucceeded = true; if (pReply->resultCode != 200 && pReply->resultCode != 204) bSucceeded = false; - ProtoBroadcastAck((MCONTACT)pReq->pUserInfo, ACKTYPE_MESSAGE, bSucceeded ? ACKRESULT_SUCCESS : ACKRESULT_FAILED, (HANDLE)pReq->m_iReqNum, 0); + JSONNode root = JSONNode::parse(pReply->pData); + if (root) { + SnowFlake newLastId = _wtoi64(root["id"].as_mstring()); + SnowFlake oldLastId = getId(hContact, DB_KEY_LASTMSGID); // as stored in a database + if (oldLastId < newLastId) + setId(hContact, DB_KEY_LASTMSGID, newLastId); + } + + ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, bSucceeded ? ACKRESULT_SUCCESS : ACKRESULT_FAILED, (HANDLE)pReq->m_iReqNum, 0); } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/Discord/src/version.h b/protocols/Discord/src/version.h index d7b213ad39..283aed187b 100644 --- a/protocols/Discord/src/version.h +++ b/protocols/Discord/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 1 #define __RELEASE_NUM 0 -#define __BUILD_NUM 2 +#define __BUILD_NUM 3 #include -- cgit v1.2.3