diff options
author | George Hazan <ghazan@miranda.im> | 2020-04-17 12:22:37 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2020-04-17 12:22:37 +0300 |
commit | 8ef3e712e44c9f4704375b55fc6487e131d93f8a (patch) | |
tree | 03d2042295e27241f3ff1c902240c9395dac12ae /protocols/Discord | |
parent | a427d9066d300620f6dd63e93824adf42188dbcc (diff) |
Discord: fix for the basic search (by SnowFlake)
Diffstat (limited to 'protocols/Discord')
-rw-r--r-- | protocols/Discord/src/proto.cpp | 29 | ||||
-rw-r--r-- | protocols/Discord/src/proto.h | 3 |
2 files changed, 23 insertions, 9 deletions
diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp index 232ffe94d7..bb88415a52 100644 --- a/protocols/Discord/src/proto.cpp +++ b/protocols/Discord/src/proto.cpp @@ -276,9 +276,9 @@ void CDiscordProto::SearchThread(void *param) psr.firstName.w = L""; psr.lastName.w = L""; psr.id.w = L""; - ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)param, (LPARAM)&psr); + ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)1, (LPARAM)&psr); - ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)param, 0); + ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0); mir_free(param); } @@ -296,9 +296,24 @@ HWND CDiscordProto::SearchAdvanced(HWND hwndDlg) if (p == nullptr) // wrong user id return nullptr; - p = mir_wstrdup(wszNick); - ForkThread(&CDiscordProto::SearchThread, p); - return (HWND)p; + ForkThread(&CDiscordProto::SearchThread, mir_wstrdup(wszNick)); + return (HWND)1; +} + +///////////////////////////////////////////////////////////////////////////////////////// +// Basic search - by SnowFlake + +void CDiscordProto::OnReceiveUserinfo(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest*) +{ + JsonReply root(pReply); + if (!root) { + ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_FAILED, (HANDLE)1); + return; + } + + auto &data = root.data(); + CMStringW wszUserId(data["username"].as_mstring() + L"#" + data["discriminator"].as_mstring()); + ForkThread(&CDiscordProto::SearchThread, wszUserId.Detach()); } HANDLE CDiscordProto::SearchBasic(const wchar_t *wszId) @@ -308,9 +323,7 @@ HANDLE CDiscordProto::SearchBasic(const wchar_t *wszId) CMStringA szUrl = "/users/"; szUrl.AppendFormat(ptrA(mir_utf8encodeW(wszId))); - AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_GET, szUrl, &CDiscordProto::OnReceiveMyInfo); - pReq->pUserInfo = (void*)-1; - Push(pReq); + Push(new AsyncHttpRequest(this, REQUEST_GET, szUrl, &CDiscordProto::OnReceiveUserinfo)); return (HANDLE)1; // Success } diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index 1fd77e06f1..b52e809811 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -421,7 +421,8 @@ public: void OnReceiveGateway(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void OnReceiveMarkRead(NETLIBHTTPREQUEST *, AsyncHttpRequest *); void OnReceiveMessageAck(NETLIBHTTPREQUEST*, AsyncHttpRequest*); - void OnReceiveToken(NETLIBHTTPREQUEST*, AsyncHttpRequest*); + void OnReceiveToken(NETLIBHTTPREQUEST *, AsyncHttpRequest *); + void OnReceiveUserinfo(NETLIBHTTPREQUEST *, AsyncHttpRequest *); void RetrieveMyInfo(); void OnReceiveMyInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*); |