diff options
author | George Hazan <ghazan@miranda.im> | 2017-08-25 16:15:40 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-08-25 16:15:47 +0300 |
commit | dfcfd2d4f53590faf29f3192eab235ffcace6bf2 (patch) | |
tree | 8b0fa9eaa8b428c7eedd83171b2af66f1e5f4f37 | |
parent | 1c1ee19ac151d50f436b94db778ac53313d3de3e (diff) |
fixes #845 ([Discord] Adding a new contact causes "Only bots can use this endpoint" error)
-rw-r--r-- | protocols/Discord/src/connection.cpp | 2 | ||||
-rw-r--r-- | protocols/Discord/src/proto.cpp | 2 | ||||
-rw-r--r-- | protocols/Discord/src/proto.h | 3 | ||||
-rw-r--r-- | protocols/Discord/src/server.cpp | 47 | ||||
-rw-r--r-- | protocols/Discord/src/version.h | 2 |
5 files changed, 17 insertions, 39 deletions
diff --git a/protocols/Discord/src/connection.cpp b/protocols/Discord/src/connection.cpp index 3d1ad8e83a..06cda379c2 100644 --- a/protocols/Discord/src/connection.cpp +++ b/protocols/Discord/src/connection.cpp @@ -127,7 +127,7 @@ void CDiscordProto::ServerThread(void*) if (m_szAccessToken != nullptr) // try to receive a response from server - RetrieveUserInfo(0); + RetrieveMyInfo(); else { if (mir_wstrlen(m_wszEmail) == 0) { ConnectionFailed(LOGINERR_BADUSERID); diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp index 68fb32d8a8..ace96630cb 100644 --- a/protocols/Discord/src/proto.cpp +++ b/protocols/Discord/src/proto.cpp @@ -252,7 +252,7 @@ int CDiscordProto::AuthRequest(MCONTACT hContact, const wchar_t*) return 1; // error JSONNode root; root << WCHAR_PARAM("username", wszUsername) << INT_PARAM("discriminator", iDiscriminator); - AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_POST, "/users/@me/relationships", &CDiscordProto::OnReceiveAuth, &root); + AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_POST, "/users/@me/relationships", nullptr, &root); pReq->pUserInfo = (void*)hContact; Push(pReq); return 0; diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index bf21c76b62..f0af47b0ad 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -366,14 +366,13 @@ public: int OnDeleteContact(MCONTACT hContact); void OnReceiveCreateChannel(NETLIBHTTPREQUEST*, AsyncHttpRequest*); - void OnReceiveAuth(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void OnReceiveFile(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void OnReceiveGateway(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void OnReceiveMessage(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void OnReceiveMessageAck(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void OnReceiveToken(NETLIBHTTPREQUEST*, AsyncHttpRequest*); - void RetrieveUserInfo(MCONTACT hContact); + void RetrieveMyInfo(); void OnReceiveUserInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void RetrieveHistory(MCONTACT hContact, CDiscordHistoryOp iOp = MSG_NOFILTER, SnowFlake msgid = 0, int iLimit = 50); diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp index 9b86b13fb5..2924b971d0 100644 --- a/protocols/Discord/src/server.cpp +++ b/protocols/Discord/src/server.cpp @@ -141,47 +141,33 @@ void CDiscordProto::OnReceiveHistory(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest ///////////////////////////////////////////////////////////////////////////////////////// // retrieves user info -void CDiscordProto::RetrieveUserInfo(MCONTACT hContact) +void CDiscordProto::RetrieveMyInfo() { - CMStringA szUrl; - if (hContact != 0) { - SnowFlake id = getId(hContact, DB_KEY_ID); - if (id == 0) - return; - szUrl.Format("/users/%lld", id); - } - else szUrl = "/users/@me"; - - AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_GET, szUrl, &CDiscordProto::OnReceiveUserInfo); - pReq->pUserInfo = (void*)hContact; - Push(pReq); + Push(new AsyncHttpRequest(this, REQUEST_GET, "/users/@me", &CDiscordProto::OnReceiveUserInfo)); } -void CDiscordProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pReq) +void CDiscordProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest*) { - MCONTACT hContact = (UINT_PTR)pReq->pUserInfo; if (pReply->resultCode != 200) { - if (hContact == 0) - ConnectionFailed(LOGINERR_WRONGPASSWORD); + ConnectionFailed(LOGINERR_WRONGPASSWORD); return; } JSONNode root = JSONNode::parse(pReply->pData); if (!root) { - if (hContact == 0) - ConnectionFailed(LOGINERR_NOSERVER); + ConnectionFailed(LOGINERR_NOSERVER); return; } SnowFlake id = ::getId(root["id"]); - setId(hContact, DB_KEY_ID, id); + setId(0, DB_KEY_ID, id); - setByte(hContact, DB_KEY_MFA, root["mfa_enabled"].as_bool()); - setDword(hContact, DB_KEY_DISCR, _wtoi(root["discriminator"].as_mstring())); - setWString(hContact, DB_KEY_NICK, root["username"].as_mstring()); - setWString(hContact, DB_KEY_EMAIL, root["email"].as_mstring()); + setByte(0, DB_KEY_MFA, root["mfa_enabled"].as_bool()); + setDword(0, DB_KEY_DISCR, _wtoi(root["discriminator"].as_mstring())); + setWString(0, DB_KEY_NICK, root["username"].as_mstring()); + setWString(0, DB_KEY_EMAIL, root["email"].as_mstring()); - if (hContact == 0) { + if (0 == 0) { m_ownId = id; for (int i=0; i < pReply->headersCount; i++) if (!strcmp(pReply->headers[i].szName, "Set-Cookie")) { @@ -197,7 +183,7 @@ void CDiscordProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *pReply, AsyncHttpReques ProcessType(pUser, root); } - CheckAvatarChange(hContact, root["avatar"].as_mstring()); + CheckAvatarChange(0, root["avatar"].as_mstring()); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -250,13 +236,6 @@ void CDiscordProto::SetServerStatus(int iStatus) ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)iOldStatus, m_iStatus); } -void CDiscordProto::OnReceiveAuth(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pReq) -{ - MCONTACT hContact = (UINT_PTR)pReq->pUserInfo; - if (pReply->resultCode == 204) - RetrieveUserInfo(hContact); -} - ///////////////////////////////////////////////////////////////////////////////////////// // channels @@ -333,5 +312,5 @@ LBL_Error: m_szAccessToken = szToken.Detach(); setString("AccessToken", m_szAccessToken); - RetrieveUserInfo(0); + RetrieveMyInfo(); } diff --git a/protocols/Discord/src/version.h b/protocols/Discord/src/version.h index bf45d22131..150d7b25f8 100644 --- a/protocols/Discord/src/version.h +++ b/protocols/Discord/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 5 #define __RELEASE_NUM 0 -#define __BUILD_NUM 2 +#define __BUILD_NUM 3 #include <stdver.h> |