From f2f109ef851c68b7f9ff53a179a7e75311cd2d1a Mon Sep 17 00:00:00 2001 From: Sergey Bolhovskoy Date: Wed, 17 Sep 2014 10:30:51 +0000 Subject: VKontakte: Add search by name support git-svn-id: http://svn.miranda-ng.org/main/trunk@10492 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/VKontakte/src/vk_proto.cpp | 5 ++++- protocols/VKontakte/src/vk_proto.h | 3 ++- protocols/VKontakte/src/vk_search.cpp | 31 ++++++++++++++++++++++++------- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index 5afa14dedf..e8f01b8897 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -345,7 +345,10 @@ HANDLE CVkProto::SearchByEmail(const PROTOCHAR* email) HANDLE CVkProto::SearchByName(const PROTOCHAR* nick, const PROTOCHAR* firstName, const PROTOCHAR* lastName) { - return 0; + TCHAR arg[200]; + mir_sntprintf(arg, SIZEOF(arg), _T("%s %s %s"), nick, firstName, lastName); + ForkThread(&CVkProto::SearchByStringThread, (void *)arg); + return (HANDLE)1; } MCONTACT CVkProto::AddToList(int flags, PROTOSEARCHRESULT* psr) diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index 43608c2ee1..750034ccc6 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -205,7 +205,8 @@ struct CVkProto : public PROTO //==== Search ======================================================================== void __cdecl SearchBasicThread(void* id); - void OnSearchBasic(NETLIBHTTPREQUEST*, AsyncHttpRequest*); + void __cdecl SearchByStringThread(void* id); + void OnSearch(NETLIBHTTPREQUEST*, AsyncHttpRequest*); //==== Misc ========================================================================== diff --git a/protocols/VKontakte/src/vk_search.cpp b/protocols/VKontakte/src/vk_search.cpp index 158d949d8b..a6337407a3 100644 --- a/protocols/VKontakte/src/vk_search.cpp +++ b/protocols/VKontakte/src/vk_search.cpp @@ -20,15 +20,24 @@ along with this program. If not, see . void CVkProto::SearchBasicThread(void* id) { debugLogA("CVkProto::OnSearchBasicThread"); - Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/users.get.json", true, &CVkProto::OnSearchBasic) - << TCHAR_PARAM("user_ids", (TCHAR *) id) + Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/users.get.json", true, &CVkProto::OnSearch) + << TCHAR_PARAM("user_ids", (TCHAR *)id) << VER_API); } -void CVkProto::OnSearchBasic(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) +void __cdecl CVkProto::SearchByStringThread(void* str) { - debugLogA("CVkProto::OnSearchBasic %d", reply->resultCode); + debugLogA("CVkProto::OnSearchBasicThread"); + Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/users.search.json", true, &CVkProto::OnSearch) + << TCHAR_PARAM("q", (TCHAR *)str) + << INT_PARAM("count", 200) + << VER_API); +} + +void CVkProto::OnSearch(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) +{ + debugLogA("CVkProto::OnSearch %d", reply->resultCode); if (reply->resultCode != 200){ ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0); return; @@ -41,11 +50,19 @@ void CVkProto::OnSearchBasic(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) return; } - for (size_t i = 0;; i++) { + int iCount = json_as_int(json_get(pResponse, "count")); + JSONNODE *pItems = json_get(pResponse, "items"); + if (!pItems){ + pItems = pResponse; + iCount = 1; + } + + + for (size_t i = 0; i