summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorSergey Bolhovskoy <elzorfox@ya.ru>2014-10-01 06:21:09 +0000
committerSergey Bolhovskoy <elzorfox@ya.ru>2014-10-01 06:21:09 +0000
commit1f3f340be39ea193b1c210ddd986d74b468ea4ef (patch)
tree9cb32b4d2919d76e9da356ac11811f72ec0e3480 /protocols
parent635a27f15ede36bd90380095402594563a225d54 (diff)
VKontakte: SearchByEmail support
git-svn-id: http://svn.miranda-ng.org/main/trunk@10660 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r--protocols/VKontakte/src/vk_proto.cpp5
-rw-r--r--protocols/VKontakte/src/vk_proto.h2
-rw-r--r--protocols/VKontakte/src/vk_search.cpp53
3 files changed, 58 insertions, 2 deletions
diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp
index c867bf0c65..2e437d290e 100644
--- a/protocols/VKontakte/src/vk_proto.cpp
+++ b/protocols/VKontakte/src/vk_proto.cpp
@@ -281,7 +281,7 @@ DWORD_PTR CVkProto::GetCaps(int type, MCONTACT hContact)
{
switch(type) {
case PFLAGNUM_1:
- return PF1_IM | PF1_CHAT | PF1_SERVERCLIST | PF1_AUTHREQ | PF1_BASICSEARCH | PF1_SEARCHBYNAME | PF1_MODEMSG;
+ return PF1_IM | PF1_CHAT | PF1_SERVERCLIST | PF1_AUTHREQ | PF1_BASICSEARCH | PF1_SEARCHBYNAME | PF1_SEARCHBYEMAIL | PF1_MODEMSG;
case PFLAGNUM_2:
return PF2_ONLINE | PF2_INVISIBLE | PF2_ONTHEPHONE | PF2_IDLE;
@@ -447,7 +447,8 @@ HANDLE CVkProto::SearchBasic(const PROTOCHAR* id)
HANDLE CVkProto::SearchByEmail(const PROTOCHAR* email)
{
- return 0;
+ ForkThread(&CVkProto::SearchByMailThread, (void *)email);
+ return (HANDLE)1;
}
HANDLE CVkProto::SearchByName(const PROTOCHAR* nick, const PROTOCHAR* firstName, const PROTOCHAR* lastName)
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h
index d5352338dc..2768b61ebe 100644
--- a/protocols/VKontakte/src/vk_proto.h
+++ b/protocols/VKontakte/src/vk_proto.h
@@ -219,8 +219,10 @@ struct CVkProto : public PROTO<CVkProto>
//==== Search ========================================================================
void __cdecl SearchBasicThread(void* id);
+ void __cdecl SearchByMailThread(void* email);
void __cdecl SearchThread(void* p);
void OnSearch(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
+ void OnSearchByMail(NETLIBHTTPREQUEST *, AsyncHttpRequest *);
//==== Misc ==========================================================================
diff --git a/protocols/VKontakte/src/vk_search.cpp b/protocols/VKontakte/src/vk_search.cpp
index d85d91168b..5763f6d7ca 100644
--- a/protocols/VKontakte/src/vk_search.cpp
+++ b/protocols/VKontakte/src/vk_search.cpp
@@ -39,6 +39,16 @@ void CVkProto::SearchBasicThread(void* id)
Push(pReq);
}
+void CVkProto::SearchByMailThread(void* email)
+{
+ debugLogA("CVkProto::OnSearchBasicThread");
+ AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_GET, "/method/account.lookupContacts.json", true, &CVkProto::OnSearchByMail)
+ << TCHAR_PARAM("contacts", (TCHAR *)email)
+ << CHAR_PARAM("service", "email")
+ << VER_API;
+ Push(pReq);
+}
+
void __cdecl CVkProto::SearchThread(void* p)
{
PROTOSEARCHBYNAME *pParam = (PROTOSEARCHBYNAME *)p;
@@ -128,3 +138,46 @@ void CVkProto::OnSearch(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
delete pParam;
}
}
+
+void CVkProto::OnSearchByMail(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
+{
+ debugLogA("CVkProto::OnSearch %d", reply->resultCode);
+ if (reply->resultCode != 200){
+ ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
+ return;
+ }
+
+ JSONROOT pRoot;
+ JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
+ if (pResponse == NULL){
+ ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
+ return;
+ }
+
+ JSONNODE *pItems = json_get(pResponse, "found");
+ if (!pItems){
+ ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
+ return;
+ }
+
+ for (int i = 0;; i++) {
+ JSONNODE *pRecord = json_at(pItems, i);
+ if (pRecord == NULL)
+ break;
+
+ PROTOSEARCHRESULT psr = { sizeof(psr) };
+ psr.flags = PSR_TCHAR;
+
+ psr.id = mir_wstrdup(json_as_string(json_get(pRecord, "id")));
+ psr.firstName = mir_wstrdup(json_as_string(json_get(pRecord, "first_name")));
+ psr.lastName = mir_wstrdup(json_as_string(json_get(pRecord, "last_name")));
+ psr.nick = mir_wstrdup(json_as_string(json_get(pRecord, "nickname")));
+ psr.email = mir_wstrdup(json_as_string(json_get(pRecord, "contact")));
+ if (!psr.nick || !psr.nick[0])
+ psr.nick = psr.email;
+
+ ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)1, (LPARAM)&psr);
+ }
+
+ ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
+}