diff options
author | George Hazan <ghazan@miranda.im> | 2021-01-18 15:51:20 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2021-01-18 15:51:20 +0300 |
commit | 5d642ad620c7a9075a832db5fd220dded8b80e04 (patch) | |
tree | 8452f2df6c2ab4e9fbcd6f5fcd51eaa59252d895 /protocols/Discord | |
parent | f4d2bc200b670221a1bfa8c818cc86c56d51ec64 (diff) |
Discord: message sending error processing added
Diffstat (limited to 'protocols/Discord')
-rw-r--r-- | protocols/Discord/src/http.cpp | 2 | ||||
-rw-r--r-- | protocols/Discord/src/proto.cpp | 24 | ||||
-rw-r--r-- | protocols/Discord/src/proto.h | 3 |
3 files changed, 26 insertions, 3 deletions
diff --git a/protocols/Discord/src/http.cpp b/protocols/Discord/src/http.cpp index dc529df61f..6dceb2be52 100644 --- a/protocols/Discord/src/http.cpp +++ b/protocols/Discord/src/http.cpp @@ -79,8 +79,6 @@ JsonReply::JsonReply(NETLIBHTTPREQUEST *pReply) } m_errorCode = pReply->resultCode; - if (m_errorCode != 200) - return; m_root = json_parse(pReply->pData); if (m_root == nullptr) diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp index 32b1740b04..cbcb5dca5c 100644 --- a/protocols/Discord/src/proto.cpp +++ b/protocols/Discord/src/proto.cpp @@ -437,6 +437,27 @@ MCONTACT CDiscordProto::AddToList(int flags, PROTOSEARCHRESULT *psr) //////////////////////////////////////////////////////////////////////////////////////// // SendMsg +void CDiscordProto::OnSendMsg(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pReq) +{ + JsonReply root(pReply); + if (!root) { + int iReqNum = -1; + for (auto &it : arOwnMessages) + if (it->reqId == pReq->m_iReqNum) { + iReqNum = it->reqId; + arOwnMessages.removeItem(&it); + break; + } + + if (iReqNum != -1) { + CMStringW wszErrorMsg(root.data()["message"].as_mstring()); + if (wszErrorMsg.IsEmpty()) + wszErrorMsg = TranslateT("Message send failed"); + ProtoBroadcastAck(pReq->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)iReqNum, (LPARAM)wszErrorMsg.c_str()); + } + } +} + int CDiscordProto::SendMsg(MCONTACT hContact, int /*flags*/, const char *pszSrc) { if (!m_bOnline) { @@ -472,7 +493,8 @@ int CDiscordProto::SendMsg(MCONTACT hContact, int /*flags*/, const char *pszSrc) JSONNode body; body << WCHAR_PARAM("content", wszText) << SINT64_PARAM("nonce", nonce); CMStringA szUrl(FORMAT, "/channels/%lld/messages", pUser->channelId); - AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_POST, szUrl, nullptr, &body); + AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_POST, szUrl, &CDiscordProto::OnSendMsg, &body); + pReq->hContact = 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 dbc45b2512..fb7a95be86 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -19,6 +19,7 @@ struct AsyncHttpRequest : public MTHttpRequest<CDiscordProto> int m_iErrorCode, m_iReqNum; bool m_bMainSite; + MCONTACT hContact; }; class JsonReply @@ -437,6 +438,8 @@ public: bool RetrieveAvatar(MCONTACT hContact); void OnReceiveAvatar(NETLIBHTTPREQUEST*, AsyncHttpRequest*); + void OnSendMsg(NETLIBHTTPREQUEST*, AsyncHttpRequest*); + ////////////////////////////////////////////////////////////////////////////////////// // Misc |