diff options
author | George Hazan <ghazan@miranda.im> | 2018-10-17 23:25:57 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-10-17 23:26:06 +0300 |
commit | 4555fcf644d733b40715afcc6c0b9b9df1829c1d (patch) | |
tree | c16c16699a23346ffc58ede468bc0ea18115328a | |
parent | 8e46dca450dee488b406dbb49eda1a06f55ea2a8 (diff) |
Discord: fix for assigning message ids to own messages
-rw-r--r-- | protocols/Discord/src/dispatch.cpp | 12 | ||||
-rw-r--r-- | protocols/Discord/src/proto.cpp | 7 | ||||
-rw-r--r-- | protocols/Discord/src/proto.h | 13 | ||||
-rw-r--r-- | protocols/Discord/src/server.cpp | 10 | ||||
-rw-r--r-- | protocols/Discord/src/version.h | 2 |
5 files changed, 24 insertions, 20 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index a0bf365e2a..f10114c884 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -322,14 +322,18 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot) return; } + char szMsgId[100]; + _i64toa_s(msgId, szMsgId, _countof(szMsgId), 10); + // restore partially received updated message if (pUser->lastMsg.id == msg.id) msg = pUser->lastMsg; - SnowFlake nonce = ::getId(pRoot["nonce"]); - SnowFlake *p = arOwnMessages.find(&nonce); + COwnMessage ownMsg(::getId(pRoot["nonce"]), 0); + COwnMessage *p = arOwnMessages.find(&ownMsg); if (p != nullptr) { // own message? skip it - debugLogA("skipping own message with nonce=%lld, id=%lld", nonce, msg.id); + ProtoBroadcastAck(pUser->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)p->reqId, (LPARAM)szMsgId); + debugLogA("skipping own message with nonce=%lld, id=%lld", ownMsg.nonce, msg.id); } else { CMStringW wszText = PrepareMessageText(pRoot); @@ -346,8 +350,6 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot) debugLogA("store a message from private user %lld, channel id %lld", pUser->id, pUser->channelId); ptrA buf(mir_utf8encodeW(wszText)); - char szMsgId[100]; - _i64toa_s(msgId, szMsgId, _countof(szMsgId), 10); recv.timestamp = (DWORD)StringToDate(pRoot["timestamp"].as_mstring()); recv.szMessage = buf; diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp index 129e9eee64..55df6c34c5 100644 --- a/protocols/Discord/src/proto.cpp +++ b/protocols/Discord/src/proto.cpp @@ -17,9 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "stdafx.h" -static int compareMessages(const SnowFlake *p1, const SnowFlake *p2) +static int compareMessages(const COwnMessage *p1, const COwnMessage *p2) { - return compareInt64(*p1, *p2); + return compareInt64(p1->nonce, p2->nonce); } static int compareRequests(const AsyncHttpRequest *p1, const AsyncHttpRequest *p2) @@ -392,11 +392,10 @@ int CDiscordProto::SendMsg(MCONTACT hContact, int /*flags*/, const char *pszSrc) // to distinguish our own messages from these generated by another clients SnowFlake nonce; Utils_GetRandom(&nonce, sizeof(nonce)); JSONNode body; body << WCHAR_PARAM("content", wszText) << INT64_PARAM("nonce", nonce); - arOwnMessages.insert(new SnowFlake(nonce)); CMStringA szUrl(FORMAT, "/channels/%lld/messages", pUser->channelId); AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_POST, szUrl, &CDiscordProto::OnReceiveMessage, &body); - pReq->pUserInfo = (void*)hContact; + arOwnMessages.insert(new COwnMessage(nonce, pReq->m_iReqNum)); Push(pReq); return pReq->m_iReqNum; } diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index a99bfa22d2..4f99ac0735 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -55,6 +55,17 @@ struct CDiscordMessage {} }; +struct COwnMessage +{ + SnowFlake nonce; + int reqId; + + COwnMessage(SnowFlake _id, int _reqId) : + nonce(_id), + reqId(_reqId) + {} +}; + ///////////////////////////////////////////////////////////////////////////////////////// enum CDiscordHistoryOp @@ -196,7 +207,7 @@ class CDiscordProto : public PROTO<CDiscordProto> LIST<CDiscordUser> arMarkReadQueue; OBJLIST<CDiscordUser> arUsers; - OBJLIST<SnowFlake> arOwnMessages; + OBJLIST<COwnMessage> arOwnMessages; CDiscordUser* FindUser(SnowFlake id); CDiscordUser* FindUser(const wchar_t *pwszUsername, int iDiscriminator); diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp index cb15344580..b52c254569 100644 --- a/protocols/Discord/src/server.cpp +++ b/protocols/Discord/src/server.cpp @@ -249,22 +249,14 @@ void CDiscordProto::OnReceiveCreateChannel(NETLIBHTTPREQUEST *pReply, AsyncHttpR ///////////////////////////////////////////////////////////////////////////////////////// -void CDiscordProto::OnReceiveMessage(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pReq) +void CDiscordProto::OnReceiveMessage(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest*) { - MCONTACT hContact = (UINT_PTR)pReq->pUserInfo; - - bool bSucceeded = true; - if (pReply->resultCode != 200 && pReply->resultCode != 204) - bSucceeded = false; - JSONNode root = JSONNode::parse(pReply->pData); if (root) { CDiscordUser *pUser = FindUserByChannel(::getId(root["channel_id"])); if (pUser != nullptr) pUser->lastMsg = CDiscordMessage(::getId(root["id"]), ::getId(root["author"]["id"])); } - - 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 bf55aa75eb..80d6ffba71 100644 --- a/protocols/Discord/src/version.h +++ b/protocols/Discord/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 6 #define __RELEASE_NUM 0 -#define __BUILD_NUM 1 +#define __BUILD_NUM 2 #include <stdver.h> |